This fixes the contents of the `n`-th repeater inside the
`ComponentContainer` to also show up in the `n`-th repeater *after*
the `ComponentContainer`.
The ComponentContainer is lowered to a Comonent Container and a
dynamic tree node. The tree node is managed manually and I messed
up the repeater indices since there were no entries in the repeater
array for the embedded components. That mad things hard to keep
consistent as components get merged.
This chnages that: It lowers a Component Container to Something like this:
```slint
ComponentContainer {
if false: Emtpy {}
}
```
This way the standard mechanismns make sure we have something to put into
the repeater list and that unscrews the indices, saving a bit of code along
the way.
The inserted repeated node is still marked as `is_component_placeholder`, so
that we can wire it up as needed.
This exposes FocusReason to .slint, and adds it as an argument to focus-event-changed callback on FocusScope to close#8387. It also adds two new callbacks, focus-gained and focus-lost, which are identical to focus-event-changed but are only invoked on focus gain or loss respectively.
In addition to this, it removes the FocusEventReason::AccessKit variant, replacing it with the mouse variant to hopefully make AccessKit more compatible with any Slint code that will use FocusEventReason.
Finally, I added two tests based on focus_change_event.slint, one for testing the FocusEventReason argument and another for testing the new callbacks.
close#8387
ChangeLog: Added `focus-gained` and `focus-lost` callback to FocusScope. Pass an `FocusReason` enum to the FocusScope callbacks
Closes#5992
Adds the enum FocusEventReason and makes it an argument for FocusEvent. This reason could eventually be exposed in Slint to solve #8387.
Using the focus reason tracking, I also added a select all on keyboard focus for TextInputs (except on macOS), which should close#5992.
ChangeLog: TextInput selects its content when focused with the keyboard on Windows and Linux
From the v1.11.0 crash reporter:
There is a panic in
`target/x86_64-unknown-linux-gnu/release/build/slint-lsp-8494405be069a534/out/main.rs:115729:64`
```
called `Result::unwrap()` on an `Err` value: Other("Could not initialize any renderer for LinuxKMS <REDACTED: user-file-path> from Skia renderer: Error opening device <REDACTED: user-file-path>: No such file or directory (os error 2)\\nError from FemtoVG renderer: Error reading DRM resource handles: Permission denied (os error 13)\\nError from Software renderer: Error opening device <REDACTED: user-file-path>: No such file or directory (os error 2)\\nNo renderers configured.")
```
That line in the generated file is in
```
115728 │ fn window_adapter_impl (& self) -> sp :: Rc < dyn sp :: WindowAdapter > {
115729 │ sp :: Rc :: clone (self . window_adapter_ref () . unwrap ()) }
```
Relevant backtrace:
```
6 "core::result::unwrap_failed"
7 "slint_lsp::preview::ui::slint_generatedPreviewUi::PreviewUi::new"
8 "slint_lsp::preview::ui::create_ui"
```
So the theory is that user_init need the window for some reason.
(eg, could be needing the scale factor to conver sizes or some other
things that needs the window)
So make sure we do the test before calling user_init
We must take care that all access to property that we consider constant
in global are accessed after the global has been initialized.
So initialize the global before the properties.
Fixes#8375 , #8337
... by changing the resolution for the `WindowItem` to traverse the
item tree from the current item, instead of going to the window.
This doesn't quite fix#4298 because `rem` resolution is still missing.
That requires the built-in default font size function to be fixed as
well, which is non-trivial.
cc #4298
Conversion from negative float to unsigned is saturating to 0 in rust
and undefined behavior in C++, we should therefore handle the case
properly
Fixes#8222
This does some refactoring to allow builtin item functions to return a
value:
- builtin member functions are no longer BuiltinFunction, but they are
just normal NamedReference
- Move special case for them in the LLR/eval
Adds methods to change a `string`'s case to lowercase or uppercase.
They use Rust's `to_lowercase` and `to_uppercase` `String` methods.
ChangeLog: Added string.to-lowercase and string.to-uppercase
Closes#7860
Add two new float to string conversion methods that mimic
JavaScript's Number.toFixed() and Number.toPrecision().
They are implemented as no_mangle functions similar to the already
existing float to shared string conversion.
Closes#5822
`__CARGO_FIX_YOLO=1` is a hack, but it does help a lot with the tedious fixes where the result is fairly clear.
See https://rust-lang.github.io/rust-clippy/master/index.html#/needless_borrow
```
__CARGO_FIX_YOLO=1 cargo clippy --fix --all-targets --workspace --exclude gstreamer-player --exclude i-slint-backend-linuxkms --exclude uefi-demo --exclude ffmpeg -- -A clippy::all -W clippy::needless_borrow
cargo fmt --all
```
Add a check for 2024 edition warnings so we make sure users can use Slint
in a crate using the 2024 edition when it gets released.
The warnings can be silenced as we don't handle types in Slint that
have Drop with side effects other than memory allocations
New warning introduced in nightly rust
```
error: use of a double negation
--> /home/runner/work/slint/slint/target/debug/build/test-driver-rust-805d926ab786688f/out/expr_arithmetic.rs:10:55
|
10 | assert_eq!(instance.get_t4(), 3 + - 5 - 8 - -9 * --- 120);
| ^^^^^^
|
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
= note: use `-= 1` if you meant to decrement the value
help: add parentheses for clarity
|
10 | assert_eq!(instance.get_t4(), 3 + - 5 - 8 - -9 * --(- 120));
|
```
type-safety+=1
This would avoid for example using a sub-component index in an array of
instances or items.
It also self-document what the index is for.
There are still a couple of cast from repeater-index to u32 because we
do some hack with the repeater-index number for component containers
We also cast back to numbers in order to convert it to string in the
generated code.
Because we set the viewport-width several time to different value during
the layouting of the ListView, it will cause this property to always be
dirty. In particular, this causes permanent restart of the fluent's
scrollbar animation on the size of the handle, causing continous
repaints.
It can panic if lazily constructing the window adapter.
Make sure it is actially not lasily constructed, we don't need lazy constructor when not embedding anyway.
Introduce two new properties for string in .slint:
- .is-empty: Checks if a string is empty.
- .character-count: Retrieves the number of grapheme clusters
https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries
These additions enhance functionality and improve convenience when working with string properties.
Only the interpreter is implemented so far
MacOs won't work yet because we don't disable the default winit menubar
The viewer don't support removing the MenuBar yet
Popups are stored in a HashMap and are assigned an ID so popup.close(); closes the correct popup and so a single PopupWindow cannot be opened multiple times
This currently doesn't have public API to enable it yet.
TODO:
- Error handling in the compiler
- Public API in the compiler configuration
- Documentation