Commit graph

62 commits

Author SHA1 Message Date
Simon Hausmann
155b1443e2 Add support for reacting to dark/light mode theme changes with winit
On macOS and Windows, use winit's `Window::theme()` instead of
dark-light, to detect the theme.

Always react to WindowEvent::ThemeChange. It's delivered on macOS,
Windows, and the web.
2023-02-17 16:11:44 +01:00
Simon Hausmann
c3c98d928c Fix panic when minimizing window on Windows with winit
Fixes #2197
2023-02-17 15:59:02 +01:00
Olivier Goffart
6889dfa5f5 Rust: Make new(), run() and show() report errors from the backend
Fixes #2198
2023-02-10 05:00:03 +01:00
Olivier Goffart
f4fca41173 Compile the winit backend's with RUSTFLAGS='--cfg slint_int_coord'
(at least the swrenderer part)
2023-01-24 15:52:49 +01:00
Olivier Goffart
11022b01f3 Fix winit not taking the original size of the canvas into account
We need to check the original size of the canvas before winit override it

The previous code didn't work for two reason
 - It was done after winit had reset the size of the canvas to the
   default size
 - It just calls set_inner_size on the winit Window, which is not what we want,
   we want to call the api::Window::set_size funciton so it can keep all
   different sizes in sync
2022-12-14 14:03:26 +01:00
Simon Hausmann
4883786546 Try to clean up the workaround for the window resizing bug on Windows
Use a dedicated cell and clean up the comments.
2022-12-13 16:50:35 +01:00
Simon Hausmann
f45ab26efe Fix endless window resize on Windows with winit
Restore the resize_event recursion guard accidentally removed in commit 06f7f76b69
2022-12-13 13:31:35 +01:00
Simon Hausmann
8e3df98ffe Minor cleanup
Replace indirect access to the window field with direct access.
2022-12-12 14:24:55 +01:00
Simon Hausmann
b2ebac63c2 Remove component_destroyed from winit's internal renderer interface
The default impl of unregister_component in WindowAdapterSealed would call free_graphics_resources
on the rendere. Any re-implementation would have to do the same,
which the winit backend forwarded through
the winit backend specific internal renderer interface.

Instead, the original call site for unregister_component now calls
free_graphics_resources and unregister_component (for accessibility tree dirty notification).
2022-12-09 09:03:27 +01:00
Simon Hausmann
f5bbca9fce Remove default_font_size() from internal winit renderer interface
Replace register_root_component in the WindowAdapterSealed altogether with
a default font size getter on the renderer.

This is overall simpler and allows removing the doc-hidden getter in the software renderer.
2022-12-09 09:03:27 +01:00
Simon Hausmann
06f7f76b69 Reduce the renderer interface further in the winit backend
Move the canvas into the renderer entirely as interior state.

This complicates the implementation but paves the way for an easy-to-use API.
2022-12-09 09:03:27 +01:00
Simon Hausmann
6c22af4247 Wrap the software renderer into a struct
This is in preparation for internalizing the canvas state.
2022-12-09 09:03:27 +01:00
Simon Hausmann
ff119eab4f Minimize the WinitCompatibleRenderer trait a little
Replace the raw-window-handle traits with a winit window. It's okay to
use winit one level into the renderer (the part that lives in this
crate).
2022-12-09 09:03:27 +01:00
Simon Hausmann
7fb7804d52 Rename window member in MappedWindow struct to winit_window 2022-12-08 12:12:11 +01:00
Simon Hausmann
6a9ff686fc Simplify size conversions between winit and Slint
Encapsulate the direct conversion between physical sizes in functions,
so that the conversion remains type safe and the code remains easy to read.
2022-12-08 12:12:11 +01:00
Simon Hausmann
307636d652 Remove winit dependency from the renderers
GLWindow (yes, misnomed) is now responsible to creating and owing the
winit:🪟:Window.
2022-12-08 12:12:11 +01:00
Simon Hausmann
26ff1f6a79 Cleanup: simplify internal render() signature by removing adapter argument
We can unwrap internally.
2022-12-08 12:12:11 +01:00
Simon Hausmann
18bf24e7bf cleanup: simplify access to the winit window
We can now return a reference.
2022-12-06 14:15:56 +01:00
Florian Blasius
61c39b5fa1 Add support for dispatching key events through the public platform API
This change adds `KeyPress` and `KeyRelease` variants to the
`WindowEvent` enum, along with the new `slint::Key` enum, that allows
encoding keys.
2022-11-15 10:34:17 +01:00
Simon Hausmann
39121994ca Always set Window.default-font-size
Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
2022-11-03 17:15:44 +01:00
David John
82278a5742 api: add Window::is_visible 2022-10-29 09:21:26 +02:00
Simon Hausmann
c16253d29f Use Property<LogicalLength> instead of Property<Coord>
This removes the special code for the generated property getters and
ensures type safety in the run-time library for property value setting.

