Commit graph

239 commits

Author SHA1 Message Date
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
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
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
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
Simon Hausmann
8a7db55bb6
Route debug() calls in Slint consistently through Platform's debug_log() (#5718) 2024-07-29 16:31:09 +02:00
Simon Hausmann
9a34789070 Revert "Fix conversion to from float to int"
This reverts commit f5d003d1e2.

We decided to postpone this change until a later release, in maybe a
different shape.
2024-07-25 15:25:00 +02:00
Olivier Goffart
f5d003d1e2 Fix conversion to from float to int
Round the value.

The previous behavior is that

 - For the interpreter, we were rounding (same as new behavior)
 - for Rust and C++ we were truncating, unless the properties were
   inlinined and then we were keeping it as float
2024-07-23 17:32:57 +02:00
Olivier Goffart
e67e46ab47 LLR: merge the popup's x and y property access in one expression 2024-07-10 17:54:03 +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
14593a55e1 llr: Don't generate unused globals
Global for which none of the properties are used can be omitted in the
generated code.
2024-07-04 10:24:54 +02:00
Simon Hausmann
0f158e10dd testing api: Avoid bogus warnings about missing debug info
A `Rectangle { clip: true; }` will generate an intermediate `Clip` rectangle, which
certainly has no debug info.

The check whether debug info is present or not should not be done on a per-element
level but it can be done on the level of the compilation unit.
2024-07-03 18:01:24 +02:00
Olivier Goffart
59942df91f Add some tests and fixes for change handler
Make sure that when inlining, the callback in the sub component
is executed before the root

Fix a warning in the generated C++ code
2024-06-28 10:45:45 +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
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
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
Olivier Goffart
d0ed0438ce
LLR: peliminary support for multiple public components
There currently still can only be one because the passes expect that,
but now the LLR and generator should be ready to accept multiple public
component later
2024-06-15 14:44:11 +02:00
Olivier Goffart
d0cdebfee6 C++: move globals in a different struct
So that subcomponent don't depend on the root component name
which will hallow to have several root components
2024-06-14 16:26:53 +02:00
Olivier Goffart
4cc6337c42 Rust: Don't get the default font size through the root component
Planning for multi-component support
2024-06-13 13:53:07 +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
Simon Hausmann
15b517a554 Emit a warning to stderr (debug_log) when using the ElementHandle API but there's no debug info present 2024-06-05 01:29:58 -07:00
Simon Hausmann
1a8ce3c659 Add support for optimized rectangles in ElementHandle
Keep merging elements, but remember the boundaries in the debug info, separated by a slash.

Also fixed tests that rely on accessible-label being set only once. For example

```
Button { text: "foo"; }
```

will certainly have "foo" as accessible-label on `Button`, but its internal `Text` element has
an implicit "accessible-label" set to the same
value.

So don't rely on that for now but search by id instead.
2024-06-05 01:29:58 -07:00
Simon Hausmann
4eef2d4936 WIP: Add find_by_element_type_name 2024-06-05 01:29:58 -07:00
Simon Hausmann
a52fe6bbfc Make element debug information configurable
The `SLINT_EMIT_DEBUG_INFO` environment variable needs to be set for Rust and C++ builds. For the interpreter it's always enabled, since ... we have it.
2024-06-05 01:29:58 -07:00
Olivier Goffart
43a336b534 C++ part of element_ids
Simplify a bit the llr generation so that there is less code duplication
between Rust and C++
2024-06-05 01:29:58 -07: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