Commit graph

65 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
1888ecfd65 c++: Generate better indices for the parent node of repeaters 2022-03-31 14:40:57 +02:00
Tobias Hunger
8a036ef293 rust: Generate better indices for the parent node of repeaters
Co-authored-by: Simon Hausmann <simon.hausmann@slint-ui.com>
2022-03-31 14:40:57 +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
Tobias Hunger
ee68716d07 Component: Add information to stich together ItemTrees
Add accessors to the information necessary to stitch together the
Component-wide ItemTrees (which include DynamicNodes) into one logical
tree of Items.
2022-03-28 14:13:36 +02:00
Tobias Hunger
0c952ddee7 rust: Simplify item_tree() method by making the tree const 2022-03-21 19:21:57 +01:00
Tobias Hunger
ea684fa4de Add item_tree function to Component VTable 2022-03-14 17:19:31 +01:00
Tobias Hunger
bdc3778cec Rename init/free item functions back 2022-03-14 09:43:50 +01:00
Tobias Hunger
095537e3fd Remove item from ItemTreeNode
... and make ItemTreeNode non-generic this way.

The Item is now only in the extra ItemArray struct and we are free to
expose the ItemTree further.
2022-03-14 09:43:50 +01:00
Tobias Hunger
6681545aca Use item_array in rust 2022-03-14 09:43:50 +01:00
Tobias Hunger
b95342551b Add index into item_array into ItemTreeNode 2022-03-14 09:43:50 +01:00
Simon Hausmann
f1dae75d53 Fix interpreter ffi build
Commit 738ac0dc01 increased the size of the ImageInner::StaticTextures variant,
which breaks the size assertions in the interpreter ffi build.

This changes fixes that by reducing the size of the ImageInner variant again by
moving all the fields into a separate struct.
2022-03-03 14:04:45 +01:00
Simon Hausmann
738ac0dc01 mcu: scale images at compile time (#966)
Apply a scale factor to reduce the size of embedded images at compile
time.
2022-03-03 13:28:47 +01:00
Olivier Goffart
0dc188f328 Support for referring to other globals from globals
- We need to make sure that the initialization of global is in the right order.
 - In C++ and rust, we need to add accessor to the global component
 - There can be `PropertyReference::Global` in binding of globals
 - The interpreter globals need to hold references to the global they may depend on

Fixes #175
2022-02-28 10:14:34 +01:00
Olivier Goffart
c941946f49 Debug: make sure that more properties have debug_name
The global properties, and base properties were not named

This adds a Property::new_named regardless if debug is enabled or not
2022-02-18 17:40:17 +01:00
Olivier Goffart
d70a304e2b fix slint_debug_property cfg build 2022-02-18 12:24:35 +01:00
Olivier Goffart
a32eee64a7 Count the uses of property, and do not generate properties that are not used 2022-02-17 16:25:48 +01:00
Olivier Goffart
85e88eb3d6 Silent warning in the generated code.
Inlining may cause global to become unused.
In a perfect world, We should remove the global completely instead, but
that will be for a followup patch
2022-02-16 18:46:37 +01:00
Olivier Goffart
068a7a51b5 Rust generator: Fix type conversion when creating a Point
Before it used to always be a property access, but now it may be inlined
and result in a f64 or int expression
2022-02-16 18:46:37 +01:00