Commit graph

362 commits

Author SHA1 Message Date
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
387e4202ea Rust: one more fix for computations on big numbers 2025-01-20 16:47:49 +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
de80bb0a2c Rust: Fix comparison of big integers
Don't convert integer to f32 in the rust generated code
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
Olivier Goffart
9d1be5209c Don't panic in the generated rust ComponentHandle::window()
It can panic if lazily constructing the window adapter.
Make sure it is actially not lasily constructed, we don't need lazy constructor when not embedding anyway.
2025-01-16 19:11:31 +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
cfbcf0b1d7
Introduce Window::try_dispatch_event (#7313)
That is the same as Window::dispatch_event, but it reports an error
instead of panicking
2025-01-09 19:39:38 +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
e03e812984 Fix Focus in PopupWindow
Fix https://github.com/slint-ui/slint/issues/2911
2024-12-09 15:58:16 +01:00
Olivier Goffart
a7f0fdcd93 C++: explicitly cast to float when generating gradiant stop
To avoid the error `error: narrowing conversion of`
2024-12-06 23:04:12 +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
73b549a42c bundled translation: Better error reporting
forward the error up the stack instead of panicking while producing the llr
2024-11-19 21:34:42 +01:00
Olivier Goffart
d68b84a3f1
Change API to set the language with bundle translation
* Change API to set the language with bundle translation

Part of #6793
2024-11-17 11:40:02 +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
95f5685789
Bundle translations (#6661)
This currently doesn't have public API to enable it yet.

TODO:
 - Error handling in the compiler
 - Public API in the compiler configuration
 - Documentation
2024-10-29 15:07:15 +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
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
Olivier Goffart
d8ab4e4600 Signed DistanceField font rendering in swrenderer
Note that this is still disabled in the compiler with no way to enable
it with public API
2024-10-23 09:12:30 +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
Tobias Hunger
7f8da7bf28 compiler: Do not fail the embed_images pass with URLs
Slintpad uses URLs to images. Do not fail when we "embed"
those so that we find the list of resources on the Documents
later.

This fixes image loading in slintpad again.
2024-10-21 15:00:55 +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
Simon Hausmann
9eef4c9a96 Use approx_eq() also for comparing float point numbers in the Rust generated code
The parent commit does that for C++, and the interpreter's `PartialEq` impl for `Value` uses `approx_eq`, too.
2024-10-15 13:49:40 +02:00
Simon Hausmann
a4a5eb6f0f Simplify unit/float detection
Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
2024-10-15 13:49:40 +02:00
Simon Hausmann
bb4c77ce04 C++: Fix compilation of floating point equality comparison
Newer clang may produce warnings like this when using == with floating point numbers:

```
error: floating-point comparison is always false; constant cannot be represented exactly in type 'float' [-Werror,-Wliteral-range]
```

Use the C++ equivalent of approx_eq to avoid the warning and provide more reliable comparison.
2024-10-15 13:49:40 +02:00
Qubi0-0
f6184ef858
Fix Generated C++ code issue with keywords (#6441)
Fixes #5613

ChangeLog: C++: generated code adds `_` to the end of identifier that would otherwise be keywords
2024-10-08 15:03:03 +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
04e03ed197
Rust generator: don't run the init code twice for popups (#6447)
Don't run the `init=>` callback in popup twice

ChangeLog: rust: Fixed `init=>` callback on PopupWindow ran twice.
2024-10-04 17:17:36 +02:00
Olivier Goffart
8ac0c792e8 Update derive_more 2024-09-26 09:14:58 +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
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
5f77808d1c Optimization: improve expression inlining
If a property is only used once, we can inline it with a bigger
threshold.
But this require to first compute the use, and then do the inlining
while adjusting the usages
2024-08-23 17:17:15 +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
Olivier Goffart
e0ca9dfd76 Fixes rust generated code when taking expression of void callback
code like so:
```slint
callback foo();
if true : Button {
   clicked => {
      true ? foo() : foo();
   }
}
```

the code like foo() use the `option.map()`  to get to the parent, but then it
needs to still be wrapped in a `{...}` to convert that to a `()` expression

Fixes #5883
2024-08-21 11:52:15 +02:00
Simon Hausmann
9bdade0105 Compile the multiple-includes test with a header-only build of appwindow.slint 2024-08-20 15:53:24 +02:00
Simon Hausmann
8146799e8a Fix build with type aliases and generated .cpp files
These need to remain in the header file
2024-08-20 15:53:24 +02:00
Simon Hausmann
4b2d572732 C++ code generator: Fix header-only build when included multiple times
Make sure to mark whatever variables and functions that are left in the header as inline,
even if we don't generate C++ files.
2024-08-20 15:53:24 +02:00
Simon Hausmann
fddb6e30e3 C++: Place embedded resources into generated .cpp files 2024-08-20 15:53:24 +02:00
Simon Hausmann
c25a03d6f7 C++: Make it possible to split up the C++ code generated for a .slint file
Add a COMPILATION_UNITS argument to slint_target_sources that defines into how many .cpp files to split up a .slint file. The new default is now one.
2024-08-20 15:53:24 +02:00
Olivier Goffart
a9f526491a Timer Element
Closes #5724
2024-08-16 16:36:38 +02:00
Simon Hausmann
fb6775b386 When the slint scale factor is provided at compile time, propagate it also as initial value to the slint::Window created 2024-08-14 11:00:50 +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
819e549278 Rust generated code: handle the case if the parent is destroyed in a binding
This can happen if somehow the parent get destroyed while a binding is
running. This is issue #3464

This is enough to fix #5698
2024-08-09 15:05:15 +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
W Etheredge
80ae11cd80 Use associated constants on number types 2024-08-01 07:53:48 +02:00
Simon Hausmann
8a7db55bb6
Route debug() calls in Slint consistently through Platform's debug_log() (#5718) 2024-07-29 16:31:09 +02:00