Commit graph

362 commits

Author SHA1 Message Date
Olivier Goffart
20061392cd
C++: Fix compilation of PopupWindow::show in changed callback
Some checks are pending
CI / ffi_32bit_build (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.82) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.82) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.82) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
The window is dependent of an lambda `auto` parameter, so the `template` keyword is required in order to call show_popup

Fixes #8710
2025-06-16 23:25:24 +02:00
Simon Hausmann
06a19e59ad
slint: Change Platform.os to return a new enum OperatingSystemType (#8679)
* slint: Change Platform.os to return a new enum OperatingSystemType

cc #8631
2025-06-12 14:25:16 +02:00
Tobias Hunger
93f72b8c99 core: Fix the component container
Some checks are pending
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.82) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
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.
2025-06-05 13:48:16 +02:00
Avery Townsend
8c4ccabf7d
Expose FocusReason to .slint as an argument in focus-event-changed and add focus-gained and focus-lost callbacks (#8569)
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
2025-06-04 09:51:26 +02:00
Olivier Goffart
dc915b1af3 C++: add asserts that we are in the main thread
Some checks are pending
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.82) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
- In the timer functions
 - in the generated getter/setters and callback invocation
2025-05-28 11:29:48 +02:00
Avery Townsend
c41d4a4df3
Add FocusEventReason to FocusEvent and add a select all on keyboard focus for TextInput (#8523)
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
2025-05-27 07:56:13 +02:00
Olivier Goffart
2f2116686f C++: forward declare explicitly to make the code more robust
We currently forward declare classes as we use them in functions.
But this breaks if classes with the same name were declared in the
parent namespace. As shown with this example

```C++
// Uncomment that line to make the code break
//struct SharedGlobals;

namespace ns {
    // Is that a forward declaration in `ns`?
    // Depends if it was declared before in the parent namespace
    void foo(struct SharedGlobals *x) {}

    // Actualy define ns::SharedGlobal
    struct SharedGlobals { int x; };

    int xyz() {
        SharedGlobals globals;
        foo(&globals);
    }
}
```

So make sure we forward-declare the classes properly to be more robust
and be able to include generated file with namespace after a file
without namespace

CC #2909
2025-05-26 18:32:09 +02:00
Olivier Goffart
9289940371 Prospective panic fix in the rust generated code
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
2025-05-07 09:04:02 +02:00
Simon Hausmann
f983cf0b19 Add Platform.os as well as a rudimentary test 2025-05-06 13:06:27 +02:00
Olivier Goffart
86978e9fc1
Rust generated: fix constant non-inlined global
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
2025-05-05 18:55:19 +02:00
Olivier Goffart
ff2e2e6731
Compiler: Fix changed callback on private global properties
The code would fail to compile because the property would not be seen as
used and would be removed, but not the change callback.

Fixes #8269

Also fix a segfault in the added test because it will initialize the
change callback (and therefore query the properties) because the
SharedGlobal structure is fully initialized.
So we must only initialize the change callback on global after the
SharedGlobal is fully initialized
2025-04-25 16:10:12 +02:00
Bryce Happel Walton
dedc5d31e2
Added Exp and Ln functions to Slint (#8226)
ChangeLog: Added Math.exp and Math.ln
2025-04-25 14:30:38 +02:00
Simon Hausmann
eb825f2e95 Support default-font-* properties in Live-Preview
... 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
2025-04-24 09:18:45 +02:00
Olivier Goffart
cd8ab8ce53
Fix array index access at negative index
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
2025-04-22 11:28:09 +02:00
Olivier Goffart
9058456fbf
live-preview: don't replace the native menu bar with the previewed one
Always use the non-native one for the previewed component
2025-04-17 17:12:23 +02:00
Nigel Breslaw
ffce61ca97
HSV should wrap hue values otherwise it outputs an invalid hue of black (#8024)
Fix by wrapping around at 360.
Added tests.
Updated the docs.
2025-04-03 12:33:40 +03:00
Olivier Goffart
7b8ef71ddd link_section needs unsafe with edition 2024
Second part of #7998
2025-03-31 17:35:22 +02:00
Olivier Goffart
fa650ed5ec Allow to have builtin item function to return a value
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
2025-03-31 14:06:24 +02:00
Olivier Goffart
aca30901be C++: put the parent in a weak pointer
Right now we always `lock().value()` it which is the equivalent of
`upgrade().unwrap()` in rust, this helps because it keeps the parent
alive when we are calling function in it.

Ideally we should also check that it wasn't deleted, but that's another
issue.

Fixes #7880
2025-03-28 17:24:14 +01:00
Olivier Goffart
a80f14e7d8 Fix re-instentiating if elements when the condition is dirty
Fixes #3953
2025-03-27 15:37:07 +01:00
Olivier Goffart
3621fbcbd3
C++: fix mod with negative number again
`mod(-42, 2)` would return 2 instead of 0
2025-03-27 13:41:29 +01:00
crai0
c103d37828
Add string.to-lowercase and string.to-uppercase (#7922)
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
2025-03-25 09:53:54 +01:00
Olivier Goffart
51523e981f Compiler: Fix when one branch of a void condition is not void
Fix panic or warning in the generated code

Fixes #7864
2025-03-21 14:37:10 +01:00
Simon Hausmann
cc932fceb9
Improve font embedding for MCUs when bundling translations (#7875)
Include messages from bundled translations into the character set used for deciding which glyphs to embed.
2025-03-18 11:54:28 +01:00
crai0
a8eb44b739 Promote float to double in cpp code gen 2025-03-18 11:44:28 +01:00
crai0
e6e7b4e3df Fix cpp code gen 2025-03-18 11:44:28 +01:00
crai0
4bb7412460 ChangeLog: Add float.to-fixed and float.to-precision
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
2025-03-18 11:44:28 +01:00
Olivier Goffart
a6a142f9c8 C++: fix a bug in which a substraction could overflow
There was an image like this:
```slint
height: 40px
Image {
     width: parent.width;
     height: self.source.height * 1px;
     source: @image-url("....");
}
```

The `y` propery ended inlined like so:
`(40 - the_image.source.get().size().height)/float(2)`
but since height was `unsigned` the C++ rules means that the operation
happens as unsigned and we have an overflow. and `y` turned out to be
very big instead of slightly negative (for image whose height was larger
than 40)
2025-03-05 08:25:45 +01:00
Olivier Goffart
5ab791416b Implement Property::set_constant in C++ 2025-03-03 00:50:09 +01:00
Olivier Goffart
79b31153c5 C++: implement the ItemTreeVTable::window_adapter
This is required to fix closing popup with the Qt backend, as we use the
window_adapter as a hack to get the root window_adapter (as opposed to
the popup one)

(That function was only used for the ComponentContainer and was not
implemented for C++ before)

Note that this reinterpret a
`Option<slint::private_api::WindowAdapterRc>` to just a `WindowAdapterRc`
This is because `Option` is only forward declared in C++ as it is not
generaly `#[repr(C)]`,  but we assume (and assert) the usage of a niche.

As reported in https://chat.slint.dev/public/pl/ihnwtdgp7fb75k4aj5ou3p4idc
2025-02-28 00:34:14 +01:00
Olivier Goffart
185d49e238
Fix possible panic when ContextMenuArea gets destroyed when the menu is visible 2025-02-25 21:38:13 +01:00
Simon Hausmann
dde0ebe201 Fix build for C++ generated code for embedded textures 2025-02-24 17:02:10 +01:00
Simon Hausmann
df6c99871d Change TargetPixelBuffer's draw_texture function to take a data structure instead of many arguments 2025-02-24 17:02:10 +01:00
Olivier Goffart
2e4353d3c9 Implement closing of popup menus 2025-02-10 20:27:43 +01:00
Olivier Goffart
c0b72cad2f
ContextMenu: show submenu on hover after a timeout
This means that the parent menu still get the mouse events

Also add the ability to close the menu programmatically
2025-02-07 13:27:32 +01:00
Yuri Astrakhan
feb7a864df Auto-fixed clippy::useless_format
See https://rust-lang.github.io/rust-clippy/master/index.html#useless_format

```
__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::useless_format

cargo fmt --all
```

`__CARGO_FIX_YOLO=1` is a hack, but it does help a lot with the tedious fixes where the result is fairly clear.
2025-02-07 13:16:50 +01:00
Olivier Goffart
7104c6e88e
Rudimentary key navigation of the popup menu (#7556)
Closing the menus is still not implemented
2025-02-07 10:01:40 +01:00
Yuri Astrakhan
6324b35e94 Auto-fixed clippy::needless_borrow
`__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
```
2025-02-07 09:02:45 +01:00
Yuri Astrakhan
61de4d56b0 Fix all format arg inlining
Ran this command:

```shell
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2025-02-06 10:16:20 +01:00
Olivier Goffart
13f07018c9 C++: initialize the backend before the translations
Otherwise initializing the translation won't work.

This can't be tested because the testing backend is always initialized before.
And also hasn't been a problem on MCU where the feature is the most usefull
because it also uses custom backend there initialized before
2025-02-03 14:00:59 +01:00
Olivier Goffart
7fba31a7b0
Refactor: use Struct instead of Type for the type in a Expression::Struct 2025-02-03 10:19:30 +01:00
Olivier Goffart
094ff8f56b Refrersh the menubar when one of the property get changed
Install a PropertyTracker to update the shadow tree if something changes
2025-01-30 17:43:33 +01:00
Olivier Goffart
010126992e MenuItem with for and if 2025-01-30 10:08:22 +01:00
Olivier Goffart
86426087c8
Silence 2024 edition warnings
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
2025-01-28 14:04:19 +01:00
Olivier Goffart
bb793da832
Prospective CI fix with Rust nightly
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));
   |
```
2025-01-28 11:37:26 +01:00
Olivier Goffart
6c7a50bd3d LLR: used typed index for vectors in the LLR
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.
2025-01-26 11:44:54 +01:00
Olivier Goffart
1aeeba7d6b llr: Store a GlobalIndex in the EvaluationContext instead of a reference
So that the CompilationUnit is only borrowed once and can be made
mutable
2025-01-26 11:00:42 +01:00
Olivier Goffart
55bafbb51b llr: don't store Rc<SubComponent> but an index instead
The goal eventually is to serialize the LLR and we can't do it if it
uses Rc inside.
2025-01-26 11:00:42 +01:00
andber1
813e790431 Ignore pedantic and nursery clippy warnings in generated code 2025-01-23 12:16:57 +01:00
Olivier Goffart
2df0b8bf20 ListView: adapt the viewport's width based on the minimum-width of delegate
(Instead of their `width` property)
2025-01-21 14:31:55 +01:00