Commit graph

477 commits

Author SHA1 Message Date
Olivier Goffart
2e4d1f2427 WIP: work on changed callback 2024-05-02 22:25:53 +02:00
Olivier Goffart
12d904a71c
Fix compiler panic with init in a component inlined into a repeater
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
2024-04-29 15:34:12 +02:00
Simon Hausmann
10e5c228b7 Fix calling clear-focus() on non-focusable elements not producing an error 2024-04-26 11:09:11 +02:00
Simon Hausmann
d1dd89528b Simplify creation of focus() and clear-focus() forward functions from components to the inner focus forward element
... by sharing more code in the compiler.
2024-04-26 11:09:11 +02:00
Simon Hausmann
31767eb6ab Add a clear-focus()function on all elements that have a focus() function
This is the counter-part, which removes focus from the element if it's currently focused. The window - if focused - may still be focused towards the windowing system.
2024-04-26 11:09:11 +02:00
Olivier Goffart
13127dc71c Accessibility: Add support for accessibility-action-* callback (#5073)
Merge branch 'feature/accessibility'

 Conflicts:
	internal/compiler/widgets/cosmic-base/button.slint
	internal/compiler/widgets/cupertino-base/button.slint
	internal/compiler/widgets/fluent-base/button.slint
	internal/compiler/widgets/material-base/button.slint

Also updated license header in actions.slint
2024-04-16 15:02:25 +02:00
Olivier Goffart
ecf66ca3f2 Fix @children from inherited base
Fix #5071
2024-04-16 14:50:16 +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
Olivier Goffart
2c0ba2bc0f Compiler: properly transform property access from base expression in state
Fix #5038
2024-04-12 15:53:56 +02:00
Olivier Goffart
8900c17f2b Fix return statement within a cast expression 2024-04-02 15:00:32 +02:00
Olivier Goffart
523e1a161c WIP: More on support for accessibility actions
Continue with the core library support and the compiler support.

This hasn't been tested yet and is missing implementation in the
backends
2024-03-28 11:28:56 +01:00
Olivier Goffart
ea0227098a Throw an error when a callback aliases itself
Instead of panicking
Fixes #4938
2024-03-26 18:14:31 +01:00
Olivier Goffart
18eea8602a Fix insertion point of @children
Don't always appends at the end

Fixes #4935
2024-03-26 18:14:14 +01:00
Olivier Goffart
db08970324 Keep the optimized ElementRc around.
They can be used in as the Popup's parent_element which we need to get
to the parent's enclosing Component.
Since that parent_element is not in a RefCell, we can't change it.
parent_element is a Weak so if its optimized item is removed, we will
not be able to access it.

Fix #4884
2024-03-19 11:58:36 +01:00
Olivier Goffart
c553eb4398
compiler: Don't panic when using foo.focus(something)
Just ignore the case where focus has more argument that planed as it has
been reported as an error earlier.

Also fix the error message for calling member function with the wrong
number of argument to not include the base in the count.

Fix #4883
2024-03-19 11:06:08 +01:00
Olivier Goffart
5c381fd73e Fix clipping and border-radius
Fix #4854
2024-03-14 23:48:16 +01:00
Tobias Hunger
28b96ca6f6 janitor: manual cargo clippy fixes
Semi-random selection of clippy topics that were
uncontroversial before:-).

Leaves about 84 deduplicated issues in the code base
according to clippy from nightly.
2024-03-14 13:42:38 +01:00
Olivier Goffart
255dc59ef4 Rename @image-url(..., 9slice(...)) to @image-url(..., nine-slice(...))
As per API review:
 - In the Rust and C++ API we use `set_nine_slice_edges` because the getter couldn't start with 9
 - in english we spell number less than 10 with letters and this is a name
2024-03-07 17:01:57 +01:00
Tobias Hunger
06b04e71b5 compiler: Return the TypeLoader from compile_syntax_node 2024-02-29 19:35:52 +01:00
Tobias Hunger
48de2f83e4 compiler: Add layout debug info to all nodes when lowering layouts
This enables us to find all layouts e.g. in

