Commit graph

1507 commits

Author SHA1 Message Date
Simon Hausmann
93dcd90c74 winit: Add API to provide access to the event loop and the winit Window
To avoid exposing the internal custom event, this also wraps the enum in
a public SlintUserEvent enum.
2023-04-24 12:59:06 +02:00
Simon Hausmann
04262414b1 winit: Fix documentation for the crate
Despite this being an internal crate, provide some better docs and links
so that we _can_ recommend folks to use it.
2023-04-24 12:59:06 +02:00
Simon Hausmann
8c0a068099 winit: Adjust the window size to satisfy changed min/max constraints
Like Qt, ensure the window size is in bounds of updated min/max
constraints.

Fixes #2581
2023-04-21 16:06:34 +02:00
Simon Hausmann
84c4f817f1 Fix resizing of the preview in SlintPad after selecting a new demo
I misread the spec about the name conversion for the DOMStringMap used in JS for the dataset
attribute and the name used in the DOM.
Both, the setting in preview_widget.ts as well as
reading it in windowadapter.rs counts as JavaScript access, so use camel case.

The old variant happened to work in Safari.

Amends 43234dafc5
2023-04-19 11:40:14 +02:00
ogoffart
bd63218412 Bump version number to 1.0.1 2023-04-18 14:56:40 +00:00
Simon Hausmann
f9e561e21f Prospective fix for panic when running material style under Wayland/Gnome
When for example only a maximum height is set, but no maximum width,
avoid passing -1 or 0 to winit for the width. Instead use the same large
value was for Qt.

cc #2562
2023-04-18 08:57:01 +02:00
Cole Lawrence
af30896e4a Add always-on-top property to Window element 2023-04-15 13:58:47 +02:00
Simon Hausmann
2a4a6f7887 winit: Fix dark color scheme not always being detected correctly
When the dark color scheme was queried before the window was mapped, we'd initialize it to false,
but never update it to the actual theme value.

Fixes #2533
2023-04-12 10:40:28 +02:00
Simon Hausmann
81d3b4a930 Qt: Fix missing support for horizontal alignment in TextInput
Apply horizontal alignment to the text lines created by QTextLayout.

Fixes #2524
2023-04-11 14:21:01 +02:00
Simon Hausmann
ab051680e5 janitor: Rename GLWindow to WinitWindowAdapter
It's no more an "OpenGL Window", it's the type that adapts winit to our windowing
system abstraction.
2023-04-05 11:04:19 +02:00
Simon Hausmann
43234dafc5 Fix loading of demos in SlintPad
Add a data attribute hack to force auto-resizing to the preferred size
in SlintPad. Otherwise the initial size of the hello world will remain
in effect when loading other demos.
2023-03-31 15:23:55 +02:00
Simon Hausmann
3b9c2ec7f1 Fix wasm build 2023-03-30 09:28:37 +02:00
Simon Hausmann
d6c9ddd27a Qt: Avoid setting 0x0 as maximum size on a window
Centralize the code to ensure that we only set a maximum size if > 0 into corelib.
2023-03-30 08:43:48 +02:00
Simon Hausmann
528f428c60 Unify the code to compute the optional min/max window size into a helper function 2023-03-30 08:43:48 +02:00
Simon Hausmann
71253ef52e Share logic for determining if winit window is resizable
In show() use the same logic as in apply_geometry_constraint.
2023-03-30 08:43:48 +02:00
Simon Hausmann
a7043a3a36 Apply a maximum size to a window only if it's non-zero
A window with zero width or height doesn't make sense.
2023-03-30 08:43:48 +02:00
Simon Hausmann
84b3e8f78a Cleanup
When modifying the window builder in show(), don't mix shadowing and variable re-assignment.
In this case, just use assignment.
2023-03-30 08:43:48 +02:00
Simon Hausmann
ab5f6101fa When applying geometry constraints, make the window resizable only when an min/max is set on the window
(also removed redundant set_resizable(true) call)
2023-03-30 08:43:48 +02:00
Olivier Goffart
e8f21035ff Fix the slide_puzzle canvas size on wasm
Since winit can't handle resize from the CSS or JS, work it around in
the demo by calling set_size on the slint window.

