Commit graph

513 commits

Author SHA1 Message Date
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
Olivier Goffart
5663ddd9cc
SwipeGestureRecognizer (#6005) 2024-09-09 14:40:55 +02:00
Nigel Breslaw
482308f5da
Add Math.atan2 to the inbuilt math function
Math.atan2(y, x) -> angle
2024-08-30 09:55:10 +02:00
Olivier Goffart
4de03fba5b Use f32 for float-to-string conversion
Because f64 has too much precision, so limit to f32 so that we don't
have extra precision we don't need and would be wrong as all our float
as in f32

(Also avoid double allocation in rust generated code)
2024-08-23 16:09:53 +02:00
Tobias Hunger
45c24803f2 compiler: Remove version info from SourceFile again
... and fix the fallout of that change.
2024-08-21 16:55:13 +02:00
Olivier Goffart
43c7f57b0f spawn_local: initialize the platform if not initialized before the call
Take the opportunity to refactor a bit the way the global platform or
context is accessed

Fixes: #5871
2024-08-21 13:26:04 +02:00
Olivier Goffart
a9f526491a Timer Element
Closes #5724
2024-08-16 16:36:38 +02:00
Tobias Hunger
4a3a86a0b0 interpreter: Remove internal API from deprecated ComponentCompiler
It is not used anymore and internal, so let's remove it.
2024-08-14 10:49:37 +02:00
Simon Hausmann
636de6fc7c Python: Fix support for named exports 2024-08-13 12:04:04 +02:00
Simon Hausmann
2d5d53fba8 Fix comment about "internal"-ness of internal feature gated interpreter function
Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
2024-08-13 12:04:04 +02:00
Simon Hausmann
28f9d3cc71 Remove unnecessary helper function 2024-08-13 12:04:04 +02:00
Simon Hausmann
5e39e211c2 Fix build without internal feature 2024-08-13 12:04:04 +02:00
Simon Hausmann
1e3f05c983 Python: Expose Slint structs
Structs declared and exported in Slint are now available in the module namespace
with a constructor.

Fixes #5708
2024-08-13 12:04:04 +02:00
Olivier Goffart
51481b101c
Make conversion from float to int property truncate
- Make sure that in Rust and C++ we also truncate if the properties are
inlined
 - Change the interpreter to truncate

This is a redo of commit f5d003d but truncate instead of round

fixes #5689
2024-08-10 14:51:05 +02:00
Olivier Goffart
4622025969 Use less precision when comparing vaue in slint language
In rust, use f32 instead of f64 for arithmetic comparison.
In the interpreter, use approx_eq

The test is failling in nightly because of precision change in `log`.
By using f32, it actually should work

Also Revert "Disable builds with nightly Rust temporarily"
This reverts commit 4afc3a2e84.

Fixes #5722
2024-08-08 14:30:25 +02:00
Matheus Castello
d1f5b536c0 internal: interpreter: fix typo in ComponentCompiler deprecation message
Signed-off-by: Matheus Castello <matheus@castello.eng.br>
2024-07-23 07:04:19 +02:00
Simon Hausmann
b12b05ee10 doc: Fix intro that claimed that Compiler provided ComponentDefinition
There's a CompilationResult inbetween first.
2024-07-17 11:20:27 +02:00
Simon Hausmann
c74872ab86 Fix dynamic accessibility tree updates not working in the interpreter
It turns out that for repeated elements, we set root_weak to self_weak, instead of the root we obtain from the parent instance. Fix this by moving the code to initialize parent_item_tree_offset to before we try to use it (via parent_instance) to initialize root_weak.
2024-07-11 16:25:39 +02:00
Simon Hausmann
419042f476 Add support for using own properties in PopupWindow's x and y properties
This allows positioning popup windows in a way that takes their width/height into account.
2024-07-10 13:43:41 +02:00
Olivier Goffart
5dfa8d56dc API review of the slint interpreter Compiler api
Closes #5466
2024-07-05 17:20:08 +02:00
Olivier Goffart
35a6e7bde5 Split Text item into SimpleText and ComplexText
SimpleText has all the most common properties and is half the size
2024-07-05 12:51:25 +02:00
Olivier Goffart
86b9099fdd interpreter: Mark ComponentCompiler as deprecated 2024-07-04 12:47:54 +02:00
Olivier Goffart
708ab9f7c2
viewer: use the new Compiler API and add a --component command line arg 2024-07-03 16:49:22 +02:00
Olivier Goffart
f93729ffe2 Port LSP to slint_interpreter::Compiler
Add a feature to only generate a specified component.
2024-07-03 11:51:23 +02:00
Olivier Goffart
dbf4ca6e59 Interpreter: add the Compiler struct 2024-07-01 15:00:46 +02:00
Olivier Goffart
5bd352c430 Intepreter: Create a CompilationResult types that can hold Several ComponentDefinition 2024-07-01 15:00:46 +02:00
Olivier Goffart
2dcd7107ad Interpreter: give the right type to the model property instead of Value
This way it also start initialized with a value of the proper type, and
this will "fix" #5500 by not panicking anymore.
Fixes #5500
2024-06-28 13:06:57 +02:00
Olivier Goffart
bd18d8dc0a Fix compiler crash when const propagating a property of component-factory with its default value
We couldn't represent an empty component factory in the exrpession tree,
so add Expression::EmptyComponentFactory for that
2024-06-25 20:25:01 +02:00
Olivier Goffart
42a2c6a569
Only generate code for the exported Window
Have a warning when a component is exported from the main file and
doesn't inherit Window.
Unless it's the last component, for compatibility with Slint 1.6

Also don't warn in the interpreter
2024-06-25 15:13:06 +02:00
Tobias Hunger
1d12d6b868 janitor: Fix clippy "extra unused lifetime" 2024-06-24 14:59:47 +02:00
Tobias Hunger
9a253dc571 janitor: Fix clippy "match for destructuring a single pattern" 2024-06-24 14:59:47 +02:00
Tobias Hunger
ae2a10bd6b janitor: Fix clippy "redundant closure" 2024-06-24 14:59:47 +02:00
Tobias Hunger
cd3b60c889 janitor: Fix clippy "creates a reference which is immediately dereferenced" 2024-06-24 14:59:47 +02:00
Olivier Goffart
3764312561
Generate multiple components in Rust and C++ (#5449)
When lowering to the LLR, generate one PulbicComponent for each exported
component in the main file

Closes #784
2024-06-24 10:03:19 +02:00
Olivier Goffart
408637a677 Remove the is_root_component within the component
There will be serveral roots, so this makes no sense.
2024-06-21 11:58:09 +02:00
Olivier Goffart
acb7da11d2 fix missing warning of missing export
... for last component when globals are exported
2024-06-21 11:57:49 +02:00
Olivier Goffart
a4c0cc9f09 Move the used_types from the (root) Component in the Document
Preparation for multi-components

Note that this had to rename one instance of TextStyle because it
conflicts with the struct of the same name used in the FontSettings
in the style. This wasn't a problem before because it shares some
property in common, and the the order of processing of component has
changed leading to the other one being generated.
(But that is a wider bug in the compiler outside of the scope of this
refactoring)
2024-06-20 12:03:38 +02:00
Olivier Goffart
2fd8744cfc compiler: Move embedded_file_resources from the root Component to the Document 2024-06-20 12:03:38 +02:00
Simon Hausmann
af80d7df41 Fix a warning in default Python build about unused create_window() function in EventLoopInterface
Yes, the fix for that is here, instead of cluttering #cfg's into the winit backend. This seemingly unused function is not needed by femtovg on desktop,
merely by skia (not enabled by default) and the software renderer.

In the Slint Rust crate, the software renderer is enabled by default - which is why this doesn't trigger a warning. But for the interpreter it was missing.
2024-06-18 17:48:17 +02:00
Tobias Hunger
7e908af32f janitor: interpreter: Polish the highlight feature code 2024-06-14 16:59:39 +02:00
Tobias Hunger
c55f0a9b0e compiler: Add a snapshotter to help create snapshots of compiler state
Use this snapshot to keep a unoptimized typeloader around, so that the preview
does not need to do another parsing run.

Move the document cache in the preview over to use the snapshot.
2024-06-12 10:15:29 +02:00
Simon Hausmann
97df6b1be1 Mark AccessibleRole as non-exhaustive
That way we can add new variants in the future, while still exporting this in our public API.
2024-06-11 08:02:10 -07:00
Simon Hausmann
db3d726886 Make it possible to retrieve a SharedImageBuffer for a slint::Image in Rust
This change exposes functionality of already existing internal API
that all renderers use to obtain pixels for upload to the screen - so
it's rather well tested.

This also exposes the `SharedImageBuffer` API, an enum that represents
different SharedPixelBuffer encodings.
2024-06-11 07:46:57 -07:00