```slint
component MyLayout inherits GridLayout { @children }

component FooBar {
   my-layout := MyLayout {
      Rectangle {
      }
   }
}
```
2024-02-26 22:19:29 +01:00
Olivier Goffart
11e8070726 Compiler: fix lookup of the model not seeing that the element is being repeated
The problem is that we were taking the whole `repeated` field and as a
result we wouldn't see that the element was being repeated and that we
shouldn't have to lookup id within it

Fix #4683
2024-02-26 12:16:51 +01:00
Olivier Goffart
2ab71db4f7 Update deps, including resvg 2024-02-21 12:30:33 +01:00
Olivier Goffart
fac0921579 Compiler: keep the layout debugging info next to its node 2024-02-21 11:33:37 +01:00
Olivier Goffart
22d9fc9cf9 @image-url: Semantic analysis of the 9slice 2024-02-13 14:46:27 +01:00
J-P Nurmi
cc5d2b24e5 Add BasicBorderRectangle to avoid unnecessary xxx-border-radius bindings 2024-02-06 18:01:35 +01:00
J-P Nurmi
031742246c Implement clipping 2024-02-06 18:01:35 +01:00
J-P Nurmi
51457025bf Add BorderRectangle::border_top|bottom_left|right_radius 2024-02-06 18:01:35 +01:00
Simon Hausmann
54d8b9adb3 Add missing debug assertion
As suggested in #4477, amends 7ce0bd493a
2024-01-30 13:44:16 +01:00
Simon Hausmann
7ce0bd493a Fix panic when using foward-focus with non-element binding
Since commit 6fefe75a1c the handling
of forward-focus bindings happens before the resolve_expressions pass,
which means that we cannot rely on type mismatch
error handling yet.

Fixes #4475
2024-01-30 10:09:07 +01:00
Simon Hausmann
72802a4106
Don't require inlining if an animated property is private and local (#4449)
* Don't require inlining if an animated property is private and local

This avoids inlining Button elements from our widget set.

This is covered by tests/cases/properties/animation_merging.slint
2024-01-26 14:51:58 +01:00
Tobias Hunger
91e4a1bfa7 compiler: Do not duplicate nodes when inserting a Window
Do not duplicate the root element's node(s) when the compiler adds a
Window element above the root element.
2024-01-26 13:19:48 +01:00
Simon Hausmann
6fefe75a1c Don't require components that use forward-focus to be inlined
Achieve this by generating a `focus()` function for such components
and call it from the outside.

This replaces the previous focus handling with what should be cleaner:

- Any `forward-focus: some-element;` is basically syntactic sugar for
 `public function focus() { some-element.focus(); }`.
- The init code gets simplified to calling focus() on the root, if it's
  available.

