Commit graph

1488 commits

Author SHA1 Message Date
Simon Hausmann
ab1341878f
Make SlintInternal.dark-color-scheme a property instead of a function (#1790)
That's a more idiomatic API - the compiler can map the lookup straight
to a function call.
2022-10-28 14:20:20 +02:00
ogoffart
2171773a3e Bump version number to 0.3.2 2022-10-28 09:30:14 +00:00
Simon Hausmann
3d2daf6073
Fix crash when editing text that's rendered using the Skia renderer (#1786)
Olivier found the following steps that reproduce the crash with Skia:

1. Open the gallery and select the "Text Edit" tab.
2. In the first text edit widget, select the first three letters.
3. Click into the second text edit (while the first one shows the selected text)
4. At the beginning of the text, insert the letter "ù" a few times.

This sequence would result in the cursor_position property get out of
sync.  Since it represents a byte offset in the utf-8 text, it would
point straight into a utf-8 sequence, resulting in a panic when the
renderer would try to create a slice of the selected text.

As a remedy, this patch renames the cursor_position and anchor_position
properties and provides wrapper getter accessors for use within the
TextInput to safely bound the stored offset.

Eventually we need to intercept changes to the text property and adjust
the cursor and anchor position properties accordingly, so that they
remain valid.  However this requires that the compiler is aware that a
property is not accessible directly but has a setter that needs to be
called instead.

This likely/hopefully also fixes #1707.
2022-10-27 21:47:14 +02:00
Olivier Goffart
3240fd8bf9 Test: fix the parser tests when running without SLINT_EXPERIMENTAL_SYNTAX defined
Ignore the error mentioning the new syntax
2022-10-27 13:06:40 +02:00
Olivier Goffart
f055afd2de New syntax: allow to create component without base 2022-10-26 18:09:57 +02:00
Simon Hausmann
d7e366864b Bump various dependencies
Bump fontdb, foreign-types (used for skia/metal), ttf-parser and winit.

The winit bump is explicit on the patch version to ensure the IME crash
fix is included.
2022-10-26 18:01:29 +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
Simon Hausmann
871a06224f Add support for fluent-light and fluent-dark styles
These variants of the fluent style will use either the light or the dark color scheme,
regardless of the system wide setting.
2022-10-26 13:30:09 +02:00
Simon Hausmann
c16253d29f Use Property<LogicalLength> instead of Property<Coord>
This removes the special code for the generated property getters and
ensures type safety in the run-time library for property value setting.

In the Rust generated code we continue to do arithmetic on the scalar
values, that means we immediately extract the scalar, do arithmetic and
rely on the compiler to only allow compatible units.

Danger zone alert: In the interpreter Value::Number can now be converted
to LogicalLength as-is.
2022-10-24 12:49:37 +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
659cb3a06c LSP: fix property call on invalid base or non-main component
- We should not panic if the base type is invalid
 - We should try to keep bindings in the Element even if the base type
   is invalid
 - Fix querying the element at a position in case it is not in the last
   component of a file
2022-10-21 12:50:42 +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
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
69b15043d4 Gate the new syntax with an environment variable 2022-10-20 08:02:26 +02:00
Olivier Goffart
b24a2d6a57 new syntax: comments from review 2022-10-20 08:02:26 +02:00
Olivier Goffart
fd23745c02 Test for the input output properties 2022-10-20 08:02:26 +02:00
Olivier Goffart
baeb2cd419 New language syntax: allow struct declaration without ':=' 2022-10-20 08:02:26 +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
a3ba7bf78a syntax_updater: Continue new syntax, add it to the parser
This re-adds inheritence with the "inherits" keyword
2022-10-20 08:02:26 +02:00
Olivier Goffart
98a922bf42 syntax_updater: Experimental support for input/output properties 2022-10-20 08:02:26 +02:00
Olivier Goffart
d2af9e3fc8 syntax_updater: Implement a way to fully qualify all expressions 2022-10-20 08:02:26 +02:00
Olivier Goffart
94a37c8e16 Move dark-color-sheme builtin in an internal namespace 2022-10-19 15:23:41 +02:00
Olivier Goffart
6ee932883a Rename stark-style to dark-color-scheme
That's the term used by CSS
2022-10-19 15:23:41 +02:00
Olivier Goffart
0ba468c236 Use a builtin function to access the dark-style
instead of a property on NativeStyleMetrics
2022-10-19 15:23:41 +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
Simon Hausmann
77441c6686 Fix AboutSlint not adjusting to the dark style
The dark-style property needs to be kept up-to-date with the NativeStyle, like the Palette.
2022-10-18 15:54:57 +02:00
Simon Hausmann
75487f0a9d Add a dark theme for the fluent style
This is computed via the fluent theme designer by swapping text and background.
2022-10-18 15:54:57 +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
Florian Blasius
7d4dd770fb
Florian/cpp popup px fix (#1735)
Fix casting of x, y inside of the `show_popup` method generated by the cpp compiler. Fixes #1732
2022-10-17 17:59:35 +02:00
Simon Hausmann
36e74e509e Fix internal inconsistency with drop shadow blur property
In the documentation and type register, `drop-shadow-blur` is of type `length`.

In `BoxShadow` it is also a `Property<Coord>` and treated as such: the value
is multiplied by the scale factor.

However in `builtins.slint` it was declared as a property of float, which
is incorrect.

This change should not have any visible impact, as the externally visible type
was always length.
2022-10-14 10:14:36 +02:00
Simon Hausmann
27fea8b9f3 Fix rustdoc warnings with nightly
Use backticks as recommended by rustdoc for items that could be interpreted as HTML tags.
2022-10-12 17:29:46 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +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
ogoffart
261614b914 Bump version number to 0.3.1 2022-09-15 14:39:51 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +02:00
ogoffart
05a49da906 Bump version number to 0.3.0 2022-09-06 13:00:22 +02:00
Olivier Goffart
40f489041e Rename slint::internal to slint::unstable_private_api and move re_exports into it
Also move the module in its own file
2022-09-06 05:42:11 +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
41affeb68f Fix element rotation when the element is translated
For example

    Image {
        x: 150px;
        y: 50px;
        rotation-angle: 45deg;
    }

will end up rendering as if x and y are zero. This is because during
the injection we "move" x and y to the Rotate
element as bindings, but due to the lack of built-in
x/y properties, dummy properties are materialized
and they are not applied for the regular per-item translation.

Add x/y to the Rotate element and then it works.
2022-08-29 17:52:37 +02:00
Tobias Hunger
88cf874d03 API cleanup: Rename create_window to create_window_adapter 2022-08-29 16:53:47 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Simon Hausmann
d90b503a1c Move the mcu backend to become a board support helper crate for examples 2022-08-25 12:54:52 +02:00
Olivier Goffart
1884ddf4c6 Add api so slint-build to chose how to embed the images 2022-08-24 18:18:44 +02:00
Simon Hausmann
1d436778c1 Remove the use of the PlatformWindowRc alias again
and use Rc<dyn PlatformWindow> instead. The alias has to stay with the ffi
functions though and the item vtable definitions,
because we don't have an Rc<> template in C++.
2022-08-19 15:07:27 +02:00
Simon Hausmann
98e1befd0d Port the C++ generator and C++ API to the new window ownership model
One key difference to the Rust way is what `slint::Window` means. In
Rust that holds the `WindowInner` and `slint::Window` is only exposed as
`&slint::Window`. This is possible because the component owns the
`Rc<dyn PlatformWindow>`, which has a function to return the
`&slint::Window`.

In C++ `slint::Window` is also exposed as `slint::Window&` in the
`window()` getter, but there's no way to get a reference to a  C++
wrapper for the Rust `&slint::Window` that the `PlatformWindow` trait
returns. Therefore in C++ `slint::Window` wraps `Rc<dyn
PlatformWindow>`.
2022-08-19 15:07:27 +02:00
Simon Hausmann
fd026a3991 Change itemtable to use &PlatformWindowRc instead of &WindowInner
The former is cbindgen friendly, the latter is entirely Rust internal.
2022-08-19 15:07:27 +02:00
Simon Hausmann
7355c6f378 Port the rust code generator to the new window ownership 2022-08-19 15:07:27 +02:00