Also fix slint_size panicking not working on wasm as the map_state was
mutably borrowed by the set_size, and this may recurse into other
functions (eg, draw) causing a panic. So don't keep the state borrowed
when calling winit.

Another fix is fixing the initialization size of the window item when
the initial size is set with set_size

Fixes #547
2023-03-29 15:41:07 +02:00
Simon Hausmann
09f269b6ff Minor cleanup
Use the new winit_handle() function to remove one level of indentation.
2023-03-28 11:52:33 +02:00
Simon Hausmann
5879e1ec71 Fix touch events not working for wasm builds
Work around a winit bug for WASM builds by pinning to the exact winit
version and making the coordinates relative again.

cc #2424
2023-03-28 11:52:33 +02:00
Simon Hausmann
b38df20d9a Add a feature to enable system fonts with the software renderer
If we have a file system, then we can allow users of the software
renderer to support text rendering by from fonts served by the file
system.

cc #2100
2023-03-28 11:33:44 +02:00
Simon Hausmann
a45421b425 Speed up Linux builds
Remove the dark-light dependency, as it significantly slows down the
build on Linux. On Windows/Mac/Web it's not needed. On Linux Desktop,
folks are likely going to have Qt installed - where this works - and on
Embedded Linux the assumption is that it's not running as Linux Desktop.

On Linux the number of dependencies for `-p slint` goes down from 418 to
328. Build time on my machine goes from 1 minute down to ~50 seconds.
2023-03-28 11:32:59 +02:00
Simon Hausmann
278d650d7d Fix error messages when supplying invalid sizes to Skia and FemtoVG
Apply the same error message as for
https://github.com/slint-ui/slint/pull/2402#discussion_r1146657846
2023-03-27 12:47:31 +02:00
Simon Hausmann
029c91d577 Fix missing window title when using Slint on Wayland
Winit defaults to sctk-adwaita with ab_glyph rendering. Pick the same
default when the wayland feature is enabled on our end.

This is a stop-gap. In the future we should try to implement the window
decoration rendering ourselves.

Fixes #2188
2023-03-27 10:33:47 +02:00
Simon Hausmann
2872c13fff Fix using the software renderer with the native style
Provide access to the window inner also from within the software
renderer, so that the native style rendering can query the active state.

