Commit graph

1458 commits

Author SHA1 Message Date
Olivier Goffart
e8012c70d0
Fix MenuBar on android
The ContextMenuArea on android intercepts clicks to trigger on long clicks
and this prevent the MenuBar's TouchArea to work properly

Fixes #8353
2025-05-09 08:58:12 +02:00
Olivier Goffart
31867fad61
compiler: Reject comparison on unsupported types
The compiler was accepting the comparison of types such as color, or
struct, and then later we'd get rust compilation error or interpreter
panic.

Example seen in the crash reporter:
`internal/interpreter/eval.rs:257:35`
```
unsupported Value::Brush(SolidColor(Color { red: 0, green: 0, blue: 0, alpha: 0 })) ≤ Value::Brush(SolidColor(Color { red: 255, green: 0, blue: 0, alpha: 255 }))
```

Note that some code hapenned to compile with rust or C++.
For example, comparison of bool, or anonymous struct (represented as
tuples), or color represeted as int)
So technically this is a breaking change.
But this should be fine as this was not working in the interpreter and
this is a bug fix.

ChangeLog: Slint compilation error for comparison of types that can't be
compared with less or greater operator.
2025-05-07 11:39:27 +02:00
Olivier Goffart
9289940371 Prospective panic fix in the rust generated code
From the v1.11.0 crash reporter:
There is a panic in
`target/x86_64-unknown-linux-gnu/release/build/slint-lsp-8494405be069a534/out/main.rs:115729:64`
```
called `Result::unwrap()` on an `Err` value: Other("Could not initialize any renderer for LinuxKMS <REDACTED: user-file-path> from Skia renderer: Error opening device <REDACTED: user-file-path>: No such file or directory (os error 2)\\nError from FemtoVG renderer: Error reading DRM resource handles: Permission denied (os error 13)\\nError from Software renderer: Error opening device <REDACTED: user-file-path>: No such file or directory (os error 2)\\nNo renderers configured.")
```

That line in the generated file is in
```
115728   │          fn window_adapter_impl (& self) -> sp :: Rc < dyn sp :: WindowAdapter > {
115729   │              sp :: Rc :: clone (self . window_adapter_ref () . unwrap ()) }
```

Relevant backtrace:
```
6	"core::result::unwrap_failed"
7	"slint_lsp::preview::ui::slint_generatedPreviewUi::PreviewUi::new"
8	"slint_lsp::preview::ui::create_ui"
```

So the theory is that user_init need the window for some reason.
(eg, could be needing the scale factor to conver sizes or some other
things that needs the window)
So make sure we do the test before calling user_init
2025-05-07 09:04:02 +02:00
Simon Hausmann
ac1233491d cupertino: Fix missing title in GroupBox widget
Regression from commit c931cc28ae, which removed the two-way binding.
2025-05-06 17:26:10 +02:00
Simon Hausmann
f983cf0b19 Add Platform.os as well as a rudimentary test 2025-05-06 13:06:27 +02:00
Simon Hausmann
904bc56e62 Introduce Platform.style-name
This replaces the previously hidden `StyleMetrics.style-name` that was only accessible for internal use.
2025-05-06 13:06:27 +02:00
Olivier Goffart
86978e9fc1
Rust generated: fix constant non-inlined global
We must take care that all access to property that we consider constant
in global are accessed after the global has been initialized.

So initialize the global before the properties.

