Commit graph

112 commits

Author SHA1 Message Date
Simon Hausmann
f983cf0b19 Add Platform.os as well as a rudimentary test 2025-05-06 13:06:27 +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
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
9942afd183 SQUASH: Rework the element id to be a hash based on filename
and position iof the LBrace token.
2025-04-09 13:52:29 +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
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
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
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
Alex Badics
d173fa0ba9 compiler: Fix function constness marking 2025-02-21 11:16:00 +01:00
Alex Badics
65bcca1082 compiler: inline functions if possible 2025-02-21 11:16:00 +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
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
bcb2953f00 Auto-fixed clippy::unnecessary_map_or
This is a hacky approach, but does help a lot with the tedious fixes.

See https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_map_or

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

cargo fmt --all
```
2025-02-07 09:02:31 +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
7fba31a7b0
Refactor: use Struct instead of Type for the type in a Expression::Struct 2025-02-03 10:19:30 +01:00
Olivier Goffart
010126992e MenuItem with for and if 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
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
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
crai0
e4b70efe6e
compiler: Warn user when immediately converting gradient macro to color (#6956)
Fixes #6819
2024-12-02 13:05:38 +01:00
Olivier Goffart
f225f79d49 compiler: Put the argument names in the Type
That simplifies things a bit and will allow to have names for builtin callback and functions
2024-11-21 09:53:17 +01:00
Aurindam Jana
0898a5f641
Tweak Docs (#6834)
---------

Co-authored-by: Nigel Breslaw <nigel.breslaw@slint.dev>
2024-11-20 14:27:37 +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
e3ea25f48c LSP: Signature Help 2024-11-06 13:27:29 +01:00
Olivier Goffart
3552e004e1 Fix wrong value or panic in the interpreter when converting struct of struct
The "tmpobj" variable was overwriten because the interpreter (contrary
to rust and C++) don't have scopes for the local variables, and local
variable of the same name would conflict.
(I think this could in theory be a problem in C++ and rust although i
haven't reproduced it)

Other uses of StoreLocalVariable also make the number unique with a
counter

Fixes #6721
2024-11-05 14:06:09 +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
79e1592b9f Intern some more common types
This is just for completeness, we "only" save ~13k allocations
with no measurable speed impact:

Before:
```
  Time (mean ± σ):      1.019 s ±  0.033 s    [User: 0.716 s, System: 0.203 s]
  Range (min … max):    0.957 s …  1.061 s    10 runs

        allocations:            2679001

```

After:
```
  Time (mean ± σ):      1.015 s ±  0.015 s    [User: 0.715 s, System: 0.201 s]
  Range (min … max):    0.997 s …  1.038 s    10 runs

        allocations:            2666889
```
2024-10-28 09:39:54 +01:00
Milian Wolff
df1dd3b6cf Use one central thread_local for builtin function types
Instead of occupying multiple TLS slots, introduce a single type
that stores all the builtin function types in members. Use a macro
to define this struct then, which allows us to use a nice DSL to
define these function types, reducing the boiler plate significantly.

The downside is that we no longer have the ability to easily share
semantically equivalent function types (e.g. for `Round`, `Ceil`
and `Floor` etc.). Doing so would require us to introdue a separate
name for these types, and then use external matching to map the
BuiltinFunctions to the reduced list of types. The performance impact
is minimal though, so this is not done to KISS.
2024-10-28 09:39:54 +01:00
Milian Wolff
6e9e66ea7d Refactor typeregister's BUILTIN_ENUMS => BUILTIN.enums
This will allow us to add more buildin types to this thread local
in follow-up patches, to reduce the number of thread local slots.
2024-10-28 09:39:54 +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
fd0eb01c55 Share common definitions for builtin function types
This way we can reuse a single reference counted type where possible.
2024-10-28 09:39:54 +01:00
Milian Wolff
0fc9f3574a Only allocate the BuiltinFunction::ty() return types once
These are known statically, so let's store them once in thread local
statics and return them from there.

Before:
```
  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
```

After:
```
  Time (mean ± σ):     996.9 ms ±  17.7 ms    [User: 708.9 ms, System: 202.9 ms]
  Range (min … max):   977.8 ms … 1033.1 ms    10 runs

        allocations:            2686677
```
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
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
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
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
a9f526491a Timer Element
Closes #5724
2024-08-16 16:36:38 +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
445802c46d date_time: simplification and cleanups 2024-06-06 09:03:50 +02:00
Olivier Goffart
3da0ee5bb9 DatePicker: Logic in C++
Had to simplify a bit the rust logic to make it work
2024-06-06 09:03:50 +02:00
Florian Blasius
973ecac989 DatePicker: finished features 2024-06-06 09:03:50 +02:00
Florian Blasius
3ccee816be
Added TimePicker widget (#5251) 2024-06-05 15:23:06 +02:00
Olivier Goffart
94af4d2832 Don't optimize array
They are model and if the model is copied, the changes in model need to
apply to all copies.

Fixes #5249
2024-06-04 15:24:36 +02:00
Aurindam Jana
3523e86359
Simplify commercial license (#3063)
Base the commercial license on the Royalty-free license adding clauses pertaining to the fees.
2024-05-31 14:06:17 +02:00
Aurindam Jana
9a3aa265d5
Update Royalty-free license (#5257)
Add clarification that Application may not expose Slint APIs.
2024-05-31 10:53:19 +02:00
Olivier Goffart
0929e3dfc1 Slint: make the abs work with unit types 2024-05-08 19:04:22 +02:00
Tobias Hunger
2e3b00e38e janitor: Fix some clippy warnings pre-release
Nothing that should be controversial, but the
`internal/compiler/builtin_macros.rs` could point to a thinko in the original
commit.
2024-05-06 16:47:14 +02:00
Simon Hausmann
31767eb6ab Add a clear-focus()function on all elements that have a focus() function
This is the counter-part, which removes focus from the element if it's currently focused. The window - if focused - may still be focused towards the windowing system.
2024-04-26 11:09:11 +02:00