Commit graph

463 commits

Author SHA1 Message Date
Simon Hausmann
8ff27671ef Fix absolute item index computation for children of nested sub-components
Somehow the focus_change_subcompo test missed this case and the visible
issue of this off-by-one was that
the combo boxes in the printer demo's settings page opened at the wrong location (wrong parent).
2021-11-09 14:52:47 +01:00
Olivier Goffart
92998a76aa Rust: Don't mark the window as pub
No reason to have it public
2021-11-09 13:48:22 +01:00
Simon Hausmann
f10f05c726 Fix set_focus_item and show_popup_window calls from within sub-components in Rust
Compute the absolute item index like in the C++ generator.
2021-11-09 11:50:36 +01:00
Simon Hausmann
270f8145ff Don't call set_focus_item in the init function of sub-components
We use the setup_code for that for now, so apply the same logic as in the C++ generator.

However there's more work to be done later to make forward-focus work corectly into sub-components.
2021-11-09 11:49:51 +01:00
Simon Hausmann
3e02c7090c Minor cleanup
Qualify the Default trait also for the root field
2021-11-09 11:09:56 +01:00
Simon Hausmann
b0d76d1bcc Fix dyn_index dispatch to sub-components in Rust
Correctly make the dyn_index a local index by subtracting the base
2021-11-09 10:46:48 +01:00
Simon Hausmann
f7415171d0 Fix generated Rust code when using sub-components in nested repeaters
The code to determine the root is a little more complex, as unlike in C++
we are not passing the root on in constructors.
2021-11-09 10:40:51 +01:00
Simon Hausmann
1055b39c68 Fix calls to ItemRc that take a VRc, when called from sub-components
There are different ways to get the VRc.
2021-11-08 16:53:24 +01:00
Olivier Goffart
a6a8f232db Fix error in generated code:
```
error[E0599]: no method named `unwrap` found for struct `sixtyfps::re_exports::OnceCell` in the current scope
   --> .../test-driver-rust-0868c471dd25beed/out/imports_external_type.rs:384:29
    |
384 |                 &_self.root.unwrap().upgrade(),
    |                             ^^^^^^ method not found in `sixtyfps::re_exports::OnceCell<VWeak<sixtyfps::re_exports::ComponentVTable, imports_external_type::sixtyfps_generated_TestCase::InnerTestCase>>`
```
2021-11-08 16:41:45 +01:00
Simon Hausmann
e9a7be2f62 Fix compilation of init() calls to sub-components that are instantiated in repeaters
The path to get the root differs depending on where we are.
2021-11-08 16:29:34 +01:00
Simon Hausmann
8f2a7edbee Add support for callback aliases in Rust sub-components 2021-11-08 16:09:20 +01:00
Simon Hausmann
f693b434f4 Fix warning about unused imports in repeated elements of sub-components in Rust 2021-11-08 16:09:20 +01:00
Simon Hausmann
4ba6260a47 Add support for repeaters in Rust sub-components
* Generate a visit_dynamic_children dispatch function in sub-components and call it
* Add a self_weak to sub-components
* Fix access to the window from within repeated components
* Fix the parent type of repeated elements within sub-components to be a VWeakMapped instead of VWeak
* Fix the build of the parent_item() implementation of repeated elements within sub-comps. The parent index might still be wrong, needs to be checked.
2021-11-08 15:11:05 +01:00
Simon Hausmann
735a7eef82 Fix access to two-way bindings resolved to aliases in sub-components
We generate a getter that hides the renaming. Instead of returning a field offset, we
might as well use the same code as for the value getter
and return a `Pin<&Property<T>>`.

What doesn't work yet are aliases to globals, because that
uses a temporary.
2021-11-08 13:25:13 +01:00
Simon Hausmann
13de800ba3 Internal cleanup: Rename layouting_info to layout_info
That's making the call on the Component VTable consistent(ish) with the Item VTable.
2021-11-08 10:24:30 +01:00
Simon Hausmann
ca29d3ea66 Make it possible to use Text as a sub-component base type
At the use-size a binding for width and height is created that
uses the layout info. So that function needs to be emitted for sub-components,
and access to the window needs to be provided as well.

