Commit graph

209 commits

Author SHA1 Message Date
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
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
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
Olivier Goffart
e5289af154 Introduce MenuSeparator
Fixes #7790
2025-04-02 11:50:45 +02: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
1a2aff8b57
Revert "compiler: inline components that are used only once" (#7697)
This reverts commit bf716ff8c5.
(And also revert the test part of 259756c0fd)

This exposed the bug #7693 and more issues mentined in
https://github.com/slint-ui/slint/issues/7693#issuecomment-2675077008

Fixes #7693
CC #7680
2025-02-21 19:11:11 +01:00
Olivier Goffart
39191e5acd
Menu API changes
`ContextMenu` -> `ContextMenuArea`

`ContextMenu` must have a `Menu` child.
`MenuItem` can no longer be put dirrectly in `MenuBar` and can no longer
have children
`Menu` is used now for sub menus
2025-02-21 16:03:47 +01:00
Alex Badics
259756c0fd compiler: don't inline repeater components
They don't need to be inlined, and a lot of the times inlining them incur
a significant overhead (e.g. in case of conditional complex components)
2025-02-21 11:16:00 +01:00
Olivier Goffart
98e8386aee
MenuBar/ContextMenu: hide the entries interface
This can only be used internally by the style to implement the actual
ContextMenu

Only the declarative `MenuItem` interface is exposed.

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-25 11:06:31 +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
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
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
0ef44195f7 Add contextmenu syntax test 2025-01-21 15:41:25 +01:00
Olivier Goffart
7056515f6c Detect binding loops when it involve the condition of a if in a layout
Fixes #7126
2025-01-13 14:40:18 +01:00
Olivier Goffart
3e94bd2167 Janitor: Remove trailing whitespaces from all files
`git grep -I -l -O'sed -i "s/[[:space:]]*$//"' -e ''`
2025-01-10 13:23:22 +01:00
Olivier Goffart
9685af865a MenuBar: error when MenuBar is repeated or conditional 2025-01-08 11:00:59 +01:00
Olivier Goffart
aedd04a3d8 Parser: skip UTF-8 BOM
Skip the byte order mark.
BOM is also allowed in .rs or Cargo.toml file.

Fixes #7291
2025-01-07 12:34:08 +01:00
Olivier Goffart
76332c5e16 Improve a bit the error when the base of an element is missing 2025-01-06 10:47:05 +01:00
Arnold Loubriat
14466d1be6 Set accessible-label on tab panels 2025-01-06 09:30:11 +01:00
Arnold Loubriat
3304df0f82 Add AccessibleRole::TabPanel 2025-01-06 09:30:11 +01:00
Olivier Goffart
12c99f1c80 Add a warning when a component/type name overwrite another
Also fix the unused component warning when that happens
Fixes #7176

ChangeLog: Warning when a type name overwrite another
2025-01-03 09:29:27 +01:00
Tasuku Suzuki
bc89c634b3 Fix warning message for a property that name is used for function 2024-12-26 17:54:38 +01:00
Tasuku Suzuki
7a8ca9b147 Fix error message when a property named color is override
It said `Cannot override property 'background'` because color is defined
as below

```slint
property <color> color <=> background;
```

For the warning, the name should not be resolved.

Fixes #6324
2024-12-26 17:50:45 +01:00
Olivier Goffart
f31cefdea9
Fix min/max/clamp in presence of percentages
We were not properly converting the first argument

Fixes #7118
2024-12-16 18:44:55 +01:00
Olivier Goffart
60c10213d2
Remove LayoutSpec and undeprecate StyleMetrics.layout-* properties (#7069)
StyleMetrics is the right name for these
2024-12-16 14:52:28 +01:00
Olivier Goffart
4a5ba09e7a Fix panic in legacy component with out property
Fixes #7095
2024-12-16 13:58:56 +01:00
Olivier Goffart
6b3361d079 Properly report binding loop involing font-metrics 2024-12-10 21:26:58 +01:00
Olivier Goffart
0f15a26f35 PopopWindow: Fix close-policy and close-on-click when inheriting 2024-12-10 12:10:49 +01:00
Olivier Goffart
2ea482da49 Compiler: Change a new error from 1.9 to a warning
To keep compatibility with existing Slint code

Commit 53e79000a4 added a call to
LayoutConstraints::new which is shown to produce error in the crater
run.
2024-12-06 23:04:26 +01:00
Olivier Goffart
461beb80cd Fix purity check for focus() on custom component
Do the purity check before doing the transformation of the `focus()`
function, so the source location of the error is the most accurate

Fixes #6979
2024-12-03 15:52:33 +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
5bd20def0e Experimental support for MenuBar
Introduces `MenuBar{ ... }` that can be put in a Window
2024-11-20 09:25:37 +01:00
Olivier Goffart
650fd0eef5 Fix panic when calling expression containing un-called macro
Fixes #6650
2024-11-11 16:08:22 +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
dff19c52da Fix assertion failed: lhs_lookup.is_local_to_component
Fixes #6632
2024-10-28 11:44:25 +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
6717e627a1 Fix panic when a layout constraint has an Expression::Invalid as binding
We can detect this case earlier

Fix #6590
2024-10-22 09:35:57 +02:00
Olivier Goffart
6c81d5069e Fix parsing of unfinished import statement
Fix #6588

Note for the test: parse error at the end of the file are actually
reported at offset 0. Use a trick to add more `^` at the beginning to
mean that.
(Offset 0 is actually offset 1 as the column starts at 1)
2024-10-22 09:35:46 +02:00
Olivier Goffart
4e50fbdb15 Fix panic making an alias to a private property
Fixes #6587
2024-10-22 09:35:31 +02:00
Olivier Goffart
13d44130d9
Fix compiler panic binding to property with syntax error (#6572)
Fixes #6519
2024-10-16 21:35:35 +02:00
Olivier Goffart
f0e02a3aa3 Fix panic with invalid code
Fix #6518
2024-10-15 11:42:28 +02:00
Olivier Goffart
4718d5b050
Fix invalid node generated while parsing invalid @tr (#6560)
Fixes #6512

The TrPlural must always have an expression otherwise it panics later.
(Also adjust the panic message when nodes are missing)
2024-10-15 10:23:56 +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
d6706494a5
Binding between a read only property to input-output is deprecated (#6419)
ChangeLog: deprecated two way binding between `in` and `in-out` property

Fixes #6400
2024-10-01 16:00:06 +02:00
Enyium
4509496143
Improve layout-related error message. (#6264)
The phrasing shouldn't be universal, so users aren't taught it would always apply to *all* kinds of layouts.
2024-09-24 09:43:02 +02:00
Olivier Goffart
bcdc3e1cee Timer: make the interval property mandatory
A default of 0 is not a great default because that's way too often
2024-09-18 09:24:39 +02:00
Olivier Goffart
0c8a9fcefb Fix compiler panic when accessing path.commands in expressions
Fixes #5564
2024-09-10 13:36:09 +02:00