Commit graph

668 commits

Author SHA1 Message Date
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
a4e4863669 Fix SkiaRenderer::new to take the window adapter weak by value
... for consistency with the software renderer API.
2022-12-12 12:01:12 +01:00
Simon Hausmann
7b4a3cd29a Improve the safety of the skia renderer API
Claim a strong reference (ownership or RC) on the value that provides the raw window handle.
2022-12-12 11:59:50 +01:00
Florian Blasius
501c6af746
Add swr render test and driver (#1955)
* add test-driver-screenshots
* add screenshot based software renderer testing
* create reference screenshots for testing with  test-driver-screenshots
* add documentation to testing `README.md`
2022-12-12 11:23:27 +01:00
Simon Hausmann
01d2efce4e Move the Skia renderer into a separate crate
The crate is an internal crate until the API has been polished and
documented, after which we can call slint-renderer-skia for example.

This also duplicates a little bit of the glutin setup code, because
that would otherwise have to go into another shared crate.
2022-12-09 17:04:54 +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
2fd8bf426a Move the box shadow cache helpers to core::graphics::boxshadowcache
This way the box shadow cache can also be used from the Skia renderer,
which is to be moved into a different 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
d9185053eb Implement windowing system name helper function by means of raw_window_handle 2022-12-08 12:12:11 +01:00
Simon Hausmann
ea16113aad Remove glutin-winit dependency 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
e573f5b9e0 Speed up window resizing with GL on Linux
When selecting the egl/glx config, select a configuration that has multisampling disabled,
as opposed to one that maximizes the number of samples per pixel.

This also fixes XIO errors causing the process to abort, when resizing very quickly.
2022-12-07 16:49:57 +01:00
Simon Hausmann
958cafc357 Fix build of skia-opengl on macOS and Windows
Since commit ea4ad7297b, the metal and d3d
surfaces are built unconditionally when Skia is enabled, which means we
also need to have their dependencies enabled in the "other" skia
feature.
2022-12-06 16:52:45 +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
Simon Hausmann
8dd28d232e Port to new major glutin version 2022-12-06 14:15:56 +01:00
Simon Hausmann
755cd66398 Revert "Prospective build fix for arm cross build" and "With Rust 1.64 we can use core:ffi types instead of depending on libc"
This reverts commit 000d95670b and commit
d764796e0c to fix arm cross build and
x86-64 linux.

Let's use the core::ffi types when fontconfig-sys switches to it.
2022-12-06 09:16:03 +01:00
Simon Hausmann
000d95670b Prospective build fix for arm cross build
Use the `c_char` type that adapts to the signedness
2022-12-06 09:07:48 +01:00
Simon Hausmann
11f46906a2 Centralize rust-version in Cargo.toml
Require 1.64 in the workspace and inherit the setting in package
Cargo.toml files.
2022-12-05 12:39:14 +01:00
Simon Hausmann
d764796e0c With Rust 1.64 we can use core:ffi types instead of depending on libc 2022-12-05 10:33:50 +01:00
ogoffart
fb02b4118b Bump version number to 0.3.3 2022-11-28 13:11:11 +00:00
Simon Hausmann
247772104a Move WindowEvent, PointerEventButton and Key to the platform module
For `Key` this is a move, as it is a new type. For `WindowEvent` and `PointerEventButton` deprecated aliases
are provided.
2022-11-24 11:34:28 +01:00
Olivier Goffart
73a16a171c Janitor: upgrade a few crates 2022-11-22 18:38:05 +01:00
Simon Hausmann
0f25000610 internal: Replace calls to the internal process_key_input with the public dispatch_event API
This can be done for key press and release events, for composition we
need to extend the API first.
2022-11-16 09:47:54 +01:00
Olivier Goffart
6d29a66b52 winit: Fix build with the mcu simulator
the renderer-winit-software feature enable femtovg without the
renderer-winit-femtovg feature, and need the open gl context
2022-11-16 09:38:42 +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
2812d3cf6c janitor: bump skia-safe version to 0.56.1 2022-11-15 10:11:01 +01:00
Simon Hausmann
e9db914fb1
Add is_visible to NodeJS and C++ Window types (#1816)
Amends commit 82278a5742
2022-11-04 16:24:24 +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
Simon Hausmann
b835290f83 Use LogicalRect for the geometry of popups in WindowAdapterSealed 2022-11-01 12:15:51 +01:00
David John
82278a5742 api: add Window::is_visible 2022-10-29 09:21:26 +02:00
ogoffart
2171773a3e Bump version number to 0.3.2 2022-10-28 09:30:14 +00:00
Simon Hausmann
3d2daf6073
Fix crash when editing text that's rendered using the Skia renderer (#1786)
Olivier found the following steps that reproduce the crash with Skia:

1. Open the gallery and select the "Text Edit" tab.
2. In the first text edit widget, select the first three letters.
3. Click into the second text edit (while the first one shows the selected text)
4. At the beginning of the text, insert the letter "ù" a few times.

This sequence would result in the cursor_position property get out of
sync.  Since it represents a byte offset in the utf-8 text, it would
point straight into a utf-8 sequence, resulting in a panic when the
renderer would try to create a slice of the selected text.

As a remedy, this patch renames the cursor_position and anchor_position
properties and provides wrapper getter accessors for use within the
TextInput to safely bound the stored offset.

Eventually we need to intercept changes to the text property and adjust
the cursor and anchor position properties accordingly, so that they
remain valid.  However this requires that the compiler is aware that a
property is not accessible directly but has a setter that needs to be
called instead.

This likely/hopefully also fixes #1707.
2022-10-27 21:47:14 +02:00
Simon Hausmann
ea4ad7297b Always build the Metal and D3d backends on macOS/Windows when Skia is enabled
Their dependencies are always pulled in and for improved CI build coverage
let's always build them.
2022-10-27 13:56:07 +02:00
Simon Hausmann
5805509d80 Fix build on macOS with Skia and the Skia's metal backend
This reverts the foreign-types part of commit d7e366864b
as we need to use the same version of the
ForeignTypeRef trait as the metal crate is using.
2022-10-27 13:56:07 +02:00
Olivier Goffart
b3f346049f Fix parsing the SLINT_BACKEND string
`SLINT_BACKEND="winit"` wouldn't work. So make `winit` and `femtovg` be
possible value for the backend string
2022-10-27 13:07:59 +02:00
Olivier Goffart
e4994f9e9a femtovg renderer: don't draw svg if they are empty
Otherwise computing the fit_size will lead to NaN and then panic.

The size is empty in the wasm case when loading an html image and it
isn't loaded yet. We will be called again because the htmlimage has an
internal property that will be changed when it is loaded
2022-10-27 09:38:47 +02:00
Simon Hausmann
d7e366864b Bump various dependencies
Bump fontdb, foreign-types (used for skia/metal), ttf-parser and winit.

The winit bump is explicit on the patch version to ensure the IME crash
fix is included.
2022-10-26 18:01:29 +02:00
Simon Hausmann
ee39f3802e janitor: Fix warning about use of deprecated functions from ttf-parser 2022-10-24 17:51:36 +02:00
Simon Hausmann
296365cd57 janitor: Bump femtovg and ttf-parser versions 2022-10-24 17:47:19 +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
2e08b7dd1e Fix the rendering size of svg
- On the web, to return the image size, we need to use the natural size
   of the image, and not its dom size, as the later get modified since
   commit  b727aba4a0

 - The target size did not take in account the image fit, that's because
   former version of resvg could only render by respecting the aspect
   ratio. But since the web don't have this limitation, we now need to
   take it into account. And new version of resvg can also scale with
   any aspect ratio
2022-10-24 10:05:38 +02:00
Florian Blasius
c58c704f16
Change type of Window background from color to brush (#1755) 2022-10-21 16:17:22 +02:00