Commit graph

79 commits

Author SHA1 Message Date
Lukas Jung
87fe9fe836 Set the mouse-cursor when hovering a TouchArea 2021-12-07 22:41:24 +01:00
Olivier Goffart
80c0602277 WIP: start making the corelib crate a no_std crate
Does not compile yet with no_std because of the lack of
alternative for thread_local
2021-11-25 12:02:16 +01:00
Simon Hausmann
ad1b251966 Internal cleanup
Centralize the setting of the width/height on the window item in the core library.
2021-11-11 11:47:54 +01:00
Simon Hausmann
67579ec560 Simplify drop implementation of generated components
Avoid creating an intermediate array of items to free the graphics resources.
Instead call run-time function with the item tree as a parameter, which is traversed.

It's practically the same data structure that was previously created, except
that it is shared/global and has little holes for the dynamic tree items, but those are easy to skip.
2021-11-01 08:58:53 +01:00
Simon Hausmann
d57edfbb7c Simplify free_graphics_resources API in the backend
Take an iterator reference instead of a slice, so that we can change the call sites in the future.
2021-10-30 13:03:52 +02:00
Olivier Goffart
567c644a5f Fix PopupWindow position when all elements are not inlined
Pass a reference to the parent item in the show_popup function
so we can compute the exact location at runtime.
2021-10-28 15:52:29 +02:00
Olivier Goffart
2716e4b4dd TouchArea: add the pointer-event callback
... instead of `pressed-changed`

This allows to see what mouse button was pressed.

Closes #535
2021-10-04 14:39:49 +02:00
Simon Hausmann
ac0cc85d33 Simplify font resolution in the GL backend
The font resolution function querying fontdb is fast now, so we can
always call it when rendering text. That way we don't need all the
indirection in the text_size(), etc. functions, we don't need an entry
in the item graphics cache for the font and we can avoid a lot of
property dependencies.
2021-09-21 10:10:45 +02:00
Simon Hausmann
cc7ea5b92a GL renderer: fix rendering of Text/TextInput when the text property changes in a way that requires different fonts
Unfortunately the text property was not included in the property dependency chain
for the cached Font.
This is fixed by delaying that with a getter function, but in the mid term
we should be able to remove this again once
femtovg learns lazy font resolution.
2021-09-17 18:27:44 +02:00
Simon Hausmann
ed3d848d02 Fix native widget rendering when the window is inactive
Set QStyle::State_Active conditional to whether the window is active,
which maps to Qt's active window concept and winit's has-focus (until we
render popups differently).
2021-09-15 15:34:34 +02:00
Olivier Goffart
4f1eacd6d8 LineEdit is now able to scroll to keep the cursor visible 2021-09-02 17:20:44 +02:00
Simon Hausmann
5ae6d308be Minor cleanup in Window::draw_contents
The component rendering closure can be FnOnce, it doesn't have to be
FnMut.
2021-09-02 12:16:35 +02:00
Simon Hausmann
8114e187b0 Unify mouse input event and draw handling between Qt and the GL backend
The unification reduces back-end specific fields for the window and
allows making all the property trackers in the run-time window private.
2021-09-01 18:20:23 +02:00
Simon Hausmann
5dff29ef67 Internal cleanup: Centralize code to determine default font properties
If the root item is a Window, then we use the default-font-* properties as the basis
for all unspecified font properties in text rendering.

This patch centralizes the code for retrieving that in the runtime window.

If this becomes a performance bottleneck, then we could cache it in a
box-pinned property in the run-time window.
2021-09-01 18:20:23 +02:00
Simon Hausmann
549fcb049b Internal cleanup: Move the scale factor property into the shared runtime Window 2021-09-01 18:20:23 +02:00
Olivier Goffart
861edf94fd Remove FontMetrics trait
since there is only one function in it, just put that function in the Window
then there is no need to heap alocate a dyn FontMetrics just to call this function.
2021-08-31 13:27:32 +02:00
Olivier Goffart
c1fc242a9a Move the text_input_byte_offset_for_position from the FontMetrics to the Window
In preparation of having mutiple-lines TextInput, we will need to give more
data to this function so it no longer belong in FontMetrics

