Commit graph

742 commits

Author SHA1 Message Date
Simon Hausmann
ff2a4ecb4e Cleanup: Use winit's HTML Canvas accessor instead of our own 2023-06-07 11:30:43 +02:00
Simon Hausmann
ada79d544c Fix on-demand previews in the documentation not showing up
After creating the winit window we end up issuing a request_redraw() on
the window adapter after setting the component. This is before show().
With regular windowing systems the redraw event will be delivered when
the window is actually shown, but winit delivers it right away.

In our draw() implementation we don't do anything before show() is
called, as the size won't be correct.

Therefore content is never rendered.

To work around this behavior, we can use the redraw_requested state and
draw right away in show() on wasm.
2023-06-01 16:51:12 +02:00
Simon Hausmann
a8fcb5acd6 Fix delayed docs preview not working
After commit 7df902b53c, the winit window
is not created when calling show() anymore but it's now created at
component creation time.  That means the event loop workaround removed
in 459f810bd8 is now needed at
construction time.

Since this is a winit and wasm specific issue, it's now dealt with in
the wasm interpreter implementation, by invoking the creation from the
event loop from there and returning a promise in the API.

This changes the API therefore: create() can only be called after the
event loop is running.
2023-06-01 16:51:12 +02:00
Simon Hausmann
599d86e4e1 Simplify Skia renderer API
Remove the size argument from render().
2023-05-26 10:46:59 +02:00
Simon Hausmann
f9b8592eba Simplify FemtoVG Renderer API
Remove the size argument from render().
2023-05-26 10:46:59 +02:00
Simon Hausmann
879e09922f Begin renderer API cleanup: Remove size argument from WinitCompatibleRenderer::render()
We would pass `physical_size_to_slint(&self.winit_window().inner_size())`, which is
identical to `slint::Window::size()`, which
calls `size()` on the WindowAdapter, which
returns the above.
2023-05-26 10:46:59 +02:00
Simon Hausmann
b952b4e658 winit: Fix fullscreen support
This was accidentally removed in 7df902b53c

cc #2775
2023-05-25 19:07:21 +02:00
Simon Hausmann
459f810bd8 winit: Clean up implementation of WinitWindowAdapter::show() and hide()
show() used to create the window, which required access to the event
loop (target), which in turn required workarounds like in #1603.  Since
the winit window exists now in show(), we don't need this workaround
anymore.

