Commit graph

134 commits

Author SHA1 Message Date
Olivier Goffart
425b477874 Always keep the binding of the right in a two way binding
When having a binding such as
```
  foo <=> bar
```
The default value will always be the value of `bar` regardless what's
the value of foo.

This change of behavior is the only one that makes sense bacause if we
are having repeater or if, this will be a problem. eg:
```
property <xxx> bar;
if (some_cndition) : SomeElement {
   foo <=> bar;
}
```
Then we can't possibly take the default value of foo for the value of
bar since it depends on the condition. (and it is even worse in case of
repeater)

This is a change of behevior, this is why the tests have changed. The
cse of tests/cases/bindings/* were already covered by a warning since
0.3.0 so that should be fine. But the warning did not trigger for
builtin property such as `visible`  (eg, input/visible_mouse test)

Also some internal two way bindings had to be reversed.

cc: #1394
2022-11-04 15:32:20 +01:00
Simon Hausmann
39121994ca Always set Window.default-font-size
Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
2022-11-03 17:15:44 +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
Simon Hausmann
65e4e7bf15 Bump resvg/usvg/tiny-skia dependencies 2022-11-01 10:44:33 +01:00
Olivier Goffart
f055afd2de New syntax: allow to create component without base 2022-10-26 18:09:57 +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
Florian Blasius
c58c704f16
Change type of Window background from color to brush (#1755) 2022-10-21 16:17:22 +02:00
Olivier Goffart
0ba8f58076 New syntax: New lookup rules for unqualified identifier
Instead of looking up any property in `self` and `root`, only resolve
the properties in scope declared in the current component.
2022-10-20 16:40:29 +02:00
Olivier Goffart
9518e7184d Check access rights when accessing properties within expression 2022-10-20 08:02:26 +02:00
Olivier Goffart
c1f4f4e96b Start working on input/output properties 2022-10-20 08:02:26 +02:00
Olivier Goffart
328cee7289 collect_structs: Also visit the type of array expression
Prevent compilation error in the generated code when dealing with
empty array expression of a given type, which is otherwise optimized out

Fixes #1733
2022-10-19 14:19:39 +02:00
Olivier Goffart
0d07d34c69 Fix panic when the forward-focus expression is invalid
Caused a crash of the LSP when having invalid element in the
forward-focus property
2022-10-18 10:13:55 +02:00
Olivier Goffart
d18ed9f799 Fix panic when doing binding analysis of properties in repeater in layout
Given an element in a layout, we must visit the properties in the
repeated component, not the dummy repeated element.
2022-10-18 10:11:40 +02:00
Be
ecb6fd5309 switch to yeslogic-fontconfig-sys from servo-fontconfig
This allows setting the RUST_FONTCONFIG_DLOPEN environment variable
to dlopen fontconfig at runtime rather than linking it at build
time. This is helpful for cross compiling to Linux, particularly
because fontconfig has lots of C dependencies. Building a vendored
copy of fontconfig does not work as expected:
https://github.com/slint-ui/slint/issues/88
2022-10-05 15:21:54 +02:00
Olivier Goffart
e7506e0d2a Dependency analysis: properly visit layout properties
in the funciton `visit_layout_items_dependencies` we were passing a
NamedReference for a property that could have been in the base
component type of an element, instead of in one of the element within
the current visited component. This would result in wrong computation
done later to find out the "element path" of the property.
We then need to tell the visitor that the named reference is in a sub
component. To do that, we need to visit a PropertyPath instead of just a
NamedReference

Issue 1659 was showing one of the symptoms of this, which was an assert.
But it could also result in wrong analysis (binding loop not detected
when it should or vice versa)

Fixes #1659
2022-09-19 18:38:29 +02:00
Olivier Goffart
6d12b276a9
Polish of the rotation feature
- Add a check that this only Applies to Image element without children
 - Default the origin to the center of the Image
 - Add docs and test

cc: #1481
2022-08-30 12:10:42 +02:00
Simon Hausmann
e5d8b0e9d9 Remove unnecessary collect in lower_property_to_element
We can pass an iterator instead
2022-08-17 08:39:10 +02:00
Simon Hausmann
56cbb0e642 Adjust lower_property_to_element signature to visibily separate between main property and extra properties 2022-08-17 08:39:10 +02:00
Simon Hausmann
ef318c4f69 Make the property to element lowering a little less magic
Instead of automatically mapping property bindings if the initial property has a `-` infix,
supply the list of all properties as a parameter.
2022-08-17 08:39:10 +02:00
Olivier Goffart
46854c7291 Workaround for issue #1461
Some binding can't be express with the current data structures because
they reference propertis within inner elements within a component.

The fix is a bit involved and the best is to have an error istead of a
panic, for now.
2022-08-17 07:49:05 +02:00
Simon Hausmann
686df50e9f Revive support for rotation of elements
The rotation-angle/rotation-origin-x/y properties are lowered to an
injected Rotate element, that we already had.

This needs further fixes for transforming input events and an
implementation of rotation in Skia.
2022-08-11 10:34:41 +02:00
Olivier Goffart
dd081758b0 Upgrade to lyon 1.0 2022-07-22 19:27:49 +02:00
Olivier Goffart
57d61475b3 Detect loop on the property itself
This is the most basic loop and we wouldn't show a signal.

Turn out the comment was wrong and we do not seem to emit the error
twice for two ways binding to itself

Fixes #1407
2022-07-22 13:29:18 +02:00
Olivier Goffart
2c64cfcc82 Keep the same priority for property changed by states with or without default value 2022-07-08 19:05:54 +02:00
Olivier Goffart
d7dc9821a7 Take the priority into account when emitting the compat alias warning 2022-07-08 19:05:54 +02:00
Olivier Goffart
9eb8518278 Add a warning when setting a two way binding for which the rhs does not declare a default value
Because of issue #1394 and because the semantic are not properly defined
currently, we decided that future version of slint should always and only
take the binding from the right hand side, even if it has no bindings.

Since we can't change the behavior in 0.2, just add a warning instead for now.
The warning can be silenced by setting a default binding for the property on the rhs.

Ignoring the warning can still lead to panic (the one in #1394)
2022-07-08 19:05:54 +02:00
Olivier Goffart
9111dbfbce Don't optimize const state property
state info properties are special and cannot simply be inlined or set
(because we need to record the time it was changed and stuff)
So disable the optimization for now.

In fact, what could be done is to remove the state entirely if the state property
is constant. But that change is a bit more involved

This patch does:
 - Don't inline const state property
 - Don't generate a call to .set in the generated code
 - Also allowed to debug the expression with a context from the generator
   (added T generic parameter to the pretty printer)

Fix panic reported in https://github.com/slint-ui/slint/issues/1327#issuecomment-1151244049
2022-06-27 16:25:57 +02:00
Simon Hausmann
8428a1dad1 Fix wasm build 2022-06-16 15:21:01 +02:00
Simon Hausmann
7c37a3b14e mcu: Fix missing glyphs in the slide puzzle
Scan for string literals to make sure to include the special characters used in the demo.
2022-06-16 15:21:01 +02:00
Simon Hausmann
9f957e7db5 Fix some missing glyphs in the slide puzzle on stm32h7
Implement some very rudimentary font fallback handling and add some the
glyphs the puzzle needs.

The font fallback handling deserves to go into a module shared between
GL backend and the compiler.

For the character selection we should scan the text elements for
literals just like we do for the font size.
2022-06-16 15:21:01 +02:00
Simon Hausmann
3bc43cdcfa mcu: embed default font and imported fonts
Make sure to embed whatever we pick as default font, but also register
any custom imported fonts.

This fixes the plaster font not showing up in the slide puzzle on the
stm32.
2022-06-16 15:21:01 +02:00
Olivier Goffart
014c827194 swrenderer: Optimize image drawing by using premultiplied colors 2022-06-14 11:23:02 +02:00
Tobias Hunger
07ad20a09c
Basic Slint accessibility support (#1294)
Implement basic accessibility (a11y) support, using the Qt backend.

_This should get us started, but accessibility support is an additional way to interact with UIs that is very different from the "graphical way" most users will interact with the UI. No single PR will "make a toolkit accessibility", this needs to be an ongoing effort!_

Parts of this PR:

* Add functions to access a11y-related properties to Component
* Add helper functions to Item struct 
* Handle accessible- properties in the compiler
* Add documentation, add description, enforce some basic rules
* Make the Text element accessible by default
* Don't optimize away accessibility property in the LLR
* Ensure that accessibility property are marked as used
* Add some accessibility properties to the native style widgets
* Support for bool and integer `accessible` properties
* Implement basic support for accessibility
* Make basic widgets accessible by default
* Make slider focus-able and interactable with keyboard
* Tell a11y layer about value changes
* Generate QAccessible constants using bindgen
* Don't expose the `accessible` properties when using the MCU backend: There is no backend to make use of them
* Handle focus change based on keyboard focus of the window
* Report accessible widgets at correct positions
* Allow for (virtual) focus delegation at the a11y level
* Calculate value step size dynamically
* Make sure to not send notifications to a11y backend about dead objects
2022-06-08 20:42:10 +02:00
Olivier Goffart
31502d5918 VSCode web extension: load files from the vscode API
We can't use file system call to load files with wasm, we need to go through the vscode API

Note that this is all async, so i had to prevent re-entry within the compiler using a rentry trick.

I removed the lifetime in the TypeLoader because I thought this was going to be necessary
to get 'static futures. But it turned out not to be necessary. Anyway, I kept it htis way because
it is actually nicer IMHO, even if the CompilationConfiguration is now copied
2022-06-02 16:21:07 +02:00
Olivier Goffart
a20d08b45f deduplicate_property_read: bail out if there is a write
Fixes #1271
2022-05-31 14:55:09 +02:00
Tobias Hunger
96b6ca8830 janitor: Remove unnecessary references 2022-05-22 11:59:00 +02:00
Olivier Goffart
9fc838206a Fix gradient interpolation
When the percentage is missing, we should interpolate between the
last valid entry to the first valid entry after that, not always the
last valid entry in the whole gradient
2022-05-21 12:00:20 +02:00
Simon Hausmann
fd195904a1 Allow for the use of cache-rendering-hint in separate components
The `lower_property_to_element` pass usually disallows that because it
injects the Layer element and we can't do that for components. But we
can handle this like with opacity and inline.
2022-05-19 18:50:45 +02:00
Olivier Goffart
b4ebd88d35 Implements @radial-gradient(circle, ...)
Only the circle is implemented so far.

Part of #263
2022-05-19 14:07:20 +02:00
Olivier Goffart
b3fe9cc96d Fix compiler panic when optimizing child of layout
Normally, child of layout don't get optimized anyway because
the layout sets their `x` and `y` prop, preventing the optimization.
But if the rectangle has an opacity, its `x` and `y` property are
stolen by the opacity element, and then it can get optimized anyway

Fixes #1267
2022-05-13 16:05:15 +02:00
Olivier Goffart
a2d5ddaeca Fix priority of aliases when default value are involved
This code would have unpredictable results:

```slint
export Button := Rectangle {
    property<bool> the_enabled <=> touch.enabled;
    property<bool> the_visible <=> touch.visible;
    background: !the_enabled ? blue : red;
    border-color: !the_visible ? green : yellow;
    border-width: 15px;
    touch := TouchArea {}
    fs := FocusScope {
        enabled <=> root.the_enabled;
        visible <=> root.the_visible;
    }
}

Demo := Rectangle {
    VerticalLayout {
        spacing: 10px;
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
        Button { the_enabled: false; the_visible: false; }
    }
}
```

Because the enabled and visible property defaults to true (default
enforced by the compiler), but we set it also to false via an alias
2022-05-09 09:30:01 +02:00
Olivier Goffart
01bf529f79 Properly initialize the default binding of a state to its materialized value
Fixes #1237
2022-05-06 12:55:42 +02:00
Olivier Goffart
8be92eac1d Fix conversion from brush to color in the ternary operator
Fixes #1235
2022-05-06 10:29:54 +02:00
Olivier Goffart
e85e69fda0
Declare .slint enum in one place in i-slint-common
This avoid repeating the enums both in the compiler and in
the runtime library, and register them in a bunch of other places.

So it should be easier to add enums and enum values

Since cbindgen doesn't see through the macro, generate the enum
manually
2022-04-14 19:17:48 +02:00
Tobias Hunger
2c82fd7618 Tab: Make tab accept keyboard 2022-04-13 14:42:32 +02:00
Simon Hausmann
5aae0b7312 Fix wasm build 2022-04-08 15:11:26 +02:00
Simon Hausmann
70f3f50359 mcu: Add support for automatic font size detection
Continue to support specififying logical font sizes in the compile step
via SLINT_FONT_SIZES, but additionally look for Text/TextInput/Window elements
and extract any constant font sizes
found.

This makes it work out of the box with the printer demo.
2022-04-08 15:11:26 +02:00
Simon Hausmann
819c058fd6 Add support for multiplication and divison to the constant propagation when only one unit is present 2022-04-08 15:11:26 +02:00
Olivier Goffart
f8f61dc2b7 Fix a bunch more issue with PopupWindow
* Make sure that the compiler don't panic if the parent of a PopupWindow
   is optimized (by not optiizing such element)

 * Ensure that we can call popup.show() from within a deeper repeater

 * Ensure that the parent element of the popup is the right one in case of
   repeater (and not the node in the parent component)

This partially revert ad5991f8fa and
6c7a7aed0e because we must do the lower_popup
adter the repeater pass, because otherwise the parent element of the
created component for the PopupWindow might be wrong and it is not easy to
adjust (we would have to make Component::parent_element a RefCell or duplicate
it again.

Fixes #1132
2022-04-01 14:06:38 +02:00
Olivier Goffart
ad5991f8fa Fix PopupWindow within repeater
* The LLR expect that the popup_window is actually contained in it's parent
   component popup_windows, otherwise the context is not correct.
 * There is no index property for a PopupWindow

Fixes #1113
2022-03-30 16:46:55 +02:00