Commit graph

505 commits

Author SHA1 Message Date
Tobias Hunger
b5520ef370 interpreter: Expose visibility of exported components 2025-02-05 12:56:32 +01:00
Tobias Hunger
d9c22bcdfe interpreter: Fix clippy warnings
I was just looking whether my change introduced clippy warnings,
but took the opportunity to polish the codebase a bit.
2025-02-05 09:41:00 +01:00
Tobias Hunger
ded82cbb62 interpreter: Add JSON encoding/decoding for the interpreter values
Extract the `from_json` and `to_json` code from the viewer into the `interpreter`.

Extend the `from_json` and `to_json` a bit. Add some simple tests while at it.
2025-02-04 13:06:40 +01:00
Arnold Loubriat
358e42a8d5 Add the accessible-action-expand action 2025-02-03 20:32:45 +01:00
Tobias Hunger
3d7c447b97 interpreter: Rename highlight feature
... to `internal-highlight`.
2025-02-03 17:38:59 +01:00
Olivier Goffart
481b29880b Fix clippy warning
```
warning: passing a unit value to a function
   --> internal/interpreter/eval.rs:752:29
    |
752 | / ...                   item_rc_
753 | | ...                       .downcast::<corelib::items::ContextMenu>()
754 | | ...                       .unwrap()
755 | | ...                       .activated
756 | | ...                       .call(&(args[0].clone().try_into().unwrap(),))
757 | | ...                       .into()
    | |_________________________________^
    |
```

Activate, contrary to the other callback, doesn't return a value.
So write the Value::Void directly instead of using the fact that
`().into()` a value would produce Value::Void.