Since the `focus()` functions are now generated in the imports pass,
they become visible in the style checker. That means the checker
requires consistent focus handling between the styles.
2024-01-26 12:16:09 +01:00
Olivier Goffart
09dc25f107 Keep all nodes for a given element (even if it is optimized out) 2024-01-25 14:45:22 +01:00
Olivier Goffart
ffaf19812c Refactoring: use Element::to_source_location instead of the node directly 2024-01-25 14:45:22 +01:00
Olivier Goffart
1e19e0a754 Rust codegen: fix compile if slint names matches internal names
Fixes #4419
2024-01-24 22:47:58 +01:00
Olivier Goffart
2564eede9f Compiler: avoid two error message when trying to call a non-existing function 2024-01-24 20:06:48 +01:00
Simon Hausmann
ec1b991c53 Fix calling builtin member functions on the root item when a window item is injected
The element references, just like the named references, need to be fixed up.
2024-01-23 11:04:13 +01:00
Olivier Goffart
c7aae4b77e Update resvg and related dependencies 2024-01-22 16:16:35 +01:00
Tobias Hunger
382b5486ca
Component container subcomponent (#4355)
This changes the component containers away from using a "MAGIC" index in the
placeholder dynamic item tree node it creates. These are hard to
integrate across sub-components.

Use index numbers right after the index numbers used by repeaters and
"extend" the repeater offset by the number of component containers in
the sub-component. This way we can piggy-back on the forwarding of
repeaters.

This has one annoying side-effect: We do have indices in our item tree
that are out of range for a repeater. But I think that is acceptable
considering that we never materialize that array anyway.
2024-01-17 11:26:08 +01:00
Simon Hausmann
fef9c446a4
Fix missing invocation of init callbacks due to inlining (#4322)
When a component declares an init callback as well as the element that
instantiates it, the init callback of the container would not
get invoked if the container was inlined:

```
component InlinedContainer {
    init => { ... } // not invoked
    @children // force inlining
}

component UseSite {
    InlinedContainer {
        init => { ... }
    }
}
```

That's because the inlining happens very early, before the init
callbacks are collected into the init code. And during inlining that
would be treated like a property binding and the "binding" at the
element site overrides the one at the component site.

One natural approach would be to move the init code collection to an
earlier place before inlining, but that isn't possible because the
boundaries of the compiler components (Rc<Component>) aren't set
up yet (repeated component extraction phase happens much later).

An alternative would be to re-introduce the init callback code in
ElementRc and place it in there at *::from_node() time.

This patch chooses to solve this at the inlining time: When we're in the
first phase of the inlining (the optional one), do what
with the init binding what collect_init_code would do later: Move it
straight into the init_code of the component we're inlining into.

Fixes #4317
2024-01-12 10:14:27 +01:00
Simon Hausmann
5f69857926
Fix missing font fallback handling on Windows when pre-rendering glyphs for the software renderer (#4245)
Add some symbol/emoji fonts for Windows, next to the existing options for macOS and Linux.
2024-01-02 13:37:08 +01:00
Olivier Goffart
85526d772e Fix detection of properties when they are only used in two way bindings
Fixes #2166
2023-12-19 11:14:53 +01:00
Tobias Hunger
d785f2d5df compiler: Store an optional version number with the document
A None value means the file on disk is the golden version.

We have an editor, the LSP and the preview that all need to at least
notice when they have newer data then their peers. So IMHO it makes
sense to have an optional document version around.

The language server protocol makes use of a version number already. This
patch moves that code into the compiler so that it is stored with the
actual data getting versioned.
2023-12-18 14:21:50 +01:00
Olivier Goffart
63d199a728 Rust&C++: Fix Return value of complex expression
We were using the has_value of the previous expression of a sequence of
expression, instead of using the last expression type to know if there
is a value.

Fixes #4070
2023-12-08 17:28:38 +01:00
今何求
607bdbfcf8
Upgrade to fontdue 0.8
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2023-11-29 10:52:27 +01:00
Olivier Goffart
a3e48c4950 Const propagation of min and max
Since we generate a lot of max(min, preferred) in the geometry code,
this allow to simplify some expressions in the generated code
2023-11-24 14:20:27 +01:00
Olivier Goffart
fdfa4b31e4 Visit the geometry property as root from binding_analysis
We need to visit them from there to mark them as used externally,
otherwise the remove_alias passes might remove them.

Fixes #4002
2023-11-24 14:07:42 +01:00
Olivier Goffart
678afb3ba0 Throw an error when returning no value when one is expected.
Previously we were likely to get error in the compiled code anyway.
(although the interpreter worked fine)

Fixes #3962
2023-11-20 13:50:57 +01:00
Olivier Goffart
8d91ff7dea
Fix compiler panic when there is a component called "Window"
the ensure_window and popupwindow passes were looking up the "Window"
builtin in the global register instead of in the builtin register,
causing the presence of an user-defined "Window" to cause panic.

The "Clip" and "BoxShadow" calls are not affected because they were
looking up in the builtin reguister, but using the appropriate function
is more future-proof

Fix #3916
2023-11-20 13:10:31 +01:00
Olivier Goffart
ac8fd60091 Fix regression with empty array
Regression noticed in this line:
3f97d98bff/ui/tabs/downloads.slint (L77)

The following used to work:

```slint
import { Button, VerticalBox } from "std-widgets.slint";
export component Demo {
    in property <[int]> mods;
    VerticalBox {
        alignment: start;
        for xxx in true ? mods : [] : HorizontalLayout { alignment: center; Button { text: "OK!"; } }
    }
}
```

But we fixed array conversion and this caused a regression with empty
array
2023-11-01 11:30:59 +01:00