In the Rust generated code we continue to do arithmetic on the scalar
values, that means we immediately extract the scalar, do arithmetic and
rely on the compiler to only allow compatible units.

Danger zone alert: In the interpreter Value::Number can now be converted
to LogicalLength as-is.
2022-10-24 12:49:37 +02:00
Olivier Goffart
6ee932883a Rename stark-style to dark-color-scheme
That's the term used by CSS
2022-10-19 15:23:41 +02:00
Olivier Goffart
0ba468c236 Use a builtin function to access the dark-style
instead of a property on NativeStyleMetrics
2022-10-19 15:23:41 +02:00
Simon Hausmann
299325370d Change generated accessor functions for Property<Coord> getters to return LogicalLength 2022-10-13 17:02:18 +02:00
Simon Hausmann
6d1497d7a2 Fix wasm build 2022-10-07 11:16:36 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +02:00
Simon Hausmann
dba137e3ba
Rename RequestedSize to WindowSize and RequestedPosition to WindowPosition (#1640) 2022-09-14 12:59:53 +02:00
Olivier Goffart
e17d07fbc8 winit: Set the icon from the builder
Also simplify the code that sets the property to the builder
2022-09-13 13:39:09 +02:00
Tobias Hunger
53a3c72b57
api: Change logical/physical position and size on window (#1620)
* Add `RequestedSize` and `RequestedPosition` enum to enable asking for
  logical or physical size/position.
* Rename `Window::size()` to `Window::physical_size()`
* Make `Window::set_size(...)` take an `Into<RequestedSize>`
* Rename `Window::position()` to `Window::physical_position()`
* Make `Window::set_position(...)` take an `Into<RequestedPosition>`
* Change `WindowAdapter` and related classes to be able to handle
  requests being made in the either physical or logical units.

Implement this for C++, Rust and node.
2022-09-13 08:55:31 +02:00
Olivier Goffart
911515bfd0 Fix the initial window size when the height depends on the width
We need to assign the width beofre computing the preferred height
otherwise zero or very small value can be assumed and it will case the
text engine return a huge preferred height.

Testcase:

```
export App := Window {
  VerticalLayout {
    padding: -10px;
    Text {
        text: "Lots of text with\nnewlines etc.\n lorem ipsum dolor sit amet";
        wrap: word-wrap;
    }
  }
}
```

In particular, this fixes the gallery window size being too high when
using the skia renderer, because when given a zero width, skia return
a big size for the height, (contrary to the Qt backend that consider 0
as infinite, or the femtovg backend that will stop rendering once a line
can't fit)

Replaces #1621
2022-09-12 12:12:18 +02:00
Simon Hausmann
22f21f16a4 Move the trick to return Poll when request_redraw() is called during draw() straight into the event loop handler 2022-09-08 11:35:34 +02:00
Simon Hausmann
372e6b0ffc winit: Work around request_redraw() not always resulting in a Event::RedrawRequested
The old workaround doesn't work anymore (commit
575665994a removed the
redraw_all_windows() but that was correct as well). Instead we take an
approach that is hopefully more idiomatic to winit:

The winit documention suggests two methods: For continuously repainting
windows, we can just draw in MainEventsCleared. Otherwise call
request_redraw() and wait for Event::RedrawRequested(id).

In practice sometimes a call to request_redraw() from within the input
event processing results right away in a Event::RedrawRequested
(observed on Windows). Sometimes a request_redraw() results in waking up
with NewEvents() but no Event::RedrawRequested, and then in the next
iteration a new request_redraw() is included (observed on Windows).

We will continue to issue request_redraw() but for any windows that
haven't received Event::RedrawRequested() we will just draw. This still
allows the windowing system to compress / combine paint events.

If during draw() request_redraw() is called, we assume that the
application wants to redraw ASAP and we fall back to Poll. This was
previously the workaround in corelib that's now only in the winit code.

Fixes #1574
2022-09-08 11:35:34 +02:00
Simon Hausmann
4095622303 Clean up internal WinitWindow trait
Since event_loop.rs is not shared anymore between the winit backend and
the "mcu" backend, we can reduce the WinitWindow trait to the features
that are needed for the event loop code to store it as trait object.
2022-09-08 08:56:17 +02:00
Simon Hausmann
9e1bb1044c Clean up from-event-loop callback handling
Join wrapping call site and implementation.
2022-09-07 12:03:37 +02:00
Simon Hausmann
8b728df021 Don't panic when calling hide() and request_window_properties_update() on the wasm interpreter generated instance
Similar to commit 0fe29cd196 we need
to wrap access to the event loop :(

hide() is directly exposed in public API,
request_window_properties_update() will be called from outside the event
loop when we expose create_with_existing_window() for the interpeter to
re-use the canvas (which calls set_component on the window).
2022-09-07 12:03:37 +02:00
Olivier Goffart
b3605cb4ec Fix errors and warnings in the wasm build 2022-09-07 10:13:58 +02:00
Simon Hausmann
6b2968c067 janitor: fix warning in wasm build
Remove unnecessary parentheses as suggested by the compiler.
2022-09-07 09:01:59 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +02:00
Olivier Goffart
594131a7ea winit: Enforce the min/max size in the WindowBuilder and set size again for wasm
In previous version, we were setting the constraint with wasm after
the window was shown, but this is no longer the case because we delay
the window creation by an iteration of the event loop.
Now should apply the constraint before showing the window.

But on wasm, we also must manually enforce these constraint because the
size given to the WindowBuilder is not applied
2022-09-06 14:23:58 +02:00
Simon Hausmann
7e5de3d5d3 Remove use of euclid types and tags for logical/physical position and size in the public API
Instead provide our own types.
2022-09-02 11:05:53 +02:00
Olivier Goffart
b9c2dec922 API: seal the WindowAdaptor trait
And hide most of its functions in the sealed trait.
2022-08-30 22:21:24 +02:00
Simon Hausmann
0fe29cd196 Fix preview in online editor not updating when making changes
Creating a new window requires access to an event loop instance. The
winit upgrade prevents us from creating multiple EventLoop instances.
Therefore we have to re-use the existing event loop instance, which is
only accessible from within the event handler.
2022-08-30 16:56:27 +02:00
Tobias Hunger
38350db9a0 Fixes pointed out by Olivier and CI 2022-08-29 16:53:47 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Olivier Goffart
a27806aca8 Add a feature to use the sofware renderer with the winit backend
Currently, you still need to pass some env variable at build time so it
embeds the font.
2022-08-22 19:02:28 +02:00
Simon Hausmann
1d436778c1 Remove the use of the PlatformWindowRc alias again
and use Rc<dyn PlatformWindow> instead. The alias has to stay with the ffi
functions though and the item vtable definitions,
because we don't have an Rc<> template in C++.
2022-08-19 15:07:27 +02:00
Simon Hausmann
af86f36157 Invert slint:🪟:WindowInner and PlatformWindow ownership
Previously: Window is an Rc<WindowInner>, which has an Rc<dyn
PLatformWindow> - and weak references the other way around.

Now: Rc<dyn PlatformWindow> is the root of window ownership. The impl
PlatformWindow has a slint::api::Window, which just holds a WindowInner.

This change is incomplete on a few levels, mainly that neither of the
code generators nor the interpreter is ported.
2022-08-19 15:07:27 +02:00
Simon Hausmann
f88b688fbf Simplify PlatformWindow receivers
For hide() we don't really need Rc<Self>, and for show() we had Rc<Self> because
for example for winit we need a Weak<Self> for the thread-local mapping of
window id to window.

However that can be encapsulated in the PlatformWindow impl using Rc::new_cyclic,
there's no need to expose this in the trait.
2022-08-19 15:07:27 +02:00
Simon Hausmann
8e84faa2c5 Prepare PlatformWindow API for exposing and (in the future) owning the Window
Move the self_weak of WindowInner into the impl of PlatformWindow. Most implementations already have it anyway.

While right now the method returns a `WindowRc`, at the end of the series
it should return a `&Window`.

From that `&Window` we can get to `&WindowInner` and all receivers there
are `&self`.
2022-08-19 15:07:27 +02:00