Commit graph

90 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Simon Hausmann
262c96af8c Simplify receiver for WindowInner
Use &self consistently, instead of Rc<Self>, so that in the future we can
replace Window(Rc<WindowInner>) with Window(WindowInner).
2022-08-19 15:07:27 +02:00
Simon Hausmann
ef5377baea Fix the image cache with rust generated code and debug builds
We use `const` for the embedded data, which doesn't guarantee a fixed location in memory.

For the image cache when embedding (encoded) image data, we rely on a fixed address.

I observed that in debug builds of the slide puzzle, the embedded data is not always
reported to be at the same address, presumably due to inlining. This makes
the theme switching a bit slower and the cache less efficient.

This patch fixes that by using static instead of const, to guarantee a fixed location in memory.

(This was not observed in release builds, but in theory it could happen there as well?)
2022-08-17 09:43:33 +02:00
Olivier Goffart
8c70cd7f57
Move the fonts out of the Backend trait (#1438)
and remove the `'static`
2022-07-26 16:45:54 +02:00
Olivier Goffart
29404e3f2c Rename i_slint_core:🪟:Window into WindowInner
We already have `api::Window` and also the Window element (`WindowItem`),
So rename the inner part to avoid confusion
2022-07-22 18:12:00 +02:00
Olivier Goffart
ac4f3e97ad Change slint enum values to be PascalCase in rust
... while still being kebab-case in .slint

Some enums might become public API and we want to have them as
PascalCase to respect the rust conventions
2022-07-22 12:23:52 +02:00
Olivier Goffart
c404194a8d Cleanup an unwanted impl From on Image 2022-07-20 12:57:37 +02:00
Olivier Goffart
65346c699c Attempt to get the "image-in-corelib" feature compile with C++ 2022-07-20 12:57:37 +02:00
Simon Hausmann
67a2f0ce3f WIP: Make image decoding a feature of the core library
This includes the cache of decoded images, the HTMLImage element support
and the SVG rendering adapter.

The objective is that Image holds an ImageInner, which is not a path
anymore that the backend has to process, but instead always either
decoded image data, a pointer to a static texture or an SVG tree that
can be rendered to the desired size.
2022-07-20 12:57:37 +02:00
Olivier Goffart
30f95e3aca Fix animation-tick() to register that there are running animation 2022-07-12 17:36:04 +02:00
Olivier Goffart
92b4f52556 Make mod() a macro that can take generic types instead of just integer 2022-07-11 17:49:28 +02:00
Olivier Goffart
d48c590346 Add animation-tick() builtin function
Low level primitive allowing to build always running animations
2022-07-11 17:49:28 +02:00
Olivier Goffart
1fac9b7ad0 Do the initialization in the same order in C++ and rust
First the parent component, then the properties.
2022-07-08 19:05:54 +02:00
Tobias Hunger
dd59d41ee6 Rename init_*_items to register_component
I want to track component structure changes in the window without
generating more code. So use a more generic name for the init_*_items
functions, so that I can add the functionality I need in there.

Also add a register_component to PlatformWindow and call that.
2022-06-30 11:51:49 +02:00
Tobias Hunger
581533f302 Rename free_*_graphics_resources to unregister_component
I want a more generic name as I want to do to track component structure
changes in addition to resource freeing and I do not want to add another
call into the generated code.
2022-06-30 11:51:49 +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
Olivier Goffart
00583ade05 Add env variable to put data into a different section
This also makes sixtyfps::Slice Send and Sync
2022-06-18 20:00:21 +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
Simon Hausmann
f0c14bea54 Fix memory leak with repeated elements in generated Rust code
The generated code provides a PinnedDrop implementation that calls
free_component_item_graphics_resources. We must annotate the components
correctly to make sure to the drop implementation is called and graphics
resources are released.

Thanks to Jocelyn!

Fixes #1261
2022-06-08 15:56:47 +02:00
Olivier Goffart
fa6be65a04 Revert "Rename the free_graphics_resources to component_destroyed"
This reverts commit 1b9fee96c16f7a660ed2c14bb3287fceedc72ba7.

The MCU backend still need the array of item, so it's too realy for this change
2022-05-31 10:48:24 +02:00
Olivier Goffart
ad2d19165a Rename the free_graphics_resources to component_destroyed
And do not iterate over the items anymore
2022-05-31 10:48:24 +02:00
Olivier Goffart
615c7635ee Qt: use a HashMap for the cache
And not the cache dirrectly within the item, because it is already in use
for the partial rendering
2022-05-31 10:48:24 +02:00
Lukas Jung
2c416670e5
Add support for the log crate (#1283) 2022-05-27 13:30:11 +02:00
Tobias Hunger
9b535e8ee8 janitor: use matches! 2022-05-22 11:59:00 +02:00
Tobias Hunger
a71848fd2c janitor: Avoid some allocations warned about by clippy 2022-05-22 11:59:00 +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
8f16585754 Rust generation: properly clone() local variable
In case we re-use a non copy type several time in an expression
2022-05-13 13:00:01 +02:00
Olivier Goffart
c8e3a05116 Fix C++ compilation when writing to the model data from a sub component 2022-05-13 13:00:01 +02:00
Olivier Goffart
525e9982d8 Re-export and document ModelExt 2022-05-04 11:08:14 +02:00
Tobias Hunger
416aa42d90 Component: Replace parent_item to parent_node
Remove the `parent_item` function. After the recent changes that did not
return an item anymore and since the item tree is exposed, this function
was only used to find the repeater a component was created by.

So replace the old function with a new one that only returns the parent
node in the parent component.

This saves a few lines of generated code that is not used anymore.

Co-authored-by: Simon Hausmann <hausmann@gmail.com>
2022-04-20 14:29:18 +02:00
Olivier Goffart
67e9a59398 Add a Model::row_data_tracked function
Closes #1177
2022-04-19 15:12:15 +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
Olivier Goffart
1b91158b46 corelib: allow to use i32 for coordinate instead of f32 2022-04-11 17:46:50 +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
Tobias Hunger
072a6fd5e4 Update internal/compiler/generator/cpp.rs
Co-authored-by: Olivier Goffart <olivier@woboq.com>
2022-03-31 17:43:57 +02:00
Tobias Hunger
e05d24b2cf c++: Implement subtree_index(...) 2022-03-31 17:43:57 +02:00
Tobias Hunger
1888ecfd65 c++: Generate better indices for the parent node of repeaters 2022-03-31 14:40:57 +02:00