Commit graph

56 commits

Author SHA1 Message Date
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
Yuri Astrakhan
05f4fc0cde Auto-fixed clippy::needless_return
`__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_return

```
__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_return

cargo fmt --all
```
2025-02-07 09:46:49 +01:00
Yuri Astrakhan
9621cae218 Auto-fixed clippy::needless_lifetimes
`__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_lifetimes

```
__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_lifetimes

cargo fmt --all
```
2025-02-07 09:20:49 +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
c0fe0be643 Add the MenuItem Element type to be added to MenuBar and ContextMenu 2025-01-23 22:02:08 +01:00
Olivier Goffart
8cf6f97962 Refactoring: Use BuiltinElement in additional_accepted_child_types
Simplifies code a bit
2025-01-23 22:02:08 +01:00
Olivier Goffart
d8d0bb2115 Rework lookup of sub-elements with regard to special accepted elements
Consider
```slint
// Some code in the wild actually have made their own menubar before
component MenuBar { /* ... */ }

component Row { /* ... */ }

export component Main inherits Window {
  // This should find the declared component and not the builtin component
  MenuBar { }

  GridLayout {
     Row {}
  }
}
```

Previously, `MenuBar` and `Row` were first resolved against
`additional_accepted_child_types` and so it would always find the
builtin one.
But this patch changes that to find the builtin one only if it hasn't
been replaced by another component with the name name.
(So we'd use the cusom MenuBar and the custom Row)

Another change is that we also lookup the
additional_accepted_child_types if they are in a @children.

```slint
component MyGrid {
   GridLayout { @children }
}
export component Main {
   MyGrid {
      // This used to be an error but is now accepted
      Row { }
   }
}
```
2025-01-23 14:28:11 +01:00
Olivier Goffart
5cf9c6806e LSP: don't auto-compete private properties 2025-01-14 11:26:57 +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
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
e854e11399 Error when making a for over an empty array
Instead of panicking.

Attempt to fix it in #6765 didn't work for C++.
Code generation might be hard for C++, so I thought it's better to error out.

Fix #6760
2024-11-11 13:23:56 +01:00
Olivier Goffart
51e4d4562a Do not print the internal struct name in LSP tooltip or error message
just strip the `slint::` or `slint::private_api::`
This is not a 100% match to the slint name (eg, LogicalPosition) but
it is better anyway
2024-11-04 17:09:57 +01:00
Olivier Goffart
b44172be4f Janitor: Remove BuiltinElement::reserved_properties
It was added when support for `font-metrics` was added, but there is no
reason why this can't simply be in the `properties` hash.
2024-11-04 17:09:57 +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
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
Olivier Goffart
1d3e9120d8 Avid reporting further error when an element is misspelled
eg, don't report an error for each callback or animation or changed
event that the the property doesn't exist or such.

Also reword the message when an element doesn't exist. Use "element"
rather than "type" as it is more accurate.
2024-08-29 13:10:35 +02:00
Olivier Goffart
85063dc4dc Fix rust generated code with struct of percent value
We wouldn't detect percent as a unit product in
43c7f57b0f/internal/compiler/generator/rust.rs (L2418-L2422)

Percent is not strictly of percent unit because that unit doesn't
combine with other unit (as per the comment in `default_unit`)
But since it converts to number, it is then an unitless value. (scalar)

Fixes #5887
2024-08-21 14:48:22 +02:00
Olivier Goffart
a9f526491a Timer Element
Closes #5724
2024-08-16 16:36:38 +02:00
Simon Hausmann
4eef2d4936 WIP: Add find_by_element_type_name 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
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
Aurindam Jana
0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00
Tobias Hunger
2e035fd0d1 compiler: Document function added in d0fc025bc8
... and remove code needlessly added in that commit,
too.
2024-03-06 14:25:21 +01:00
Tobias Hunger
d0fc025bc8 live preview: Do not drop on elements that can not have children
Slpit up `lookup_type_for_child_elemnt` (in the compiler) into the
part that looks at the element itself only (called `accepts_child_element`)
and the part that looks at the child.

When deciding whether we can drop something into another element in
the live preview, we know the child type is going to be OK, even when
the `TypeRegister` does not contain it yet (as it is not imported yet).
2024-03-06 12:15:10 +01:00
Tobias Hunger
b12575a4c4 janitor: Go over our spell checking setup
* Extend the cspell word list
* Remove those extensions from individual source files
* white-list licenses and such as we should not meddle with those
* Fix spelling
2023-10-16 09:01:51 +02:00
Olivier Goffart
8f001ac490 Add support for protected functions
Protected function can only be called from the direct base

Issue #3636
2023-10-11 10:50:50 +02:00
Tobias Hunger
2840886d28 Add component-factory type to Slint language
Add a type "component-factory" to the Slint language.
2023-07-27 12:04:16 +02:00
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +02:00
Olivier Goffart
f0a1ef7194 Fix getting type of more complex expressions in model
Fixes #2977

The problem is that expressions such as "foo * foo" can be optimized by
optimization pass to only query the property once, and this is
transformed in a Expression::CodeBlock and is no longer a
Expression::Cast(Model)
So we need to introspect the expression more.
2023-06-27 10:06:20 +02:00
Olivier Goffart
11dea135f7 Domain: slint-ui.com -> slint.dev 2023-06-16 10:55:08 +02:00
Aurindam Jana
039e54a5de
Add royalty free license to files except examples and docs (#2888) 2023-06-15 11:20:50 +02:00
Olivier Goffart
18ba3c2ae2 Slint enums in Rust and C++ 2023-06-12 13:02:14 +02:00
Amirhossein Akhlaghpour
3a4f3c61d5
Add @rust-attr on scturct (#2785)
Fixes: #2660
2023-06-05 16:29:55 +02:00
Olivier Goffart
1cbd61145e WIP: pure qualifier for callback and functions 2022-12-22 00:26:27 -08:00
Olivier Goffart
8a09043e63 Properly remember the location of builtin member function call
So we can report an error if they are called in a pure context
2022-12-22 00:26:27 -08:00
Simon Hausmann
7122d22c88 janitor: use the new default attribute for enums 2022-12-05 10:20:39 +01:00
Simon Hausmann
d8a1f2cf01 Introduce a rem unit in the type system
This allows specifying font sizes relative to the Window's
default-font-size, similar to CSS rem.
2022-11-24 11:33:38 +01:00
Olivier Goffart
731fd45bf0 syntax_updater: Add binding for x and y for elements that would end up centered
In the new language, we plan to center the element within their parent,
so for compatibility, add explicit x and y binding putting them back in
the corner
2022-11-15 17:33:27 +01:00
Olivier Goffart
6ab6ae63d4 input output property: fix semantic with two ways bindings 2022-11-11 13:02:53 +01:00
Olivier Goffart
2ceafc6392 New syntax: Make it an error to set the value of a builtin output property
With the old syntax, this becomes a warning
2022-11-01 12:51:45 +01:00
Olivier Goffart
8dbe745fc4 Builtin elements: use the input output syntax 2022-11-01 12:51:45 +01:00
Olivier Goffart
84ae4d2928 New syntax: Only allow children if the component has @children
For compatibility reason, this is also allowed when inheriting
2022-10-28 17:45:37 +02:00
Olivier Goffart
28ae8f7bc4 Refactoring: split ElementType away from the types used as property type
These are two different concept, and it is confusing to keep them in the
same enum

We want to support component without any base element, and Void is
already used for global component, so do this refactoring before
2022-10-26 14:50:44 +02:00
Olivier Goffart
f5314625d9 lsp: Group and sort properties in the property extension call
Group property from the base class they are defined, and for built in
property, group them by category.
Also filter callback and other reserved properties that are not valid
for some elements.
2022-10-21 12:50:42 +02:00