Commit graph

282 commits

Author SHA1 Message Date
Tobias Hunger
a362b7a1ae Add window_adapter to ComponentVTable
Make it duplicate as `maybe_window_adapter` with a boolean `do_create`
parameter.
2023-07-27 12:04:16 +02:00
Tobias Hunger
9de515b768 Implement embedding in rust 2023-07-27 12:04:16 +02:00
Tobias Hunger
5db78b6dd2 Implement LLR code lowering for ComponentContainer 2023-07-27 12:04:16 +02:00
Tobias Hunger
d47d52bf52 ItemVTable::init(...): Take an ItemRc so that the itan can know where in the Item Tree it is located 2023-07-27 12:04:16 +02:00
Tobias Hunger
74ef877f70 Add embed_component to ComponentVTable 2023-07-27 12:04:16 +02:00
Tobias Hunger
2840886d28 Add component-factory type to Slint language
Add a type "component-factory" to the Slint language.
2023-07-27 12:04:16 +02:00
Olivier Goffart
bde0ae7585 Compiler: Fix access_item_rc in the generator for complex path
Fixes #3148
2023-07-26 13:45:20 +02:00
Guiguiprim
ef8ddaaa1d
Add native support for min/max 2023-07-21 16:26:41 +02:00
Guilhem Vallat
0ebcc2be70 remove clippy warning in rust code gen
This generated a `clippy::clone-on-ref-ptr` warning
2023-07-19 11:04:25 +02:00
Olivier Goffart
81e5d3bb36 Fix setting rotation-angle and opacity from a callback
... if they are not set as actual binding before

As reported in #3068

The problem is that the pass will properly create the Rotation or
Opacity item, but will not create the two way binding if there is no
existing binding. This causes code like `img.rotation-angle = ...` to
change the rotation angle of the image, but not its parent Rotation
item.
Fix it by making sure there is always a binding.

Since the change only affect visual representation, I abused one of the
screenshot test to test this feature. And I also patched another bug
that some #[allow(unused_parens)] was not set in the 'init' callback and
would cause a warning in the test
2023-07-11 20:07:49 +02:00
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Guilhem Vallat
3d30e81668 reduce rust generated file size
using `use slint::private_unstable_api::re_exports as sp;` should
allow to safely qualify everything will keeping things shorter.

For the `todo` example:
- before 1_050_650 octets for 24_012 formatted lines
- after 934_049 octets for 23_032 formatted lines