Also remove the unused FontMetric::line_height()
2021-08-31 13:27:32 +02:00
Tobias Hunger
cbeecfefba Remove unnecessary clone() calls
window is just &self once the redundant clone() call has been removed,
so remove that variable entirely.
2021-08-04 22:50:35 +02:00
Tobias Hunger
ce976a1dbb Janitor: Fix clippy::useless_conversion 2021-08-04 22:50:35 +02:00
Tobias Hunger
24a2021226 Janitor: Fix clippy::needless_borrow 2021-08-04 22:50:35 +02:00
Simon Hausmann
bd556e03be minor cleanup: add transparent marker
to make the reinterpret casting between the inner and outer types a bit ... safer
2021-08-03 10:32:04 +02:00
Simon Hausmann
29f5853332 Provide sixtyfps::Window by reference in the Rust API
This also removes Clone from the Window again, to avoid having to face
the question: Does cloning a window duplicate it on the screen?
2021-08-03 10:32:04 +02:00
Simon Hausmann
d87cfb4b1e internal cleanup
Move the WindowHandleAccess impl for api::Window into the super module
so that we don't need the #[doc(hidden)] attribute.
2021-08-03 10:32:04 +02:00
Simon Hausmann
66891a299c Start a new sixtyfps::Window API for Rust, C++, the interpreters and JS
The generated component now provides access to a Window type
via the window() accessor function.

This is part of #333
2021-08-03 10:32:04 +02:00
Simon Hausmann
eaddbe664e internal cleanup: Rename ComponentWindow to WindowRc
That's all it is nowadays, it's a wrapper around Rc<Window>. It's not an
alias because we need to also "wrap" it to C++ via cbindgen, but that's
about it.
2021-07-21 20:33:02 +02:00
Simon Hausmann
ef184f7f1a internal cleanup: Remove the rest of the ComponentWindow API
Now it just remains a wrapper around the Rc, and it can soon be moved to
the API crate hopefully.
2021-07-21 17:41:12 +02:00
Simon Hausmann
77ea5b7a15 API cleanup: hide the rest of the ComponentWindow "internals" 2021-07-21 17:41:12 +02:00
Simon Hausmann
4c1d9dc03e internal cleanup: Remove the poup functions from ComponentWindow
Use WindowHandleAccess instead. Also the clone()
isn't needed anymore since the function take a self reference instead of an Rc<Self> by value.
2021-07-21 17:41:12 +02:00
Simon Hausmann
e005058285 internal cleanup: remove free_graphics_resource from the public ComponentWindow API
Use the WindowHandleAccess backdoor instead.
2021-07-21 17:41:12 +02:00
Simon Hausmann
e4717824f8 internal cleanup: Prepare for more Window internals encapsulation
Hide access to the internals behind a trait that won't be re-exported
into the public Rust API. This allows removing as_any() again.
2021-07-21 17:41:12 +02:00
Simon Hausmann
e902395d09 Trim the Rust ComponentWindow API a little bit more
* Remove some public wrapper functions that are crate internal
2021-07-21 17:41:12 +02:00
Simon Hausmann
2553dd1459 Trim the Rust ComponentWindow API and implementation a little bit
* Remove the `new` function from the main impl and use the slightly
  less visible From conversion trait
* Make the inner Rc<Window> pub(crate) instead of pub
* Instead, provide a public as_any() accessor that the Qt backend can use
2021-07-21 17:41:12 +02:00
Simon Hausmann
492af0f67c Rename the implementation of the Window item to WindowItem
If we were to add `sixtyfps:🪟:Window` to the re_exports, then
this clashes. We might rename the former, but this is a cleaner naming
in any case.

