Commit graph

81 commits

Author SHA1 Message Date
Tobias Hunger
0981cdf398 Janitor: Remove unecessary cast
Prefer a u8 literal over an i32 literal that is then cast to a u8
2021-07-22 14:07:22 +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
Tobias Hunger
57389c1731 Janitor: Fix remaining instance of clippy::redundant_clone 2021-07-21 19:44:57 +02:00
Tobias Hunger
aeebbb1d96 Janitor: Fix remaining clippy::option_map_unit_fn 2021-07-21 19:44:57 +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
Olivier Goffart
b194c62c22 GL backend: Use the cache for the Window icon 2021-07-20 17:02:24 +02:00
Olivier Goffart
1360f1e26e Added icon property to the Window element 2021-07-20 16:34:19 +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
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Simon Hausmann
035dfc3d1f A few harmless spelling fixes 2021-06-30 22:14:10 +02:00
Olivier Goffart
a58daa31c9 Fix popup size 2021-06-29 09:30:07 +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
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
Olivier Goffart
ce37cd2552 Rename a function to avoid confusion with a field 2021-06-16 15:14:07 +02:00
Olivier Goffart
deaa0fddb0 WIP layout: split vertical and horizontal cache
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
2021-06-16 15:14:07 +02:00
Simon Hausmann
5b9ce15ae2 GL backend: Implement image_size getter without mapped window
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.
2021-06-01 08:29:39 +02:00
Simon Hausmann
4a13bba32a Clean up GL resource handling
Make sure that we have a current GL context before deleting textures or other GL resources
2021-06-01 08:29:39 +02:00
Olivier Goffart
32b92aba08 Fix the viewer and LSP preview when they reload the widow breaking the layout
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.
2021-05-31 09:43:09 +02:00
Simon Hausmann
f9df83d593 Fix initial rendering of widget gallery with GL backend
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.
2021-05-28 17:54:30 +02:00
Olivier Goffart
142a8dc185 Rename ImageReference to ImageInner and make Immage.0 private 2021-05-28 17:05:16 +02:00
Simon Hausmann
d4385280eb Fix disappearing images or panics when hiding and showing a window with wayland
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.
2021-05-28 09:16:24 +02:00
Simon Hausmann
9503ba69b3 GL backend: Move all font related code into the fonts module 2021-05-27 18:51:32 +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
9b02f2e4a2 GL backend: provide font metrics even when the window is not mapped
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.
2021-05-27 17:00:44 +02:00
Simon Hausmann
6d65236813 GL backend: simplify window factory function signature
We can retrieve the event loop window target from anywhere
2021-05-27 15:49:33 +02:00
Simon Hausmann
4b98e05a8f Fix broken layout in web version of gallery
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.
2021-05-25 18:37:53 +02:00
Olivier Goffart
74418db9ad Try to create the window with a proper size already
CC #235
2021-05-21 18:43:41 +02:00
Olivier Goffart
fb690dc815 Fix infinite resize in Gnome (wayland)
The gnome compositor don't like when we resize the window while it
is being resized by the user

Fixes #226
2021-05-20 13:41:26 +02:00
Olivier Goffart
3983e47720 Fix initial window size 2021-05-18 16:55:07 +02:00
Olivier Goffart
fbdbe69fe7 Window: make hight and width fixed size, preferred-* property set the initial size
Issue #227
2021-05-18 10:23:06 +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
Olivier Goffart
720001a223 Remove the solve_layout from the component vtable
no longer required
2021-05-11 14:59:57 +02:00
Olivier Goffart
76befb63a3 Fix the dependency tracker not registering a dependency if it was not dirty
Also fix opening/closing the popup should refresh the window
2021-04-26 15:24:48 +02:00
Olivier Goffart
f1338c39ef GL backend: fix maximum and minimum size 2021-04-21 18:41:51 +02:00
Olivier Goffart
74e0a98105 Adapt the GL backend to the logical/physical pixel changes 2021-04-21 17:44:53 +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
ccca2742c3 Prepare for caching font selection in the GL renderer
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.
2021-04-13 14:09:11 +02:00
Olivier Goffart
cdcf0faa5f Set the size to the Window element when it is shown, when the size would otherwise be empty 2021-04-08 08:46:08 +02:00
Olivier Goffart
24cb910e83 GL: Don't set the windows size if it is empty.
The Qt backend already has a test for that
2021-04-07 13:05:35 +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
Simon Hausmann
1e4921de13 Fix LSP server staying alive when closing preview window
* 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.
2021-04-06 12:11:55 +02:00
Simon Hausmann
b654646722 Change the window property update event to use a window id
This will hopefully enable the custom event to be sendable across threads.
2021-04-02 12:00:32 +02:00
Simon Hausmann
b875a19310 Implement redraw handling lazily
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.
2021-03-25 16:33:54 +01:00
Simon Hausmann
c9f4c17665 Implement window property synchronization lazily
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.
2021-03-25 16:33:54 +01:00
Simon Hausmann
3bd5b0eadf Add support for recursive dependency tracking across PropertyTracker instances
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.
2021-03-25 12:29:19 +01:00
Simon Hausmann
e63baa5766 Re-organize Window and PlatformWindow construction and referencing
Initialize the self_weak in the PlatformWindow impl using the
Rc::new_cyclic pattern with a construction parameter.
2021-03-25 09:43:59 +01:00