There's cleanup for later, which is unifying the name (layout vs layouting)
and shortening the signature for
sub-component calls (no need for the window parameter).
2021-11-07 13:28:35 +01:00
Simon Hausmann
add44d2be0 Fix accessing the global from sub-components in Rust
Add a root vweak to each sub-compoment and use it to route access to the globals.
2021-11-05 17:26:18 +01:00
Simon Hausmann
f708a4a32a Rust: Add support for custom properties in sub-components
Declare a const getter function that retrieves the field offset and call it from access_member.

Right now the indirection through
the function is not needed, but
it will be necessary when supporting aliases.
2021-11-05 13:43:50 +01:00
Olivier Goffart
9401bfbec7 Rust test driver: Add a feature to generate the rust code in build.rs
instead of in the sixtyfps! macro, so se actually see where the error is in
the generated code.

This also expose a bunch of warning that were not being taken care on.
2021-11-05 11:35:56 +01:00
Simon Hausmann
2cdb9d8d82 Fix accessing properties of builtin items through a sub-component chain in Rust 2021-11-05 11:21:44 +01:00
Simon Hausmann
6a53640b03 Fix calling init on nested sub-components
Call VRcMapped::map instead of VRc::map when the type of self_rc is not a VRc anymore.
2021-11-05 11:21:18 +01:00
Simon Hausmann
5fa4bc6b70 Generate an init function for sub-components
This allows something like this:

```
SubCompo := Rectangle {
    background: green;
}
App := Window {
    SubCompo {}
}
```
2021-11-05 10:20:54 +01:00
Simon Hausmann
f70d6c6f17 Add skeleton for sub-component use in the Rust generator
* For sub-components create a super-primitive struct with just its fields
  and a new() function to create it. There's no init() function yet.
* Provide access to the root item of the sub-component

This just makes the most trivial example work:

```
SubComp := Rectangle {}

App := Window {
    SubComp {
        background: green;
    }
}
```
2021-11-04 19:50:53 +01:00
Simon Hausmann
7354b17a6a Minor cleanup in ItemTreeBuilder trait
Pass the sub-component as a parameter in enter_component(), as it's needed in the C++
implementation, it's readily available (no need to unwrap again) and Rust will need it, too.
2021-11-04 17:55:39 +01:00
Simon Hausmann
75959f4e4f Prepare for emitting Rust code for sub-components
Call generate_component like in the C++ generator. This will trigger `todo!()` :)
2021-11-04 16:06:17 +01:00
Simon Hausmann
1d7e3f07a8 Fold handle_repeater into the TreeBuilder to reduce the number of parameters 2021-11-04 15:57:55 +01:00
Olivier Goffart
7472b80094 Rust: use the new build_tree_item 2021-11-04 15:42:48 +01:00
Simon Hausmann
88293151b1 Remove unused variable in the Rust code generator 2021-11-03 11:49:18 +01:00
Simon Hausmann
14cb0520a9 Fix drop implementation of Rust generated code
Call free_graphics_resources, not init_items %-)

Amends commit 67579ec560
2021-11-01 18:50:33 +01:00
Simon Hausmann
67579ec560 Simplify drop implementation of generated components
Avoid creating an intermediate array of items to free the graphics resources.
Instead call run-time function with the item tree as a parameter, which is traversed.

It's practically the same data structure that was previously created, except
that it is shared/global and has little holes for the dynamic tree items, but those are easy to skip.
2021-11-01 08:58:53 +01:00
Simon Hausmann
d57edfbb7c Simplify free_graphics_resources API in the backend
Take an iterator reference instead of a slice, so that we can change the call sites in the future.
2021-10-30 13:03:52 +02:00
Olivier Goffart
567c644a5f Fix PopupWindow position when all elements are not inlined
Pass a reference to the parent item in the show_popup function
so we can compute the exact location at runtime.
2021-10-28 15:52:29 +02:00
Simon Hausmann
63bf1af093 Add support for tracking the length of a model in Rust
This is done by exposing the ModelNotify to the caller via the new
ModelTracker trait, which has a function that allows "hooking" into the
dirty tracking of the size.

By extension, this also works in JavaScript.