Fixes #8375 , #8337
2025-05-05 18:55:19 +02:00
Montel Laurent
4cd6f92013
Hide action when widget is disabled
ChangeLog: TextEdit/LineEdit : disable context menu action when the widget is disabled or read-only
ChangeLog: Added ContextMenuArea::enabled
2025-05-02 13:20:46 +02:00
FloVanGH
c931cc28ae
ChangeLog: std-widgets: added content-padding to GroupBox (#8314)
* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-05-02 07:11:52 +00:00
ogoffart
e0099ea500 Bump version number to 1.12.0 2025-04-30 13:27:50 +00:00
Bryce Happel Walton
769f85584d
Fix ScrollView scrollbar actions not triggering scrolled callback
Fixes #8170
2025-04-28 10:56:30 +02:00
Olivier Goffart
ff2e2e6731
Compiler: Fix changed callback on private global properties
The code would fail to compile because the property would not be seen as
used and would be removed, but not the change callback.

Fixes #8269

Also fix a segfault in the added test because it will initialize the
change callback (and therefore query the properties) because the
SharedGlobal structure is fully initialized.
So we must only initialize the change callback on global after the
SharedGlobal is fully initialized
2025-04-25 16:10:12 +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
Simon Hausmann
eb825f2e95 Support default-font-* properties in Live-Preview
... by changing the resolution for the `WindowItem` to traverse the
item tree from the current item, instead of going to the window.

This doesn't quite fix #4298 because `rem` resolution is still missing.
That requires the built-in default font size function to be fixed as
well, which is non-trivial.

cc #4298
2025-04-24 09:18:45 +02:00
Olivier Goffart
cc46811d95 Fix layout property set in when deriving components
The layout pass needs to see when going over the layout, that these
properties are set. So inline the element that sets these properties if
they are not set in the base.

Fixes #8091
2025-04-23 09:23:07 +02:00
Olivier Goffart
cedfefb1a2 Menubar: fix native menus
The condition was reversed

Fixes #8246
2025-04-23 07:29:14 +02:00
Olivier Goffart
cd8ab8ce53
Fix array index access at negative index
Conversion from negative float to unsigned is saturating to 0 in rust
and undefined behavior in C++, we should therefore handle the case
properly

Fixes #8222
2025-04-22 11:28:09 +02:00
U. Bruhin
a5ec77ac99
Allow trailing comma in import statements (#8223)
Adding support for (optional) trailing commas like this:

    import {
        Foo,
        Bar,
    } from "foobar.slint";

This way it's more convenient to keep component imports sorted and
leads to smaller diffs when adding more components to the end of the
import statement.

ChangeLog: Allow trailing comma in import statements

Closes #4922
2025-04-21 17:24:18 +02:00
Olivier Goffart
b77368f1b6
diagnostic: try to detect use of range expression and recommand to use number
Several users have been asking if it is possible to use range
expression.
Detect this and have a meaningful error message
2025-04-19 22:47:45 +02:00
Simon Hausmann
8761eaadeb
Move Palette.style-name to internal protected StyleMetrics.style-name (#8200)
This is only exposed when internal types are exposed (such as in the lsp).

The plan is to make this public under a new name/global after the release.

Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
2025-04-19 10:20:52 +02:00
Laurent Montel
eafa9bae12 Disable cut/paste action when textedit is disabled
(Too bad that we can't hide these actions)
2025-04-19 10:14:58 +02:00
Laurent Montel
706bd3e984 Disable cut/paste action in lineedit when disabled 2025-04-19 10:12:45 +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
Olivier Goffart
691039b7ea typeloader: Cache parse error for loaded document
We will need these if loading from cache

Fixes #8064
2025-04-15 19:22:57 +02:00
Olivier Goffart
25b2829052 LSP: do not clear error in dependency when reloading a dependent file
In the test, `reexport.slint` depends on `bar.slint`
When parsing `reexport.slint` we shouldn't clear previously reported
error from previously parsed `bar.slint`. The errors are still there.
2025-04-15 19:22:57 +02:00
Olivier Goffart
f669df913c Fix miscompilation because of too-agressive optimization
We try to only visit the bindings of used property.
The problem is that when we visit the element, not all properties have
been marked as used, yet. We have a chicken and egg problem.

So just visit all bindings even for property we haven't reached.
This is unfortunate that we have to do that, and we'd need a much
deeper analysis to do this properly.

Fixes #8144
2025-04-15 11:47:06 +02:00
Joshua Goins
d1f2fef430
Menu: Add enabled property (#8145)
By default it's enabled, of course. This property is not only added to
MenuItem, but Menu as well - since they can be nested. It's also
possible to select a disabled item, but it's hard to modify that since
it's logic is written in Slint. You should be prevented from activating
it with a tap or key press at least.

See #7791
2025-04-15 08:08:11 +02:00
Tobias Hunger
7a1bc6f6d7 live-preview: Add gradient support to the property editor
Parse the gradient data from source code and pass it on to the
UI side to do its magic.

SQUASH ME
2025-04-11 13:34:18 +02:00
Olivier Goffart
82adeb47b2
Fix accessing properties within the MenuItem
We were not visiting properly the MenuItem from
`recurse_elem_including_sub_components_no_borrow`
(`recurse_elem_including_sub_components` was correctly modified before)

Fixes #8090



The tree-sitter test fails because the output contained `ERROR` as it matched this string
2025-04-09 15:06:32 +02:00
Olivier Goffart
78a3757b7f
Remormat all the toml file again to fix npm upload
Commit cd6f2e2 reformated the .toml, but the 80 char width column is
judged too small to be practical

Add a .taplo.toml file

Also do not split feature array
2025-04-09 15:06:00 +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
Tobias Hunger
e1b85bbb93 component-container: Accept focus
So that we can pass the focus into the container when it first
shows.

I thought this would be super complex to do property! What a
nice surprise:-)

Fixes: #4055
2025-04-09 09:37:28 +02:00
Olivier Goffart
ca0c75bfe1 Menu: don't remove the title properties
Let further pass materialize them, and most likely remove them anyway.
That way, they can be properly set and read from the rest of the .slint
code.

Fixes #8080
2025-04-08 13:30:01 +02:00
Nigel Breslaw
538f8bde19
Allow checking at runtime about the current theme (#8049)
Although std-widgets provides many properties that adapt to the current theme users who would like to go beyond these properties and do theme dependent changes are limited. One option would be to add even more properties to the Palette, however this would potentially bloat the object, it's not obvious what properties users care about and this approach doesn't scale. In many cases developers could simply create their own properties if they knew what the current runtime theme was.

This simple change allows an app to know what the current theme is and present theme appropriate UI's.
2025-04-04 14:44:14 +03:00
Nigel Breslaw
ffce61ca97
HSV should wrap hue values otherwise it outputs an invalid hue of black (#8024)
Fix by wrapping around at 360.
Added tests.
Updated the docs.
2025-04-03 12:33:40 +03:00
FloVanGH
4d754b7ddf
StandardButton improvements (#8035)
* StandardButton improvements
* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-04-03 07:29:49 +00:00
Olivier Goffart
e5289af154 Introduce MenuSeparator
Fixes #7790
2025-04-02 11:50:45 +02:00
Tobias Hunger
cd6f2e2cf2 ci: Format toml files
... using taplo with default settings

I tried this with 4 spaces indentation, but the patch is almost as
big as this one, so I went with default settings instead as that
is just easier:-)
2025-04-02 11:03:41 +02:00
Olivier Goffart
7b8ef71ddd link_section needs unsafe with edition 2024
Second part of #7998
2025-03-31 17:35:22 +02:00
Olivier Goffart
6010cf724c Hover on MenuBar should activate menu if a menu is already open
Fixes #7822
2025-03-31 14:06:24 +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
Olivier Goffart
aca30901be C++: put the parent in a weak pointer
Right now we always `lock().value()` it which is the equivalent of
`upgrade().unwrap()` in rust, this helps because it keeps the parent
alive when we are calling function in it.

Ideally we should also check that it wasn't deleted, but that's another
issue.

Fixes #7880
2025-03-28 17:24:14 +01:00
Olivier Goffart
a80f14e7d8 Fix re-instentiating if elements when the condition is dirty
Fixes #3953
2025-03-27 15:37:07 +01:00
Olivier Goffart
3621fbcbd3
C++: fix mod with negative number again
`mod(-42, 2)` would return 2 instead of 0
2025-03-27 13:41:29 +01:00
Olivier Goffart
1efe8c8d5f
swrenderer: Don't overflow for font bigger than 256px
Fixes #7936
2025-03-25 15:51:18 +01: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
Olivier Goffart
92e5cef55f
Deprecate alias to global callback and error out when setting such callback
Also properly error out when the number of arguments to a callback alias
is not correct

Fixes #7806
2025-03-24 15:17:20 +01:00
Olivier Goffart
286bdc9ce5
Interpreter: Fix panic when animating a % property
Should register the Type::Percent as animated

Also avoid duplicating the binding for both min and max, and just make
one use the other.

Fixes #7761
2025-03-24 14:54:08 +01:00
Olivier Goffart
4015288080 Compiler: fix const propagation in condition
We should simplify the false branch even if the true branch can't be
inlined

Fixes #7827
2025-03-21 18:00:34 +01:00