Commit graph

1430 commits

Author SHA1 Message Date
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
Olivier Goffart
35c5325fa5 Review the items that should have a stretch of 1 in a layout 2023-03-24 11:15:05 +01:00
Olivier Goffart
1089d29ebb Make Empty not fill the parent by default
Unless `preferred-*:100%` is set

Part of #2284
2023-03-24 11:15:05 +01:00
Olivier Goffart
b180661ff6 const propagation: simplyfy struct access
so that `{ min: 10px, max: 20px }.min`  get optimized
2023-03-24 11:15:05 +01:00
Olivier Goffart
8cefde7c3a Remove space before => in quote_spanned
That's the style encouraged by the documentation
2023-03-24 11:14:48 +01:00
Olivier Goffart
20973bdb7b Report warnings from the slint! macro 2023-03-24 11:14:48 +01:00
Tobias Hunger
799c9a9389
docs: fix some more links from rust docs into other docs 2023-03-24 10:18:04 +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
Simon Hausmann
00471449b4 Fix compilation of Rust generated code when the generated code uses a return statement inside a block
We cast the result of the body of functions or binding expressions to
the target type via `as _`. When the code contains a return expression,
that works fine, because `return`'s type is the never type, which can be
coerced to a value of any type. However when the return statement is
inside a sub-block, the type becomes `()`, for which the `as _` cast
fails.

Work around this by attempting to detect the situation (return produces
Type::Invalid) and omit the trailing cast.
2023-03-22 18:07:34 +01:00
Olivier Goffart
cc28d24065 femtovg: speedup TextEdit with many lines
The break_text algorithm was O(N²) in the number of lines because
break_text needs to layout the whole text dspite it would in theory
only need the first line.
Trim the text we pass to break_text so we don't need to re-layout the
end for the text for every call.

This is still O(N²) if there are very long lines.
Not sure we can fix that with the current femtovg break_text api

This makes TextEdit with many lines much faster.  Still a bit slow, but
at least usable
2023-03-22 11:10:03 +01:00
Olivier Goffart
d5a4ec87e0 femtovg: increase font cache size
Otherwise, the cache is trashed with already moderate text size causing
TextEdit to become quickly very slow (unusable) when the text becomes a
bit big.

Big text are horribly still slow but at least now it can be used without
freezing the app for minutes
2023-03-22 11:10:03 +01:00
Olivier Goffart
0f29b9e434 i-slint-core-macros: update to syn 2 2023-03-22 09:49:54 +01:00
Simon Hausmann
c14ec0fb9c Update Skia
- This allows creating the Skia GL interface without string allocations
- Port the item renderer to use SkImageFilters::Shader instead of
  SkImageFilter::Paint