Relates to #333
2021-07-20 17:50:17 +02:00
Simon Hausmann
68626e27fb internal cleanup: simplify free_graphics_resources trait signature
This allows then routing the call through window::Window's Deref impl
2021-07-20 16:19:45 +02:00
Simon Hausmann
9b4752bdfa Silence cSpell on window.rs :) 2021-07-12 14:14:12 +02:00
Tobias Hunger
e5bdeaa804 Janitor: Remove unnecessary & 2021-07-07 08:42:28 +02:00
Tobias Hunger
39984b27db Janitor: Fix spelling in comments 2021-07-03 15:49:43 +02:00
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Tobias Hunger
13d7f5e7bd Janitor: Fix typos in comments and user-facing strings
Also adapt tests for error messages containing the fixed strings.

No behavior change is intended!
2021-06-28 08:32:25 +02:00
Olivier Goffart
be8c890bec Close the popup when reloading the component
Fix panic when reloading the interpreter when a popup is shown

Fixes #210
2021-06-23 13:32:46 +02:00
Simon Hausmann
0fdb87cc69 Add Image::size()
This requires the image size query to be window independent and go
through the backend instead.

This implies minor changes for the Qt backend and bigger ones for the GL
backend:

* There exists now a thread-local IMAGE_CACHE, which is used by the
  backend's image_size() function as well as by the renderer for
  loading CPU side images.
* The image remain as decoded images in there (including SVG tree)
  and the window now has a texture_cache, which holds CachedImage
  with ImageData::Texture.
* Rendering an image item therefore fetches the CPU side image,
  calls upload_to_gpu() on it, which creates a new Rc<CachedImage>
  and that's stored in the texture_cache.
* The texture cache continues to be pruned when hiding the window.
2021-06-20 11:18:28 +02:00
Simon Hausmann
6734c369c8 Fix internal docs of image_size() function
All implementations of the function return the actual source size in
pixels, disregarding the window scale factor. The function is called in
Image's layout_info() to return the image size as preferred size. Since
the logical length is the default length, there's no need to do any
scaling anyway.
2021-06-18 14:21:02 +02:00
Olivier Goffart
142a8dc185 Rename ImageReference to ImageInner and make Immage.0 private 2021-05-28 17:05:16 +02:00
Simon Hausmann
7ddbfbdd64 Clean up font_metrics interface on corelib:🪟:Window
Since the GL backend can't really fail on this anymore we can now
remove the Option from the return value.
2021-05-27 17:04:45 +02:00
Simon Hausmann
ea358d9b2c Simplify internal image_size API
We don't need a property reference anymore, a plain image reference is fine AFAICS.

Dirtyness of the source is tracked on the caller side of layouting_info()
or in the draw_image_impl anyway.
2021-05-12 19:40:09 +02:00
Olivier Goffart
5f74475224 Refactor the MouseEvent 2021-05-12 12:03:03 +02:00
Simon Hausmann
47a255eea5 Further preparation for more aggressive font caching
Pass everything needed for delayed evaluation for
`PlatformWindow::font_metrics()` to permit caching the font matching
result in the Text/TextInput's rendering cache.
2021-04-13 15:30:33 +02:00
Simon Hausmann
a48b81022b Prepare for font caching in text items in the GL renderer
We query text metrics frequently for text items, for example when in
layouts. This requires font resolution, which is about to become more
much more expensive due to analysis of the underlying text. To speed
this up, the objective is to use the item rendering cache. Making that
work in turn requires querying all related properties inside a property
tracker. That means we need to delay querying anything related to that,
including the font request needed for the `font_metrics()` function on
the PlatformWindow trait.
2021-04-13 15:02:57 +02:00
Simon Hausmann
418bc2f62c Fix printer demo showing garbage after live preview update
The component layout needs to be re-calculated. For some reason it is with
the Qt backend but not with GL.
Either way we can force it to re-calculate when the component changes.
It possibly doesn't get dirty when the dependencies are deleted.
2021-04-06 23:03:56 +02:00
Simon Hausmann
e7cde00113 Partial window properties update for the winit window
Remove the intermediate properties for width and height and - just like
qt backend - apply the width and height in apply_window_properties
and when receiving a window resize event.

This also elimiates the get_geometry() getter as that would otherwise just
have been a FIXME'ed default().
2021-04-06 22:47:30 +02:00