The code is more fragile as it will stop working if `activated` changed
return type and it no longer look consistant with the other call, but
let's make clippy happy anyway
2025-01-30 19:06:35 +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
e75415554a Create a menus module in i-slint-corelib 2025-01-30 10:08:22 +01:00
Olivier Goffart
ed179cd5b1
Refactoring: get rid in the callable in the Expression tree
Have a special node for them in FunctionCall
2025-01-24 20:26:35 +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
Olivier Goffart
7e37f19e2c ListView: fix continuous redraw with fluent style
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.
2025-01-21 14:31:55 +01:00
Olivier Goffart
90f5621985 Fix string formatting of big integer
Don't lower the precision to f32 for big enough numbers
2025-01-20 15:55:44 +01:00
Olivier Goffart
f72e8a1c01 C++/Interpreter: Be consistant with rust in the order in which we create the window
Same as previous commit for Rust
2025-01-16 19:11:31 +01:00
Simon Hausmann
8e6d2c80e5 Use unicode-segmentation from the Cargo workspace 2025-01-14 19:31:34 +01:00
Tasuku Suzuki
68b9dfc247 String: Add .is-empty and .character-count properties
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.
2025-01-14 19:29:05 +01:00
Olivier Goffart
8a5df27469
Update to Image 0.25 (#7365)
Added image-default-formats with all the format supported by image by
default, and enable that feature by default.
Also put that feature in compat-1-2 for compatibility with user that
have used image 0.24 with enabled features.
Make a new compat-1-10 feature that does not enable default format by
default

ChangeLog: upgraded image crate to 0.25, added a new cargo feature
to enable all image formats. (that feature is enabled by default with
compat-1-2, added compat-1-10 to disable it

Fixes https://github.com/slint-ui/slint/issues/7251
2025-01-14 16:31:05 +01:00
Olivier Goffart
87d86ae7d2 Only re-create elements if the model actually changed
Being dirty is not enough

Fixes #7245

ChangeLog: Elements of a `for` now only get re-created if the model is
changed, not if it is only dirty
2025-01-13 12:11:21 +01:00
Tasuku Suzuki
346d1c2df3 Fix typos
Ran `typos .` and fixed all typos that do make sense.
https://crates.io/crates/typos
2025-01-13 08:35:20 +01:00
Simon Hausmann
9504a4f090 Fix popupwindow.close() not working for the interpreter when called from other component
The instance passed to close_popup() was not the same as the one passed
to show_popup(), when called from another component. Fix this by
determining the instance in BuiltinFunction::ClosePopupWindow the same
way as in BuiltinFunction::ShowPopupWindow.

This issue was covered by popup_window_close.slint's JS test, but it was
commented out because we used to run the Node.js tests on Linux with Qt,
for which the popup testing doesn't work the same way in terms of
synthetic event delivery.

We decided to change that, also in light of the nodejs binaries we
upload to the NPM registry also being built without Qt support anyway.

This permits running additional popup window tests, providing test
coverage for the interpreter, some of which needed light syntax fixes.

Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>

Fixes #7318
2025-01-10 18:27:14 +01:00
Olivier Goffart
6b4c822a4a MenuBar: C++/Rust native menubar implementation
introduce a SetupMenuBar builtin function to ease C++/Rust lowering
2025-01-08 21:16:17 +01:00
Olivier Goffart
846664ad45 WIP: native menubar using muda
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
2025-01-08 14:05:35 +01:00
Olivier Goffart
a942ed0852 Remove thiserror dependency
Uses derive_more instead
2025-01-06 17:25:08 +01:00
Simon Hausmann
0d36f88152 Revamp BackendSelector API
Based on API review, PlatformBuilder becomes BackendSelector with
a slightly smaller API surface but more options, such as selecting
Metal or Vulkan rendering.
2024-12-16 13:06:05 +01:00
Olivier Goffart
e03e812984 Fix Focus in PopupWindow
Fix https://github.com/slint-ui/slint/issues/2911
2024-12-09 15:58:16 +01:00
Olivier Goffart
2564adcf32 interpreter: Test for Value conversion to Model 2024-12-07 11:07:27 +01:00
Olivier Goffart
118b021dfe interpreter: Fix cross referencing global
Fix test for #6984

Since global can cross-reference eachother, the Global storage need to
be a Rc of all global, and not a clone of the HashMap.
We need to hold it in a RefCell as new global are added during
initialization.
But then we can't take reference to the Rc<Global> anymore, so we need
to take a clone of it, meaning that the InstanceRef cannot be Copy.
2024-12-03 15:52:48 +01:00
Olivier Goffart
5bd20def0e Experimental support for MenuBar
Introduces `MenuBar{ ... }` that can be put in a Window
2024-11-20 09:25:37 +01:00
Olivier Goffart
20443ec0df interpreter: add TryInto/From conversion between Value and model
We'll need that to have property of type model in native items
2024-11-20 09:25:37 +01:00
Tobias Hunger
c514286122 interpreter: Add test for element_node_at_source_position 2024-11-19 10:13:22 +01:00
Milian Wolff
f6da161dbb
Reduce SmolStr <-> &str conversions and copies (#6688)
SmolStr has an Arc internally for large strings. This allows
cheap copies of large strings, but we lose that ability
when we convert the SmolStr to a &str and then reconstruct a
SmolStr from that slice.

I was hoping for some larger gains here, considering the impact
of this code change, but it only removes ~50k allocations,
while the impact on the runtime is not noticeable at all.

Still, I believe this is the right thing to do.

Before:
```
        allocations:            2338981

  Time (mean ± σ):     988.3 ms ±  17.9 ms    [User: 690.2 ms, System: 206.4 ms]
  Range (min … max):   956.4 ms … 1016.3 ms    10 runs
```

After:
```
        allocations:            2287723

  Time (mean ± σ):     989.8 ms ±  23.2 ms    [User: 699.2 ms, System: 197.6 ms]
  Range (min … max):   945.3 ms … 1021.4 ms    10 runs
```
2024-11-19 10:07:16 +01:00
Simon Hausmann
179f657a50
Show the exact feature condition around feature-gated types/functions… (#6820) 2024-11-18 13:21:58 +01:00
Tobias Hunger
fc01c549d3 interpreter: Find more elements in source code
Elements of the form `component Foo { ... }` contain
no `QualifiedName`, so they were ignored. Use the 
`{` as the seelction range for those elements.
2024-11-08 10:32:10 +01:00
Brandon Fowler
6da0f55b05
Associate PopupWindows with an ID for their active popup (#6693)
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
2024-11-04 09:17:55 +01:00
Olivier Goffart
6bb0e6038f
Merge the Callback and Function type
There is no need for two of these
This simplify some code

Amend efdecf0a13
2024-10-28 14:36:30 +01:00
Milian Wolff
0abfb056a1 Also use Rc for langtype::Type::Array
This is rarely used, but using Rc here like elsewhere allows us to
elide a few unneccessary memory allocations when copying such types.
The speed impact is not measurable though. With heaptrack I see that
we get rid of the last ~7600 allocations in my benchmark when cloning
Type.
2024-10-28 09:39:54 +01:00
Milian Wolff
69c68b22b2 Also wrap langtype::Type::Struct in an Rc
This makes copying such types much cheaper and will allow us to
intern common struct types in the future too. This further
drops the sample cost for langtype.rs from ~6.6% down to 4.0%.

We are now also able to share/intern common struct types.

Before:
```
  Time (mean ± σ):      1.073 s ±  0.021 s    [User: 0.759 s, System: 0.215 s]
  Range (min … max):    1.034 s …  1.105 s    10 runs

        allocations:            3074261
```

After:
```
  Time (mean ± σ):      1.034 s ±  0.026 s    [User: 0.733 s, System: 0.201 s]
  Range (min … max):    1.000 s …  1.078 s    10 runs

        allocations:            2917476
```
2024-10-28 09:39:54 +01:00
Milian Wolff
efdecf0a13 Wrap langtype::Type::{Callback,Function} data in an Rc
This allows us to cheaply copy the langtype::Type values which
contain such a type. The runtime impact is small and barely noticable
but a sampling profiler shows a clear reduction in samples pointing
at langtype.rs, roughly reducing that from ~8.6% inclusive cost
down to 6.6% inclusive cost.

Furthermore, this allows us to share/intern common types.

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):      1.089 s ±  0.026 s    [User: 0.771 s, System: 0.216 s]
  Range (min … max):    1.046 s …  1.130 s    10 runs

        allocations:            3152149
```

After:
```
  Time (mean ± σ):      1.073 s ±  0.021 s    [User: 0.759 s, System: 0.215 s]
  Range (min … max):    1.034 s …  1.105 s    10 runs

        allocations:            3074261
```
2024-10-28 09:39:54 +01:00
FloVanGH
14c7910d49
PopupWindow: added close-policy property (#6614)
* Update api/cpp/include/slint_window.h

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update docs/reference/src/language/builtins/elements.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update internal/core/window.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/interpreter/eval.rs

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update internal/backends/qt/qt_window.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/interpreter/dynamic_item_tree.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/compiler/passes/materialize_fake_properties.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-10-24 09:27:39 +00:00
Milian Wolff
998de63e17
Only clone the public properties for the exported component (#6633)
Copying potentially thousands of properties for no reason is something
that can be easily optimized away to save a bit of time:

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):      1.108 s ±  0.015 s    [User: 0.792 s, System: 0.231 s]
  Range (min … max):    1.085 s …  1.133 s    10 runs
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):      1.082 s ±  0.019 s    [User: 0.773 s, System: 0.214 s]
  Range (min … max):    1.054 s …  1.117 s    10 runs
```
2024-10-23 17:05:19 +02:00
Milian Wolff
e3741a87f6
Only build the RTTI hashmap once per thread (#6617)
This removes a lot of temporary allocations, note e.g. how this
was called once per component previously yet the data contained
in the map was always the same!

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     636.2 ms ±  20.0 ms    [User: 563.4 ms, System: 71.8 ms]
  Range (min … max):   615.2 ms … 657.9 ms    10 runs

        allocations:            3371939
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     600.6 ms ±   2.9 ms    [User: 522.0 ms, System: 74.4 ms]
  Range (min … max):   596.3 ms … 605.2 ms    10 runs

        allocations:            2917930
```
2024-10-22 18:01:33 +02:00
Olivier Goffart
ff53791ce7 Support for changed callback in global
Fixes #6599

ChangeLog: Support property changed callbacks in globals
2024-10-22 09:26:48 +02:00
Olivier Goffart
617dc19f8e Interpreter: on wasm, check the user agent to resolve the native style
This impact everything that use the interpreter with wasm:
 - docs preview
 - slintpad
 - vscode wasm preview
2024-10-17 18:05:38 +02:00
Milian Wolff
0f6c3a4fd7 Use SmolStr in more places of the compiler infrastructure
This removes a lot of allocations and speeds up the compiler step
a bit. Sadly, this patch is very invasive as it touches a lot of
files. That said, each individual hunk is pretty trivial.

For a non-trivial real-world example, the impact is significant,
we get rid of ~29% of all allocations and improve the runtime by
about 4.8% (measured until the viewer loop would start).

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     664.2 ms ±   6.7 ms    [User: 589.2 ms, System: 74.0 ms]
  Range (min … max):   659.0 ms … 682.4 ms    10 runs

        allocations:            4886888
        temporary allocations:  857508
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     639.5 ms ±  17.8 ms    [User: 556.9 ms, System: 76.2 ms]
  Range (min … max):   621.4 ms … 666.5 ms    10 runs

        allocations:            3544318
        temporary allocations:  495685
```
2024-10-17 18:04:58 +02:00
Olivier Goffart
9734bfdd8e
SwipeGestureRecognizer: fix cancel() function
It was implemented in the compiler, but not in the runtime
2024-10-09 18:06:32 +02:00
Simon Hausmann
0b028bfb6f
Add support for a font-metrics property to Text/TextInput. (#6452)
The struct held provides access to the design metrics of the font scaled
to the font pixel size used by the element.

ChangeLog: Slint Language: Added font-metrics property to `Text` and `TextInput`.

Closes #6047
2024-10-05 17:00:46 +02:00
Olivier Goffart
b41b389e55
interpreter: Fix wrong parent item tree of the PopupWindow (#6448)
When calling `popup.show()` the parent itemtree of the popup should be
the one from the parent in which the PopupWindow is declared in the
source, and not the one of the context in which the `popup.show()` code
appears.

Part of issue #6426.
This happens to fix the issue as presented there.

But there is another issue in which we still crash when trying to access
global from a popup who's parent has been deleted because the interpreter 
needs access to the root item tree to access the globals
2024-10-04 18:49:17 +02:00
Simon Hausmann
cd2b738c7a Rename SwipeGestureRecognizer to SwipeGestureHandler
The origin of this proposal is the name of the `swipe-left`, etc.
directional, boolean properties. They're missing another verb in their
name. In principle the right choice would be "recognize". That is what
the type name suggests, that's the term the documentation uses, so the
code should read `recognize-swipe-left: true;`. However that is a long
word. "Handle" is a verb that's simpler. It's also more generic (that's
a downside), but it's otherwise short enough to make things look
"right":

```
SwipeGestureHandler {
    handle-swipe-left: true;
    swiped => { something.naviate-left(); }
}
```

Therefore this patch proposes to rename the type to SwipeGestureHandler
and prefixes the boolean directional properties with "handle".
2024-09-18 16:37:27 +02:00
Olivier Goffart
d2bd5366f4 Timer::set_interval
Don't return an Option, just return 0 when the timer is not started.
As discussed in the API review, the rational is that the interval is
just like a field in a struct and when the struct is default
constructed, it is initialized to 0
2024-09-18 09:24:39 +02:00
Olivier Goffart
02467bd4cc
Change mod() to always return positive number (#6179)
* Change `mod()` to always return positive number

Closes #6178

ChangeLog: The mod function was changed to always return a positive value (#6178)
2024-09-17 11:37:32 +02:00