cc #98
2021-10-20 15:25:28 +02:00
James Blacklock
ab665ba7b6 enable scripts to access the length of arrays 2021-10-18 10:21:06 +02:00
Olivier Goffart
bb4e5d8b55 Fix animation not starting when set from a callback
Two problems:
 - We were not marking the property as dirty, so dependent property would not
   update themselves
 - In the generated rust/c++ code, we would not call set_animated_value
2021-10-13 14:33:40 +02:00
Olivier Goffart
89c43bcd36 Workaround a rust-analyzer parse error in the generated code
Workaround for https://github.com/rust-analyzer/rust-analyzer/issues/10492
2021-10-12 21:13:07 +02:00
Simon Hausmann
88ad176008 Improve diagnostics when images cannot be located for embedding
This is a two-stage change, that first centralizes the file I/O code
path for on-disk and builtin:/ files. Secondly the resource embedding
pass now produces diagnostics if a file cannot be located.
2021-10-05 23:16:46 +02:00
Simon Hausmann
4b267a8e9b Internal cleanup: Simplify string handling when accessing compiler-embedded files
For loading images that are included in the widget library that's included in turn
in the compiler binary, we need to create ImageInner::EmbeddedData
with &'static data and &'static file extension. The latter was
created using string interning, but we can also access the path of the
widget library data structure.
2021-10-05 23:16:46 +02:00
Simon Hausmann
4a26faef9a Add AboutSixtyFPS element 2021-10-05 23:16:46 +02:00
Olivier Goffart
7f05bfa309 Add the Dialog element 2021-09-29 16:25:44 +02:00
Olivier Goffart
fafcbfde2c Fix panic when trying to access layout cache of destroyed items
This can be reproduced by deleting the last item of the printer queue in the
printer demo.
It is a regression showing up because we now emit the MouseExit event after
the mouse grab as released.
The problem is that we upgrade the weak item, and call geometry() on it.
Calling geometry will re-evaluate the layout cache which will re-evaluate
the model which will result in the component being removed and the cache
entry having less item than expected.

It is ok to simply return 0. for these layout location since the item will
disapear anyway.
2021-09-08 14:42:08 +02:00
Simon Hausmann
ee8e5699e5 Clean up global alias handling
Remove the internal name again and pick the first exported one when
assigning ids. This avoids internal names showing up in code completion
or the internal types leaking into generated code.
2021-08-31 17:09:11 +02:00
Simon Hausmann
0d19e2d9b9 Add support for global aliases
When exporting an global multiple times under different names, make sure
that they alias in the generated code.

As a consequence, the compiler maintains the original unique name and in
Rust and C++ makes only the exported names public. In the interpreter
the internal name is theoretically still accessible from the outside.
2021-08-31 17:09:11 +02:00
Olivier Goffart
fe94f93755 Test the use of global callback from rust and C++ 2021-08-27 13:56:54 +02:00
Simon Hausmann
cf7d33fb5d Add support for accessing exported globals from Rust 2021-08-27 13:36:48 +02:00
Simon Hausmann
9868b693e2 Only publish exported globals in C++ and Rust 2021-08-27 13:36:48 +02:00
Simon Hausmann
c5d2ac2dd3 Rust codegen: Generate structures with public acccessors for global structs
It's not possible to create these from Rust code (intentional) and the
accessor to reach the instances are not implemented yet.
2021-08-27 13:36:48 +02:00
Olivier Goffart
b07d52cd23 Support aliases to callbacks in globals 2021-08-24 12:36:16 +02:00
Olivier Goffart
b42c187ed1 Refactor the way the two-ways biding are represented internaly
Don't put them in a fake expression.
This simplifies a bit the expression handling, and will make
possible to fix analysis that needs a vew into the aliases
2021-08-20 18:26:36 +02:00
Simon Hausmann
2458ac5d02 Fix panic when calling focus() on a repeated element
When trying to reference an instance of a repeated item, for use with
ItemRc or VRef<Item>, the item_index (or id) of the ElementRc is not
directly what we want.

Adjust any element references to the repeater to to the inner instance
after creating them. Also make sure that the enclosing component is
respected in the C++ and Rust generators.

Fixes #422
2021-08-20 15:39:54 +02:00