The same applies to hide(), we don't need an event loop target, all we
need is the event loop proxy to dispatch a WindowHidden event.
2023-05-24 15:59:56 +02:00
Simon Hausmann
fabe3ec189 Clean up window adapter construction
We don't need the platform error dance with Rc::new_cyclic anymore
2023-05-21 14:40:43 +02:00
Simon Hausmann
fe4a434ce4 Remove the WindowAdapter from the renderer constructor
This allows disentangling the native window creation from the renderer
creation, which is rather ugly and complicated on the C++ side.
2023-05-21 14:40:43 +02:00
Olivier Goffart
dd5ef9993f
Platform: Add a Resized event and use that to convey the changes in size (#2759) 2023-05-21 12:12:30 +02:00
Simon Hausmann
846c48b81d Add public API to allow platforms to report the window scale factor
Add WindowEvent::ScaleFactorChanged and made set_scale_factor on
WindowInner private.

This achieves what #2486 tried to do, but using the clean platform
window event interface.
2023-05-19 17:06:38 +02:00
Simon Hausmann
37a21ee13a Move the shared font database to core 2023-05-19 10:40:51 +02:00
Olivier Goffart
a68df6eb70
WindowAdaptor: change the 3 ime call into one single ime request enum (#2747) 2023-05-17 17:50:19 +02:00
Olivier Goffart
e3ecb5979c Simplify the way the window properties are applied 2023-05-17 10:22:54 +02:00
Simon Hausmann
20d206dc6b Mark the OpenGLContextWrapper trait as unsafe
There's on guarantee that the pointers returned by get_proc_address are
always valid. Our implementation might, but since the trait isn't
sealed, somebody else could implement it badly.
2023-05-17 09:01:02 +02:00
Simon Hausmann
9c1e5efb43 Clean up FemtoVG renderer interface
Accept the OpenGL context as trait impl. This means we can also move the rendering notifier
into the femtovg renderer create and get rid of
the proxy Renderer trait impl.
2023-05-17 09:01:02 +02:00
Simon Hausmann
7f45d180a9 Clean up internal RenderingMetricsCollector API
Don't require passing a dyn WindowAdapter. This was only used for
calling request_redraw(), which a proper window adapter should do anyway
if has_active_animations() is true.
2023-05-17 09:01:02 +02:00
Olivier Goffart
6db08553a1 Wasm: Fixup Copy/paste
The PR #2703 wasn't complete and didn't work in practice because the
clipboard is always None.

Using the clipboard event data works
2023-05-16 22:41:38 +02:00
Olivier Goffart
fdfdd649f7 Winit: set the Windows scale factor once we got the winit::Window
Otherwise we have the bug that setting the maximum and minimum
constraint, that happens before show(), would use the wrong scale factor
2023-05-16 16:59:13 +02:00
Simon Hausmann
2c93ce73c0 janitor: bump winit version
This version still doesn't have the html canvas fix applied though.
2023-05-15 16:39:54 +02:00
Simon Hausmann
b1073b2ee3 Fix live-preview windows not closing when the user tries to close them
This is a regression from https://github.com/slint-ui/slint/pull/2708,
where previously we would have destroyed the winit window and that's how
it would have disappeared. Now we just need to call set_visible(false);
2023-05-12 16:12:58 +02:00
Simon Hausmann
7fe4cb39aa Cleanup: Remove unnecessary WinitWindow trait
WindowAdapter is not generic anymore, we can use it directly.
2023-05-11 10:42:09 +02:00
Simon Hausmann
1e90b1af80 Remove unused unmap() function 2023-05-11 10:42:09 +02:00
Simon Hausmann
7ab90857d5 Fix winit backend tests
Don't run them on macOS/wasm, but attempt to enable their use via the
winit threaded extension.
2023-05-11 10:42:09 +02:00
Simon Hausmann
12e6e322d9 Make the WinitWindowAdapter non-generic
This isn't necessary anymore
2023-05-11 10:42:09 +02:00
Simon Hausmann
e0bcfff0ab Fix doctests
Don't run them with the winit backend, and that'll try to create an
event loop in a thread.
2023-05-11 10:42:09 +02:00
Simon Hausmann
f10e3a35bc Disable winit accessor tests
Now that we always create a window, we end up also creating an event
loop, and that's inherently incompatible with the rust test harness that
creates threads.

We can try to re-enable this later on platforms where we can run an
event loop in a thread. I have a local WIP patch for that.
2023-05-11 10:42:09 +02:00
Simon Hausmann
c3cee1c3d9 winit: Simplify internal renderer trait
Don't require the creation of an Rc<winit window>, leave
that to the caller.
2023-05-11 10:42:09 +02:00
Simon Hausmann
0475b91daf skia: Simplify renderer API
Remove the generic window handle owner part of the API. Instead assume
that the caller provides safety for the given window handles, like we do
for FemtoVG and like softbuffer does it in its public API.
2023-05-11 10:42:09 +02:00
Simon Hausmann
a3a13c727a winit: Cleanup, move the winit window out of the individual renderers 2023-05-11 10:42:09 +02:00
Simon Hausmann
d0cdc462c7 Simplify Skia Renderer
Allocate the renderer's surface type in the constructor.

This also changes the C++ API to match this, which complicates some code
a little bit.
2023-05-11 10:42:09 +02:00
Simon Hausmann
7c0f9e3b15 Remove outdated doc comment 2023-05-11 10:42:09 +02:00
Simon Hausmann
0466ea139c Simplify state handling in the FemtoVG renderer
Create the OpenGL context and FemtoVG canvas in the renderer constructor. This allows
elimiating various levels of interior mutability.
2023-05-11 10:42:09 +02:00
Simon Hausmann
721e74238f winit: Simplify softbuffer handling
Allocate the softbuffer in the constructor
2023-05-11 10:42:09 +02:00
Simon Hausmann
7df902b53c winit: Create a winit window at renderer creation time
This simplifies the logic for how to apply window related requests as
they can be applied to the winit window immediately.

It also simplifies the state handling in the WinitWindowAdapter, as
there's no more distinction between mapped and unmapped. We always map
now (winit does).

One related change in core is that the window properties are now sent to
the backend before calling show(), instead of after.
2023-05-11 10:42:09 +02:00
Simon Hausmann
d18e5697de janitor: Prospective fix for docs.rs build for next release
Don't try to include the slint preview here, we don't need it.  An
alternative would be to also add a docs symlink here, but this seems
more pragmatic for the time being.
2023-05-10 19:34:17 +02:00
Olivier Goffart
eb0ba51252 Fixup copy/paste support
cc #2703
2023-05-09 20:59:37 +02:00
Amirhossein Akhlaghpour
2e8708be87
Feature: Add copy/paste listener on Wasm (#2703) 2023-05-09 15:55:35 +02:00
Simon Hausmann
481288d489 Initial support for rendering with Skia and Vulkan
Closes #1546
2023-05-09 08:58:35 +02:00
Simon Hausmann
ed4a0d65b9 janitor: Bump winit 2023-05-08 09:11:31 +02:00
Olivier Goffart
e4a8e4c8ab Upgrade copypasta
The old version depends on an old version of xcb that crashes.
Even if cargo update should fix the problem, it won't happen automatically with old Cargo.lock
Fixes #2682
2023-05-03 21:44:59 +02:00
Olivier Goffart
98747cd385 Winit software renderer: Fix transparent background
Despite the documentation of softbuffer claiming that the high bits
should be 0, it seems to be interpreted as an alpha value when the
window is actually transparent.
And the values are considered as premultiplied alpha

Also use a Premultiplied aplha for the buffer so we can even have
transparent window with the software renderer
2023-05-03 19:29:51 +02:00
Simon Hausmann
9c56bc2e66 winit: Fix rendering into a given canvas element
Make sure to pass the canvas_id along. Amends
2b45f9448e
2023-04-28 16:47:31 +02:00
Simon Hausmann
2b45f9448e Remove platform error from WinitWindowAdapter again
Instead leave it out and return Default::default() in Rc::new_cyclic().

The map state handling gets quite ugly, because it needs to go into a OnceCell. On the upside, if we succeed with creating the winit window
in new() in the future, then that entire cell goes away.
2023-04-27 17:37:36 +02:00
Simon Hausmann
098a078008 Make it possible for the window adapter creation to fail
The creation of the renderer might fail, for example if we tried to
create an OpenGL renderer on a display that doesn't support OpenGL. We
should catch that in the future and fall back to the software renderer.
2023-04-27 17:37:36 +02:00
Simon Hausmann
af8e71dacc Minor cleanup
Replace qualifier with use.
2023-04-27 17:37:36 +02:00
Simon Hausmann
7144b75adf Fix support for transparent windows on macOS when using OpenGL
CGL supports it as-is but with glutin this is only propagated onto the context
when it's set to true in the config template builder.
2023-04-27 17:11:41 +02:00
Simon Hausmann
16000577ce Fix support for transparent Windows on Wayland
We must tell winit that we want a transparent surface by default, to
avoid that winit sets an opaque region on the wayland surface.

In terms of the surface, we already prefer a GL config with a color
buffer that supports transparency.
2023-04-27 10:32:36 +02:00
ogoffart
dfd5fc38b3 Bump version number to 1.0.3 2023-04-26 14:04:08 +00:00