Fixes #2404
2023-03-24 16:29:21 +01:00
Simon Hausmann
8ffb5131c7
Introduce error handling in the FemtoVG and Skia renderers (#2402)
Avoid unwrap() and expect() and instead propagate errors all the way
down to run_event_loop(), show(), and hide() in the Slint AIP.
2023-03-24 14:18:11 +01:00
Simon Hausmann
ef07da4893 Add comment about resizing tweak on macOS 2023-03-23 15:36:42 +01:00
Simon Hausmann
c54e1cba43 Fix support on GLX displays with FemtoVG
In order for GLX support to work, we need to create the X11 window with
the same visual as in the GLX configuration. That requires delaying
the creation of the window.

This is done in four parts:

- The window builder is re-introduced in the winit backend create
  internal renderer interface.
- The glcontext helper code for wasm was moved into a separate function
  (less indentation).
- The loop over different display preferences was replaced with a
  preference to the "window system native GL interface" over EGL,
  which should achieve the same as the fix for #2162. Upstream glutin
  defaults to this and so do various downstream projects.
- Use glutin-winit for the actual display selection.

This covers the FemtoVG bits of #2269
2023-03-23 15:36:42 +01:00
Tobias Hunger
28c35279e4 accessibility: Do not freeze trying to find items at position
Fix the code to always return a direct child widget or nullptr. The
documentation says to return a direct or indirect child, but the
implementation expects a direct child.

Fixes: #2195
2023-03-20 15:29:40 +01:00
Olivier Goffart
82e23a114b Wasm: don't print fake keys in input box
We should only forward keys that are a single character. Other ones are
just virtual keys that should't be processed.

This regressed in commit 32d2ba7

Fix #2327
2023-03-09 10:46:03 +01:00
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +01:00
Olivier Goffart
04eacbb526 Don't panic twice when the rendering panics 2023-03-06 17:13:33 +01:00
Simon Hausmann
9fcce74b2f Fix build with RUST_FONTCONFIG_DLOPEN
Since the fontconfig ffi code moved to the femtovg renderer create, we
need to build the build.rs feature setting.
2023-03-06 16:40:26 +01:00
Simon Hausmann
aac74a6271 Fix build without x11 2023-03-06 14:02:18 +01:00
Simon Hausmann
6d968aa329 Extract the FemtoVG renderer into a separate crate
This will be needed for a future experiment. Unlike the Skia renderer,
which operates on raw window handles, the FemtoVG renderer exposes a
different interface where it assumes that the caller takes care of the
OpenGL context state. This means more boilerplate remains in the winit
backend, including the glutin dependency. The upside is that it will
allow using the FemtoVG renderer in environments without glutin.

In order to work in an environment without fontconfig or memmap, the
crate has two features:

  - fontconfig (set when we anticipate fontconfig to be available at
    run-time and libloading being available at compile time).
  - diskfonts (set when we want to be able to load fonts from disk)

The winit crate enables fontconfig on "Linux" and diskfonts on !wasm.
2023-03-06 11:45:28 +01:00
Simon Hausmann
fb06cd8d51 winit: Fix rendering when moving windows between monitors with different scale factor
Adjust the size of the underlying graphics surface to avoid rendering
artefacts.

Fixes #2282
2023-03-03 15:22:56 +01:00
Simon Hausmann
fdb719a65e femtovg: Fix panic when rendering colorized image with transparent global alpha
This is reproducible in the energy monitor when scrolling down in the
settings page.

In the helper function to colorize an image, we did not expect
brush_to_paint() to fail. The condition of a transparent colorize color
was handled earlier, but it turns out that brush_to_paint() also checked
the global state as an optimization.

This optimization is wrong, as the cached colorized image should not
depend on the untracked global transparency.

So this patch adds a graceful handling of brush_to_paint returning None
for defensive measures, but also moves the early return on an global
transparent alpha to the call sites where it makes sense.
2023-03-03 15:22:28 +01:00
Simon Hausmann
1473637ce3 Remove dark-light dependency on the web
winit 0.28.2 was released today, which supports `Window::theme()` on the
web.
2023-03-02 18:53:55 +01:00
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
ed51f6b7b6 Femtovg backend: fix text_input_cursor_rect_for_byte_offset for the last glyph
It was on the wrong line if not a \n, and on the wrong position if a \n
2023-02-17 15:51:14 +01:00
Simon Hausmann
3c686047cd Silence debug output on macOS and Windows when selecting text
Use a truly silent no-op clipboard context.
2023-02-17 15:27:12 +01:00
Olivier Goffart
ca7b2e0bb8 Harmonize style properties 2023-02-10 16:49:25 +01:00
Olivier Goffart
fb8a7fb1e5 winit backend: fix compilation with wayland but not x11 2023-02-10 11:18:05 +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
Simon Hausmann
59e0723793 Improved fix for panic when using OpenGL with the winit backend on Linux
Replace the patch with use of the glutin API as advised upstream (and
also implemented in glutin-winit).

Closes #2215
2023-02-09 16:16:36 +01:00
Simon Hausmann
476300ded7 Prospective fix for preview panicing on Linux v2
Avoid unwrap in the display/context selection try function.
2023-02-09 14:24:20 +01:00
Simon Hausmann
e8439061e8 Prospective fix for vscode extension preview not working on Linux
The CI build vsix panics on line 84 in glcontext.rs. There's no unwrap()
there but there's one nearby. I wasn't able to reproduce this with a
local build, so this is a prospective attempt, assuming that this is due
to the attempt of glx-over-egl display configuration finding.
2023-02-09 09:45:54 +01:00
Olivier Goffart
a19efc30db
Replace the MAX_BUFFER_AGE const generic with a runtime enum
Having a const generic for that didn't turn to be a good API.
Also made the C++ side more difficult

(Also renamed buffer_stride to pixel_stride)

Closes #2135
2023-02-08 14:44:01 +01:00