Commit graph

119 commits

Author SHA1 Message Date
Lukas Jung
e4559f0ea6
Fix Bugs Introduced by GL Jitter on Resize Fix (#1397) 2022-07-15 10:03:03 +02:00
Simon Hausmann
9799571396 Make it possible to implement the ItemRenderer trait with a lifetime
The as_any() method returning a `&mut dyn Any` meant that the type has to be
'static. The class solution of returning &()
doesn't work because it has to be a mutable ref. Therefore just return an Option.
2022-07-12 20:37:14 +02:00
Simon Hausmann
0b20f58ada GL backend: speed up updates to layer content
Now that we store the layer textures as Rc<Texture>, before rendering a
layer we can take a clone of a possibly existing layer texture and if if
the layer's tracker is dirty, we can re-use the existing layer texture
if it's the same size.

This avoids unnecessary texture allocations.
2022-07-11 23:19:05 +02:00
Simon Hausmann
937c37677e Add API for setting and getting the size of a Window in Rust and C++ 2022-07-08 18:37:01 +02:00
Simon Hausmann
3ce9977f0a Add slint::Window::(set_)position
Fixes #323
2022-07-08 18:37:01 +02:00
ogoffart
6b15d2e479 Bump version number to 0.2.6 2022-07-06 09:58:14 +00:00
Simon Hausmann
9661e66bb4 GL backend: reduce memory allocations for text rendering
Fix a logic bug in the function to determine if we need to fall back to
other fonts or if the font we selected provides complete coverage.

In the common case where coverage is given, we start with some unknown
coverage (in old_uncovered_*) and end up with empty
remaining_required_*_coverage. That also happens to be less than
old_uncovered_*. Since that check came first, we always returned
"Improved", which meant we still built up the font fallback list, even
though we didn't need to. Fix the order of checks to avoid that.
2022-07-05 09:26:13 +02:00
Tobias Hunger
dd59d41ee6 Rename init_*_items to register_component
I want to track component structure changes in the window without
generating more code. So use a more generic name for the init_*_items
functions, so that I can add the functionality I need in there.

Also add a register_component to PlatformWindow and call that.
2022-06-30 11:51:49 +02:00
Tobias Hunger
581533f302 Rename free_*_graphics_resources to unregister_component
I want a more generic name as I want to do to track component structure
changes in addition to resource freeing and I do not want to add another
call into the generated code.
2022-06-30 11:51:49 +02:00
Lukas Jung
d63407066d Add documentation to WinitWindow::size() and set_size(). 2022-06-30 10:59:33 +02:00
Lukas Jung
e1b4727c9c Fix resize jitter bug on macOS with GL Backend 2022-06-30 10:59:33 +02:00
Olivier Goffart
deba176c72 Janitor: bump dependencies versions 2022-06-29 09:02:43 +02:00
Simon Hausmann
966e2586a6
Clean up texture caching in the GL renderer (#1375)
Clean up texture caching in the GL renderer

In preparation for moving the image decoding and caching of decoded
image data into the core library, change the texture cache to be really
a cache of textures. Previously it cached Rc<CachedImage>, which could
have also been just a CPU side image. However this was "run-time"
asserted. Instead, with this patch it's an `Rc<Texture>` and that will
always be GPU side.
2022-06-27 19:01:00 +02:00
Simon Hausmann
65419240b4 Bump resvg/usvg versions 2022-06-12 10:58:42 +02:00
Simon Hausmann
565262f5c1 Fix formatting
Re-ran `cargo fmt`
2022-06-08 09:23:31 +02:00
pubg-hacks
aed71311ca Add a read-only propery to TextInput, LineEdit and TextEdit 2022-06-08 09:23:01 +02:00
Simon Hausmann
52b82632e1 janitor: remove unnecessary function parameter 2022-06-08 09:06:31 +02:00
Simon Hausmann
22af9c0a33 janitor: Use SharedString instead of String in GL renderer image cache
We can avoid a string copy.
2022-06-02 11:04:21 +02:00
Olivier Goffart
fa6be65a04 Revert "Rename the free_graphics_resources to component_destroyed"
This reverts commit 1b9fee96c16f7a660ed2c14bb3287fceedc72ba7.

The MCU backend still need the array of item, so it's too realy for this change
2022-05-31 10:48:24 +02:00
Olivier Goffart
ad2d19165a Rename the free_graphics_resources to component_destroyed
And do not iterate over the items anymore
2022-05-31 10:48:24 +02:00
Olivier Goffart
6cbf2c0609 Put the new cache in corelib and use it in the GL backend 2022-05-31 10:48:24 +02:00
Olivier Goffart
615c7635ee Qt: use a HashMap for the cache
And not the cache dirrectly within the item, because it is already in use
for the partial rendering
2022-05-31 10:48:24 +02:00
Olivier Goffart
d2186593c0 Pass the ItemRc to each draw_function
So that it can be used as a key to the cache
2022-05-31 10:48:24 +02:00
Simon Hausmann
cf47d3919c Replace femtovg patch with new release 2022-05-23 09:32:25 +02:00
Tobias Hunger
18cbda0269 janitor: Run cargo clippy --fix 2022-05-22 11:59:00 +02:00
Olivier Goffart
b4ebd88d35 Implements @radial-gradient(circle, ...)
Only the circle is implemented so far.

Part of #263
2022-05-19 14:07:20 +02:00
Jocelyn Turcotte
041238708f wasm: Prevent wasted redraws with multiple post_events
The previous approach of calling send_event on a timer has the disadvantage
or re-entering the event loop for every queued event. Any requested redraw
after one of those events will end up actually drawing, even if that frame could be
replaced by the next event's redraw without being shown to the user.

winit also doesn't expose publicly its web Runner send_events method that would
allow us to queue the events outside and pass them all together.

We can however queue the events inside winit by putting the event loop in
ControlFlow::Poll mode so that winit batches them itself.
This has the side effect of processing and painting those events using
requestAnimationFrame.

To achieve this we take advantage of winit processing send_event calls
synchronously, possibly while on a native event handler, by entering the
event loop just to send WakeEventLoopWorkaround, set the event loop in
Poll mode, exit, and call send_events again with our event which then
ends up being queue in the web event loop's Runner until the next animation
frame where all queued events are processed and redrawn together.
2022-05-16 11:02:28 +02:00
Olivier Goffart
877934f1f1 GL backend: process timing event before processing input events
Otherwise the timing code might think at the time of an event (eg key press)
that the starting point of an animation that starts in this event is
earlier in time than it really is. Causing the animation to appear as it
had started earlier or literaly be finished before it starts.

Fixes #1255
2022-05-12 11:43:07 +02:00
ogoffart
3709ded44d Bump version number to 0.2.5 2022-05-09 16:16:00 +00:00
ogoffart
c160ec2aef Bump version number to 0.2.4 2022-05-09 13:49:25 +00:00
Simon Hausmann
6e18513c12 GL backend: fix locating the default font in slightly atypical environments
Enable fontdb's fontconfig feature to parse fontconfig files to locate
the directories where truetype fonts are located. This helps in system
setups that differ from the defaults that fontdb uses otherwise.

Fixes #1240
2022-05-07 21:59:16 +08:00
ogoffart
6395cdfc09 Bump version number to 0.2.3 2022-05-04 12:32:58 +00:00
Lukas Jung
d648862589 Make window.hide() respect the set EventLoopQuitBehavior 2022-05-04 09:16:13 +02:00
Olivier Goffart
723f89d342 Fix changing the size of contrained window on x11
Changing the constraint doesn't work on non-rezsizable window.
So first set the window as resizeable, then change the constraints, then
maybe remove the resizable flag
2022-04-29 11:54:31 +02:00
Olivier Goffart
9ec6ed0406 wasm: fix tab and back tab
The situation differs depending if the widget show the virtual keyboard or not:
For widget that don't show the virtual keyboard, we rely on the winit events,
but for some reason we don't recieve WindowEvent::ModifiersChanged events with
wasm. Since the event handling in winit is about to be rewriten, I did not
bother reporting the bug upstream, but just work around by using the deprecated
API. So that way shift + tab will no longer be understood as just tab.

For widget using the virtual keyboard, then the event handling is in
wasm_input_helper.rs.  There is a couple of issues:

 - We must map shift+tab to backtab.
 - We need to prevent the default events to trigger, so that tab and other
   shortcuts don't take effect on the browser. Winit already inhibit these
   events so we must do the same otherwise tab and shift+tab would change the
   html focus.
 - By luck, tab used to give the focus back to the canvas before (see previous
   point) and that's why it worked. But now that we don't do that anymore,
   hiding the virtual keyboard should actually re-focus the canvas
 - That will cause the focus event to be intercepted by winit, and will cause
   recursions and borrow error, so we make sure that we do not recurse when
   getting the focus event
2022-04-22 13:58:37 +02:00
Simon Hausmann
eb3ceb54bd janitor: Move the GL renderer into a separate module 2022-04-20 17:41:53 +02:00
Tobias Hunger
9ef1f08163 Take alignment from QStyle infos into account when rendering the TabBar 2022-04-20 15:19:16 +02:00
Simon Hausmann
a881922dd2 Replace touch point workaround with winit patch
Commit c85e1b6d25 added a workaround for a
winit issue, which has been fixed upstream. Until a new release is
available, let's patch in winit from a branch that has the fix
cherry-picked.

This way we don't have to remember to remove the workaround with the
next update and this has been verified on the device.
2022-04-13 11:43:24 +02:00
Olivier Goffart
1b91158b46 corelib: allow to use i32 for coordinate instead of f32 2022-04-11 17:46:50 +02:00
Simon Hausmann
c85e1b6d25 Fix touch position reported on touch release with wayland
Work around https://github.com/rust-windowing/winit/issues/1996 by tracking
touch positions ourselves
2022-04-11 15:56:34 +02:00
Olivier Goffart
14d251e63a winit backend: preserve the value of the scale_factor set programmatically 2022-04-11 14:23:28 +02:00
Simon Hausmann
56ead8689c Enable dark-light mode detection for WASM builds
The new dark-light release supports it
2022-04-10 10:45:58 +02:00
Simon Hausmann
335502be3f Upgrade to femtovg 0.3.4
The GL optimizations are in this release now and this also fixes #843
2022-04-07 13:56:23 +02:00
Simon Hausmann
063a292327 GL backend: add shortcut for zero opacity
If the global opacity is zero, we don't need to paint rectangles, etc.

This shortcut is a compromise between opting out much later on femtovg
level and too early before querying properties of the rectangle.  We
still want to do the latter as somebody might depend on that.
2022-04-07 11:37:51 +02:00
Simon Hausmann
206b765d5d Remove font-kit dependency on Windows
Use directwrite APIs directly to determine the font fallbacks for a given piece of text.
2022-04-06 17:30:30 +02:00
Simon Hausmann
d29f834e57 GL backend: minor optimization for image rendering
When colorizing or drawing images, it's not necessary to apply the extra edge anti-aliasing.
2022-04-06 11:33:18 +02:00
Simon Hausmann
6116bcb35d Minor memory usage optimization for clip layers in the GL backend
If a clipped rectangle transitions from having a border radius to none, then we can
delete the clip layer.
2022-04-06 11:32:57 +02:00
Simon Hausmann
f836322ca1 Speed up rendering of clip elements
When a clip element is enabled and it does not intersect with the current clip region,
then we don't even have to bother rendering any child elements.
2022-04-06 11:32:44 +02:00
Simon Hausmann
e06e99a4b9 GL backend: avoid triangle strip for stroke when filling plain rectangles
Similar to commit a329f052ea, we can apply the same
optimization to rectangles.
2022-04-06 11:32:23 +02:00
Simon Hausmann
a87f2abfd3 Fix font fallback determination on Windows with the GL backend
IDWriteFontFallback::MapCharacters only returns one single font that tries to cover
as much of the input string as possible. We need to continue processing the remaining parts of the text,
in order to get a complete list for all fonts we need.

Fixes #1139
2022-04-05 13:14:33 +02:00