This also makes the generated code more readable if needed.
2023-07-03 16:36:11 +02:00
Olivier Goffart
d4216385d8 refactor: extract the resource code generation in a function 2023-06-29 10:43:46 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +02:00
Simon Hausmann
ab0e38c76d
Merge absolute-x and absolute-y "virtual" properties into absolute-position (#2942)
The type of thep property is `Point`, which existed before. It was
mapped to `slint::private_unstable_api::re_exports::Point` (euclid) and
is now mapped to slint::LogicalPosition (also in C++).
2023-06-21 08:17:57 +02:00
Olivier Goffart
fdec5960bd Support for @rust-attr on enums 2023-06-19 22:40:49 +02:00
Olivier Goffart
11dea135f7 Domain: slint-ui.com -> slint.dev 2023-06-16 10:55:08 +02:00
Aurindam Jana
039e54a5de
Add royalty free license to files except examples and docs (#2888) 2023-06-15 11:20:50 +02:00
Olivier Goffart
0e31f097a4 Un-seal the WindowAdapter trait 2023-06-13 17:44:04 +02:00
Olivier Goffart
18ba3c2ae2 Slint enums in Rust and C++ 2023-06-12 13:02:14 +02:00
Simon Hausmann
e663282c65 Fix support for High-DPI with Qt
Preserve the early backend initialization of commit
f0b047057b
2023-06-10 11:41:04 +02:00
Simon Hausmann
01b00d26eb Rust: Allocate the window adapter lazily
This will be needed for embedding - to avoid creating two window
adapters - and it will be needed for the API to allow creating a
component from an existing window.
2023-06-10 11:41:04 +02:00
Olivier Goffart
12e6b34e2d Translations: support for plurals 2023-06-07 10:34:34 +02:00
Simon Hausmann
1bf05eae7c
Add support for absolute-x and absolute-y properties on any element (#2823)
Fixes #1691
2023-06-06 14:37:53 +02:00
Olivier Goffart
cf746ddf8d WIP: formatting implementation of translate in rust and C++ 2023-06-05 16:34:59 +02:00
Olivier Goffart
dcd8450dfa WIP: start working on translations: @tr()
This commit just do the parsing of the @tr macro.
2023-06-05 16:34:59 +02:00
Amirhossein Akhlaghpour
3a4f3c61d5
Add @rust-attr on scturct (#2785)
Fixes: #2660
2023-06-05 16:29:55 +02:00
Simon Hausmann
0f54b9599b Add support for manually closing PopupWindows
This patch adds a `close()` function that can be called to close a popup
window, and a `close-to-click` boolean that can be set to false to
disable the default behavior.
2023-06-02 18:07:49 +02:00
Simon Hausmann
a0a5294e49 Fix init callbacks not being invoked for PopupWindow 2023-06-02 18:07:49 +02:00
Olivier Goffart
5599bd44e0 Remove Color::opaque
It is not a right name and i don't think it is a so common operation
2023-06-02 17:02:08 +02:00
Olivier Goffart
4845241ebf Rename translucent to transparentize and mixed to mix 2023-06-02 17:02:08 +02:00
Arthur Araruna
64ad1ce357 Add some color and brush manipulation funcs (#2565)
The added functions enable mixing colors and manipulating the opacity
of colors and brushes.

They enable the behavior of some of the available functions from SASS and are
added for future use for adding the Adwaita style (future PR).
2023-06-02 17:02:08 +02:00
Simon Hausmann
c428601370
Add support for select-all(), cut(), copy() and paste() functions on text input elements (#2804)
In the compiler this is still very primitive, but an attempt to start a
generic interface. The basic assumption is that all item functions will
eventually need access to the window adapter and itemrc. Support for
additional arguments is still missing.

Also missing is support for the function access via rtti in the
interpreter, hence the hardcoding at the moment.
2023-06-01 16:04:53 +02:00
Simon Hausmann
6b8214c3f9 Add support for italic and bold text in the software renderer's bitmap font path
In the screenshot tests this works by setting SLINT_DEFAULT_FONT to
pointer to a directory, instead of a file. We then load all fonts in
that directory and consider their families the default unless a family
is specified. This way for "Noto Sans" a regular as well as an italic
version is registered in fontdb and returned in the list of font
fallback ids. embed_glyphs in the compiler then embeds those variants
and we find them at run-time.
2023-05-31 18:47:39 +02:00
Olivier Goffart
a57c7eb6bc Added TextInputInterface.text-input-focused 2023-04-12 14:49:08 +02:00
Olivier Goffart
7652097582 Better error message when trying to use private property in native code
If one declare a `property <int> foo;` in Slint, it will be private by
default, and the getter/setter won't be generated, and it may be
confusing as to why

With this change, it still generate private getter and setter so this
gives a better hint to the developer what the problem is.

Replaces #2170
2023-03-27 17:49:07 +02:00
Simon Hausmann
8ffb5131c7
Introduce error handling in the FemtoVG and Skia renderers (#2402)
Avoid unwrap() and expect() and instead propagate errors all the way
down to run_event_loop(), show(), and hide() in the Slint AIP.
2023-03-24 14:18:11 +01:00
Simon Hausmann
00471449b4 Fix compilation of Rust generated code when the generated code uses a return statement inside a block
We cast the result of the body of functions or binding expressions to
the target type via `as _`. When the code contains a return expression,
that works fine, because `return`'s type is the never type, which can be
coerced to a value of any type. However when the return statement is
inside a sub-block, the type becomes `()`, for which the `as _` cast
fails.

Work around this by attempting to detect the situation (return produces
Type::Invalid) and omit the trailing cast.
2023-03-22 18:07:34 +01:00
Olivier Goffart
4cf44ea69d Mark StandardListViewItem and TableColumn as #[non_exhaustive]
Closes #2330
2023-03-18 09:04:48 +01:00
Tobias Hunger
3d87b3ab93 clippy: Allow redundant_clone in generated rust code
This disabled about 70 clippy warnings like this one:

```
warning: redundant clone
     --> target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:44279:37
      |
44279 |                      (if (((r#state . clone ()) . r#previous_state as f64) == (1f64 as f64)) {
      |                                     ^^^^^^^^^^^ help: remove this
      |
note: cloned value is neither consumed nor mutated
     --> target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:44279:28
      |
44279 |                      (if (((r#state . clone ()) . r#previous_state as f64) == (1f64 as f64)) {
      |                            ^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
```
2023-03-09 12:12:03 +01:00
Tobias Hunger
d1aaba8117 clippy: redundant clone fix in generated rust code
This fixes about half the `redundant clone` issues that clippy reports
in our generated rust code.
2023-03-09 12:12:03 +01:00
Tobias Hunger
0b03a0646a clippy: Allow cmp_owned in generated rust code 2023-03-09 12:12:03 +01:00
Tobias Hunger
7c19cde055 clippy: Allow eq_op in generated rust code
I get the following clippy errors in the energy monitor:

error: equal expressions as operands to `-`
     --> C:\src\slint\target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:47254:94
      |
47254 | ...   (slint :: private_unstable_api :: re_exports :: LogicalLength :: new (((((0f64 as f64) - (0f64 as f64)) as f64) * (((1f64 as f64) *...
      |                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

error: equal expressions as operands to `==`
     --> C:\src\slint\target\debug\build\energy-monitor-7b0492feb1633656\out\desktop_window.rs:45382:18
      |
45382 |                  (((0f64 as f64) == (0f64 as f64))) as bool }
      |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

I am not surprised that the generated code sometimes produces code like
this (even though the other demos do not!), so I went ahead and silenced
these errors.
2023-03-09 12:12:03 +01:00
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +01:00
Olivier Goffart
6889dfa5f5 Rust: Make new(), run() and show() report errors from the backend
Fixes #2198
2023-02-10 05:00:03 +01:00
Olivier Goffart
11d404a216 Rust: Avoid use statement in the generated code
So we avoid name conflict between user types and internal types

Fixes #2207
2023-02-08 18:34:52 +01:00
Olivier Goffart
b55ec6894a Layouting: forward the implicit constraint from the children to the parent
Closes #783
2023-01-17 16:29:13 +01:00
Simon Hausmann
96c80a2dd1
Fix crash when using an int model in a repeater with a negative value (#2063)
Make sure that we return an unsigned for row_count() in C++ and Rust by ensuring an unsigned int model at creation time.

For the interpreter this "worked" by chance as casting a negative floating
number to usize automatically caps at zero, and all values are stored as f64. For safety this patch
applies the same fix though, to be on the safe side.
2023-01-14 21:20:14 +01:00
Olivier Goffart
1ab228c628 Implement calling public functions from native code
This doesn't implement any support for the interpreter yet

CC: #2012
2022-12-22 04:28:32 -08:00
Olivier Goffart
af50c2c2c2 Do not panic if the document contains a global but no normal component
Fixes #2005

(Unfortunately, we can't make a driver test for this becasue the
behavior with the interpreter is different than with the compilers.
The interpreter errors out, while the compiler should just generate
nothing)
2022-12-19 11:54:15 -08:00