Commit graph

5126 commits

Author SHA1 Message Date
Olivier Goffart
aea68b9ad8 C++: Fix subcomponents/nested_repeater.60 when not inlining
More or less the same fix as what was done in rust when the test was added
2021-11-09 12:40:04 +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
Olivier Goffart
a5e1f35f7b Make sure that the BindingExpression with animation always has a binding
Consider this code:
```60
Foo := Rectangle {
   animate y { /*...*/ }
   x: some_binding;
}

Bar := Rectangle {
   foo_instance := Foo {
      y: some_binding;
      animate x { /*...*/ }
   }
}
```
We need to make sure that the binding are set with the right animation.

FIXME: the generator should actually handle this case without needing for inlining.
Also, this currently do not work if there is several level of "inheritence"
2021-11-09 10:22:11 +01:00
Olivier Goffart
f6cf8b6d47 Check the analysys of the base component
If there is a Expression::Invalid as a binding (because it has an animation,
for example) we must check that the binding expression in the base is not
constant.

This fixes the rust test `properties_animation_merging` without inlining
(The o4_val was considered constant despite it shouldn't be)
2021-11-08 20:03:26 +01:00
Olivier Goffart
d97fe873ec Fix the FieldOffsets derive macro on non pub struct
When the struct expose as public a private type
2021-11-08 19:01:29 +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
a3bafb59f0 Don't mark the internal components as pub 2021-11-08 16:46:13 +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
Olivier Goffart
28c485c161 Handle the tab key in the Qt backend
Completes #639
2021-11-08 16:16:56 +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
Philipp Gesang
cd3717af9a handle tab keycode in backend
Treating the Tab key as text disallows handling Shift-Tab because
the shift modifier will not be passed down. This makes the
handling of Tab analogous to Escape, Return and other non-text
keycodes.
2021-11-08 16:04:37 +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
94b19d3df9 Add VRcMapped::origin() 2021-11-08 13:41:52 +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
861f2e4153 Prospective fix for spurious pipenv errors in the CI
As seen in 4116878357, we
sometimes get pipenv errors:

(truncated backtrace):
```
      File "/usr/local/lib/python3.8/dist-packages/pipenv/patched/notpip/_vendor/certifi/core.py", line 51, in where 64
        _CACERT_PATH = str(_CACERT_CTX.__enter__()) 65
      File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__ 66
        return next(self.gen) 67
      File "/usr/lib/python3.8/importlib/resources.py", line 184, in path 68
        package = _get_package(package) 69
      File "/usr/lib/python3.8/importlib/resources.py", line 47, in _get_package 70
        module = import_module(package) 71
      File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module 72
        return _bootstrap._gcd_import(name[level:], package, level) 73
    ModuleNotFoundError: No module named 'pip._vendor.certifi'
````

Previously we installed pip/pipenv via sudo install pipenv (via the GH
action). Doing a manual pip upgrade and user installation of pipenv
appears to not produce this error.
2021-11-05 14:31:01 +01:00
Simon Hausmann
7d04ba98b1 Document MSRV in the crate README
This way it appears on crates.io

cc #622
2021-11-05 13:54:58 +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
Simon Hausmann
6346a55fdd Check the Rust version when using corrosion
Let cmake perform the version check. FindRust.cmake already uses VERSION_VAR
and therefore is versioned.

cc #622
2021-11-05 13:07:36 +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
0eb210933e Fix itreem tree offsets of children of chained sub-components
Similar to commit 4eb161b83f this works in C++
by accident but for Rust to compile we need to advance the sub-component
state in the tree builder.
2021-11-05 11:34:41 +01:00
Simon Hausmann
a4c5d3d9aa Fix build of bindings in sub-components in Rust
Implement the StrongComponentRef trait for VRcMapped so that the calls to set_property_binding
compile.
2021-11-05 11:29:59 +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
5af91a133e Fix compilation when trying to clone VRcMappend and VWeakMapped
A #[derive(Clone)] imposes Clone on the VTable type, which
doesn't make sense here.
2021-11-05 11:17:55 +01:00
Simon Hausmann
4eb161b83f Fix item tree offsets for chained sub-components
When we have

```
S1 := Rectangle {}
S2 := S1 {}
App := Window {
    S2 {}
}
```

Then the right path to the rectangle is

    offsetof(App, s2) + offsetof(S2, root) + offset(S1, rectangle)

The middle one was left out in C++, where it also probably doesn't matter
because the root is the first member (although it might not always remain that way).

In Rust the FieldOffset type generated won't allow for adding
together without the middle one.

Therefore visit_item() in the generator is changed to bring forward the sub-component
state when following the chain.
2021-11-05 11:04:30 +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
Olivier Goffart
c506e87484 Add VRcMapped::map 2021-11-05 09:50:58 +01:00
Simon Hausmann
2b70e28d54 Move VRcMapped::map to VRc::map
This makes the functionality easier to discover and seems more consistent.
2021-11-04 19:59:04 +01:00
Olivier Goffart
3cdd830417 Bump vtable version 2021-11-04 19:57:52 +01:00
Simon Hausmann
183ff6586b Add VrcMapped and VWeakMapped to allow for references to objects that are reachable via VRc
For now this requires pinning on the type contained in VRc as well as
the fields mapped to. This could be lifted using additional flags, but
for now this is what we need anyway.
2021-11-04 19:57:36 +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
Olivier Goffart
6df78893d6 Use build_item_tree in dynamic_component 2021-11-04 16:40:48 +01:00
Simon Hausmann
ac945a8f37 Minor cleanup in C++ code generator
In the tree builder's enter_component we registered the sub-component as a member
and also registered the member initializer
in the constructor.

However the call to `init()` to initialize the bindings was registered in `enter_component_children` for no good reason.

It's cleaner to do that all in one place.
2021-11-04 16:27:35 +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
2b98e503f1 Fix build by adding missing Write trait use 2021-11-04 11:03:44 +01:00
Simon Hausmann
6528963bd2 Simplify and speed up string concatenation by using write!()
Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-11-04 11:03:44 +01:00
Simon Hausmann
d447cd155d Fix missing repeaters in item tree with chained sub-components
The parent commit surfaced this issue, as we now rely on visiting all repeaters
in the build_item_tree call.
2021-11-04 11:03:44 +01:00
Simon Hausmann
e0f3e6b782 Fix the C++ printer demo with disabled inline
For the following reduced test-case the order in how the dynamic nodes
in the item tree were generated (and dyn indices assigned) differed from
the way the visit_dynamic_children slots were generated:

```
Blah := Rectangle {
    for x in 1: Text {
        text: "Should be on the right";
    }
}

MainWindow := Window {
    width: 772px;
    height: 504px;
    Text {
        if (false): TouchArea {
        }
    }
    Blah {
        x: 200px;
    }
}
```

The item tree node was constructed using build_item_tree, which
basically assigned dyn index 0 to the "repater" for the touch area
and "1" to the one for the repeater inside the sub-component.

Afterwards we traversed the element tree - without descending into the
sub-components - to generate the fields and the dispatch in in the
dynamic visitor. Here a subtle order would result in a mismatch of
indices:

recurse_elem_level_order would end up visiting Text, Blah and then
Text's children, assigning the first dynamic index to Blah.

This is now fixed by merging the two iterations into one.
2021-11-04 11:03:44 +01:00