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.
* 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
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
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.
Split the vertical and horizontal pass into different property cache
This will allow to implement "height for with"
This patch does not port the Rust or C++ binding yet
By moving the image cache to the GraphicsWindow we can now decode images
first without a window and later upload to the GPU.
This also allows removing the window_map_pending property hack.
the must_resize was not set to true when the with and height are set to the prefered
size, but it must be set for the layout to apply.
Note that even with this patch, the window will be resized to the preferred
size when reloading. Because we have no way to know there if this is the first time
the window is shown, or not.
This issue is not quite specific to the gallery, a simpler test case is
this:
```
App := Window {
preferred-width: 500px;
preferred-height: 750px;
HorizontalLayout {
Rectangle {
background: blue;
}
}
}
```
As there is no fixed width/height set, the size is calculated by layout and
apply_window_properties() sets the inner size correctly on the winit window.
However the width/height properties on the root Window item are not set, remain
zero and thus lead to incorrect rendering. They are not set because they are
identical with what window.inner_size() reports - we assume no change and that
they are in sync.
The bug however is in the creation phase, when we decide on an initial size to
pass to the window_builder, we should also set those on the root item. This is
where window.inner_size() and the root item's width/height get out of sync.
Properly release GL resource when unmapping a window and detect stale
cache indices using a generation count. This fixes the disappearing
images (GL textures would be invalid and need to be re-created) as well
as the panics when an item's cache index ended up being re-used because
some other item was drawn first and allocated that indices. The latter
is fixed by using a generational counter on the cache that's bumped when
clearing, instead of a single "cache_ok" bool.
Move the item graphics cache into the GraphicsWindow and then, together
with the new femtovg::TextContext, we can provide the metrics and can
stop using the window_map_pending notifier for this query.
When we calculate the initial layout without a mapped window early on,
we end up with zero text metrics with the GL backend due to an API
limitation of femtovg.
While working on that, this patch introduces a workaround to mark the callers of
image_size() and font_metrics() as dirty when the window is mapped.
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.
Pass everything needed for delayed evaluation for
`PlatformWindow::font_metrics()` to permit caching the font matching
result in the Text/TextInput's rendering cache.
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.
Cache the default font properties in a Property<FontRequest>, so that we
can query it in the future when determining the GLFont for text
rendering. When that will happen through a property tracker, the dirty
propagation should mark the item cache dirty when default font
properties change.
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.
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().
* Provide an internal behavior parameter to run_event_loop() that we can use
from the preview to not quit when the last window was closed.
* Fix Drop for the winit event loop GraphicsWindow to drop the backend window correctly
when unmapping, not when the graphics window dies. Otherwise QuitOnLastWindowClosed doesn't work.
Similar to the window properties, use a property tracker with a change
handler in window to issue redraw requests. This allows eliminating the
forced repaints in the event loop after event processing and ensures
that the UI is repainted when programmatically setting a property, for
example.
Synchronize title/background/etc. once when the window is mapped and
afterwards lazily when the corresponding property tracker notifies us.
Since that callback can happen at any point in time and to also capture
potentially multiple changes, this first triggers a wakeup of the event
loop, when the actual application of properties happens.
By default PropertyTracker::evaluate() registers the currently
evaluating binding/tracker as a dependency. This should help with
repeaters and other scenarios where in the run-time we use property
trackers but want to track the overall "dirtyness" in the window with
regards to whether a redraw is needed or not.
The new evaluate_as_dependency_root() function allows skipping this
mechanism and is used for the two trackers in the window.