2023-03-21 09:36:39 +01:00
Olivier Goffart
47ac396bc0 compiler: turn a warning into an error
cc #2024
2023-03-20 19:13:10 +01:00
Olivier Goffart
c82bb1515e C++ image: add some docs
Note: Don't use cbindgen to generate `operator==` for public types.
Because it doesn't have docs and the documentation show warnings
otherwise
2023-03-20 17:22:56 +01:00
Olivier Goffart
be47c8464c C++: implement creation of image from raw data
Issue #616
2023-03-20 17:22:56 +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
4cf44ea69d Mark StandardListViewItem and TableColumn as #[non_exhaustive]
Closes #2330
2023-03-18 09:04:48 +01:00
Simon Hausmann
032faad210 software renderer: Fix rendering artefacts when deleting components when using the partial renderer
Upon deletion we have little choice but to refresh the screen :(
2023-03-09 15:14:15 +01:00
Tobias Hunger
3d87b3ab93 clippy: Allow redundant_clone in generated rust code
This disabled about 70 clippy warnings like this one:

```
warning: redundant clone
     --> target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:44279:37
      |
44279 |                      (if (((r#state . clone ()) . r#previous_state as f64) == (1f64 as f64)) {
      |                                     ^^^^^^^^^^^ help: remove this
      |
note: cloned value is neither consumed nor mutated
     --> target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:44279:28
      |
44279 |                      (if (((r#state . clone ()) . r#previous_state as f64) == (1f64 as f64)) {
      |                            ^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
```
2023-03-09 12:12:03 +01:00
Tobias Hunger
d1aaba8117 clippy: redundant clone fix in generated rust code
This fixes about half the `redundant clone` issues that clippy reports
in our generated rust code.
2023-03-09 12:12:03 +01:00
Tobias Hunger
0b03a0646a clippy: Allow cmp_owned in generated rust code 2023-03-09 12:12:03 +01:00
Tobias Hunger
7c19cde055 clippy: Allow eq_op in generated rust code
I get the following clippy errors in the energy monitor:

error: equal expressions as operands to `-`
     --> C:\src\slint\target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:47254:94
      |
47254 | ...   (slint :: private_unstable_api :: re_exports :: LogicalLength :: new (((((0f64 as f64) - (0f64 as f64)) as f64) * (((1f64 as f64) *...
      |                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

error: equal expressions as operands to `==`
     --> C:\src\slint\target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:45382:18
      |
45382 |                  (((0f64 as f64) == (0f64 as f64))) as bool }
      |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

I am not surprised that the generated code sometimes produces code like
this (even though the other demos do not!), so I went ahead and silenced
these errors.
2023-03-09 12:12:03 +01:00
Olivier Goffart
233bc61c8e Flickable: capture the event if the flickable can flick even if it is at the end
When scrolling the printer demo, I often end up closing or opening
element i don't want to because we reached the end and therefore it is
not scrolling and forwarding the event
2023-03-09 11:35:57 +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
Florian Blasius
1237707b7a
scroll-view: add min width/height vor scorll bar (#2353) 2023-03-09 09:08:48 +01:00
Olivier Goffart
3101c278dc Janitor: rename a 'data' variable 2023-03-08 11:44:42 +01:00
Olivier Goffart
50dad538a1 Partial renderer: take in account change in clipping and parent geometry
... as well as opacity

When an item change its geometry or clipping, one really must also
refresh all the children, even the ones outside of the item.

And if the position of the parent changes, the old offset must still be
used to compute the geometry

This change also add the clip to the dirty region so we don't need to
draw so much for clipped items
2023-03-08 11:44:42 +01:00
Simon Hausmann
7d984c7cb9 Skia: Improve quality of rounded rect rendering
Enable anti-aliasing, just like with FemtoVG and Qt.
2023-03-08 10:42:24 +01:00
Olivier Goffart
488fb14846 Fluent style: Adjust disabled scrollbar background color
So that the TextEdit looks alright when disabled

Fixes #2281
2023-03-07 11:48:21 +01:00
Olivier Goffart
db12795032 swrenderer: gradient with opacity 2023-03-07 07:16:31 +01:00
Olivier Goffart
5a54fcfeb1 swrenderer: fix image drawing when the image is not stretched to the geometry
This would cause some of the image to be drawn outside of the clip
region, which may even lead to panics

(Fix changing pages in the energy-monitor demo)
2023-03-06 17:13:33 +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
c10349b2d1 Fix software renderer system fonts on some Yocto distros
Add "Liberation Sans" as another default system font we could look for.
2023-03-06 13:55:53 +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
f4c30ce46e Fix panic when accessing a global from init that's not used otherwise
Make sure to visit the named references in the init code, when
collecting globals.

Fixes #2312
2023-03-03 15:23:57 +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
1d82c179d1 Fix panic when invoking unused callback aliases with the interpreter
Don't try to install a callback handler that captures an invalid
expression. The llr pass has an invalid expression guard, and so does
the rest of this handle_property_bindings_init callback.

Fixes #2319
2023-03-02 19:02:25 +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
Tobias Hunger
42d1fbdbcf
docs: Use it's, etc. more consistently (#2287) 2023-02-24 17:42:22 +01:00
Olivier Goffart
a89c5db8db Fix crash when a state condition is detected as constant
States are never constant because the generated state binding depend on
the time as it register the time it was set for the pottential animation

Also adjust the assert so it assert correctly which the right message

Fixes: #2274
2023-02-24 16:43:48 +01:00
Tobias Hunger
5b347e0b13 Add @tronical's suggestions
... and more links ...
2023-02-24 16:09:11 +01:00
Tobias Hunger
ba99dc96a7 docs: Add some doc comments to enums
Update enumdocs xtask to generate the right file...
2023-02-24 16:09:11 +01:00
Tobias Hunger
f7de5d4602
docs: Go over builtin_elements.md (#2280)
Co-authored-by: Simon Hausmann <hausmann@gmail.com>
2023-02-24 11:03:56 +01:00
Simon Hausmann
19d914f548 Fix SLINT_EMBED_RESOURCES environment variable
The logic was inverted: Setting to true should embed everything, while
false should be the same as if it's not set: Only embed built-in
resources (as always).
2023-02-23 21:10:43 +01:00