Commit graph

513 commits

Author SHA1 Message Date
Olivier Goffart
01850e0b82 C++ live-reload: support getting the model back 2025-07-09 11:23:33 +02:00
Olivier Goffart
43b436a89f WIP: live-reload for C++
Missing feature:
 - conversion between Value and enums
 - conversion from value to Model
 - Compatibility with the testing framework (get the `VRc<ItemTreeTable>` from an instance)
2025-07-09 09:32:17 +02:00
Olivier Goffart
5af0dd81ab
live-reload: watch the parent directory instead of the files
Otherwise that doesn't work when the editor renames the files and then
remove it, such as what vim or helix are doing

Fixes #8857
2025-07-07 13:38:29 +02:00
Olivier Goffart
647dd45213 Make a live reload module in the slint-interpreter 2025-07-04 10:07:22 +02:00
Olivier Goffart
ec12f22653 interpreter: Fix panic when a model return invalid value
This fixes the test on tests/cases/model/models when using the rust
interpreter, as the second test has a "broken" model, the data is left
uninitialized, and this causes a data of the wrong type which causes
panic when it is being used.
2025-07-04 10:07:22 +02:00
Olivier Goffart
d2b3287876 ComponentHandle: don't rely on the Inner to be a VRc<ItemTreeVTable>
Because i want to be able to hold componetns that do not directly
implement ItemTreeVTable, but only forward to it
2025-07-04 10:07:22 +02:00
Olivier Goffart
3823c1e8da Experimental support for Drag & Drop
Add a `DragArea` and `DropArea` elements.
It is currently gated as experimental.
2025-06-26 15:39:18 +02:00
Olivier Goffart
8db7db9571 core: Revert the change to use "C-unwind" calling convention
Some checks are pending
CI / tree-sitter (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / esp-idf-quick (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 / 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 / wasm (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 / wasm_demo (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 / fmt_test (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 broke the build on zephyr

```
/usr/bin/ld: /home/runner/work/slint/slint/build/zephyr/NSI/home/runner/work/slint/slint/build/zephyr/zephyr.elf.loc_cpusw.o:(.data.DW.ref.rust_eh_personality[DW.ref.rust_eh_personality]+0x0): undefined reference to `rust_eh_personality'
```
2025-06-12 15:29:23 +02:00
Tobias Hunger
a273af0264 interpreter: Use Optiopn<&T> instead of &Option<T>
... in the `set_debug_handler` function and related code
2025-06-10 16:49:40 +02:00
Tobias Hunger
d21e6680a3 live-preview: Recursively set debug-handler 2025-06-10 16:49:40 +02:00
Tobias Hunger
bd3c001c5d interpreter: Use Rc for debug_handler 2025-06-10 16:49:40 +02:00
Olivier Goffart
c0cac46009 Add --generate-link-to-definition in the docs of all our published crate
This is a nice nightly rustdoc feature and we should make use of it
2025-06-06 21:47:36 +02:00
Olivier Goffart
f91b61c8ee corelib: Remove the extern call in the vtable for wasm
In fact, remove it for non-C++

Because wasm doesn't support C-unwind. And actually warns about
incompatible ABI for the rest

Fixes #8449
2025-06-06 14:47:46 +02:00
Olivier Goffart
f39b3ab888 Use "C-unwind" API in our vtable
When using rust, allow panics to cross the boundaries of our vtable traits.
This avoids panic producing two backtrace with panic=unwind

This patch doesn't touch the ABI of out FFI interface, they stay extern "C", because
if a panic or exception crosses these boundaries, we are in trouble.
(Also, we have a panic=abort in our Cargo.toml anyway)
2025-06-06 14:47:46 +02:00
Nigel Breslaw
b763bf65ef
Tooling: Debug console for live-preview (#8630)
Previously to see errors or debug info using debug(...) required the output panel of a speperate IDE or for Slintpad to open the browser developer tools.

This PR adds a dedicated panel to the live-preview. Log messages include a link back to the source file and line number for fast finding where the message was generated. Syntax errors also now show in the logs.

By default the panel is minimised and logs will clear themselves on UI recompile. The last log message does show as a preview on the minimised bar meaning in many cases you never need to open the panel.
---------

Co-authored-by: Tobias Hunger <tobias.hunger@slint.dev>
2025-06-06 15:40:56 +03:00
Olivier Goffart
ba7e31dd3b Fix more nightly warnings 2025-06-06 12:30:45 +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
f3bcf7ab56
interpreter: Make the From<ModelRc> for Value implement set_row_data (#8575)
When converting a ModelRc<T> to a Value, the resulting model did not
implement set_row_data and therefore would not allow changing the model
from the code.
By adding a `TryFrom` bound, we can make sure set_row_data is
implemented.

This is technically a breaking change to add this bound, but most type
that implement From for value also implement TryFrom<Value>

These conversion function were added in
20443ec0df for Slint 1.9

ChangeLog: interpreter: The `From<ModelRc> for slint_interpreter::Value` now gives a model that supports `set_row_data`.
2025-06-02 16:02:16 +02:00
Olivier Goffart
99ab43e6e4 interpreter: Remove normalization in builtin enum conversion
Some checks are pending
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 / 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
CI / node_test (windows-2022) (push) Blocked by required conditions
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 (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 / mcu-embassy (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
Once upon a time, the enum were written in snake case in the .rs file,
but since ac4f3e97ad, they are written
in camel case, and the strenum crate takes care of moving that to kebab
case, which match our normalization, so there is no need to normalize
more.

The de-normalization was actually broken since
63f7533dc9 which changed a
denormalization into a normalization for the TryFrom<Value>
2025-05-30 10:59:13 +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
23962b3e25
Upgrade cbindgen and use unsafe(no_mangle) attributes (#8539)
To be compatible with the 2024 edition, we need to wrap the
`no_mangle` attribute in `unsafe()`.

The parsing for that in cbindgen was only added in the version 0.28,
but we couldn't upgrade cbindgen before because of a regression in
cbindgen 0.27 that prevented us from upgrading.
Now that cbindgen 0.29 is released with a fix, we can prepare for the
2024 edition
2025-05-26 11:21:33 +02:00
Tasuku Suzuki
83db461f63
Transition: Introduce in-out to allow writing symmetry animation (#8509) 2025-05-26 09:17:22 +02:00
Tobias Hunger
0e0b85cda7 live-preview: Extract data from Palettes
... and rpesent that data to the UI. No UI has been
implemented for this yet.
2025-05-21 16:28:03 +02:00
Tobias Hunger
63f7533dc9 compiler: Fix identifier normalization function
`__1` is a valid identifier, which we normalized to
`--1`, which is invalid.

This changes the nromalization function to leave a `_` in the first position.
2025-05-21 12:21:20 +02:00
omahs
74232eae8d
Fix typos (#8421) 2025-05-12 13:03:59 +02:00
Simon Hausmann
f983cf0b19 Add Platform.os as well as a rudimentary test 2025-05-06 13:06:27 +02:00
Olivier Goffart
ab572fc6de Janitor: Silence warning with nightly rust
```
warning: implicit autoref creates a reference to the dereference of a raw pointer
   --> internal/interpreter/dynamic_type.rs:170:26
    |
170 |         let mem_layout = (*instance).type_info.mem_layout;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: creating a reference requires the pointer target to be valid and imposes aliasing requirements
    = note: `#[warn(dangerous_implicit_autorefs)]` on by default
help: try using a raw pointer method instead; or if this reference is intentional, make it explicit
    |
170 |         let mem_layout = (&(*instance).type_info).mem_layout;
    |                          ++                     +

```

Taking a reference to the type_info is valid because the instance is a
valid instance in that function
2025-04-29 10:44:10 +02:00
Simon Hausmann
a50b8f8793
FemtoVG: Add support for WGPU based rendering (#8268)
Enable via the `renderer-femtovg-wgpu` feature flag.

cc #171
2025-04-25 14:37:32 +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
59f37b0f1f interpreter: don't panic trying to access callback alias
Fixes #8238
2025-04-22 18:41:08 +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
Tobias Hunger
50520f124f interpreter: Simplify EvalLocalContext
Replace the enum with the only variant that is actually
used: The one taking an `InstanceRef`.
2025-04-11 18:36:15 +02:00
Olivier Goffart
78a3757b7f
Remormat all the toml file again to fix npm upload
Commit cd6f2e2 reformated the .toml, but the 80 char width column is
judged too small to be practical

Add a .taplo.toml file

Also do not split feature array
2025-04-09 15:06:00 +02:00
Tobias Hunger
aaeb4a0df5 compiler: Add a DebugHook expression
You can not create this expression manually, but there
is a pass in the compiler that adds it to all set
properties in a compilation run.

All it does is basically associate an id with an expression,
so that we can then in a later step have the interpreter do
something with that information. Apart from that, it tries to
be as transparent as possible.

The LLR lowering removes that expression again, just so we can
be sure it does not end up in the generated live code.
2025-04-09 13:52:29 +02:00
Simon Hausmann
ac256d61d8 winit: replace special private function to spawn event loop with public API in the winit backend builder
This means the event loop spawning goes through the backend, which will permit for state from the Backend struct to be available when spinning the event loop even when spawning it merely.
2025-04-09 08:50:39 +02:00
Simon Hausmann
4e65998016 Clean up wasm-interpreter / winit interface
Use the window attributes hook instead of a private function in the winit backend.
2025-04-09 08:50:39 +02:00
Tobias Hunger
cd6f2e2cf2 ci: Format toml files
... using taplo with default settings

I tried this with 4 spaces indentation, but the patch is almost as
big as this one, so I went with default settings instead as that
is just easier:-)
2025-04-02 11:03:41 +02:00
Olivier Goffart
6010cf724c Hover on MenuBar should activate menu if a menu is already open
Fixes #7822
2025-03-31 14:06:24 +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
a80f14e7d8 Fix re-instentiating if elements when the condition is dirty
Fixes #3953
2025-03-27 15:37:07 +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
286bdc9ce5
Interpreter: Fix panic when animating a % property
Should register the Type::Percent as animated

Also avoid duplicating the binding for both min and max, and just make
one use the other.

Fixes #7761
2025-03-24 14:54:08 +01:00
Olivier Goffart
3250456e25
Interpreter: start timer after the initialization of properties
This is also how we do it in Rust and C++ generated code

Fixes #7848
2025-03-21 20:02:01 +01:00
Tobias Hunger
83c2bdd54c
interpreter: Support gradients in JSON conversion (#7913)
* interpreter: Support gradients in JSON conversion

Add gradients to the list of types that can be read from
JSON and serialized to JSON.

Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
2025-03-21 16:24:45 +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
ea17eee5fd Interpreter: Fix enabling only the Qt backend
when compiling, for example, the viewer with
`--no-default-features --features=backend-qt` in order to avoid
compiling winit, we would still not enable the qt backend because it
didn't enable the backed-qt feature in the selector that toggle the
`enable` feature in i-slint-backend-qt
2025-03-05 12:18:26 +01:00
Olivier Goffart
c3e32c1665
Don't enable image-default-formats by default, remove compat-1-10 feature
We decided that the compatibility with people having enabled the extra
format in image 0.24 [1] is not worth it compared to the extra compilation
time most people gets by default when they don't need this feature.
(Which is less than 10% slower when the feature is enabled)

Since then there is no need for compat-1-10, remove it

[1] by depending directly on image 0.24 in their Cargo.toml and enabling
the features, which will not work with Slint 1.10 that now use image 0.25
2025-02-22 11:15:18 +01:00