Commit graph

509 commits

Author SHA1 Message Date
Olivier Goffart
7ecbf4c81d Don't use deprecated itertools functions
A replacement is available in the std library
2021-12-07 12:10:38 +01:00
Olivier Goffart
524a9be377 Mark properies being set by the ListView and FLickable as set externally
As we will do more optimisation on constant properties, it is important
to detect the ones that aren't
2021-12-04 22:00:12 +01:00
Olivier Goffart
bc8d556799 Compiler: keep const-ness information of native property in the NativeClass 2021-12-04 22:00:12 +01:00
Olivier Goffart
3534f3bd4c Disable texture embedding with wasm
We can't support it with the interpreter, and the compiler running on wasm
is only used for the interpreter.
And this cause compilation issue because some dependencies enable features
that breaks the build
2021-11-19 15:54:45 +01:00
Olivier Goffart
d1cae710df preprocess the images at compile time
For the MCU port, we need to proccess the image to save them in the binary
in a convenient format.
This patch start this work by trying to anaylyze what format should an image
be using, and saving it as a texture in the binary.

The current graphical backend and the C++ frontend are not yet supported
2021-11-19 15:54:45 +01:00
Olivier Goffart
de43f0a783 Start doing some constant evaluation
There was a warning in the C++ generated code in the tests:  (in test_cpp_image_geometry)

```
/tmp/.tmpsAMWqZ.cpp:307:85: error: self-comparison always evaluates to true [-Werror,-Wtautological-compare]
    this->image_in_layout_fit_ok.set((sixtyfps::cbindgen_private::ImageFit::contain == sixtyfps::cbindgen_private::ImageFit::contain));
                                                                                    ^
```

Deoing some simple evaluation prevent this warning at least
2021-11-11 11:14:59 +01:00
Olivier Goffart
4360dc2010 Fix const detection with declared aliases 2021-11-11 11:14:59 +01:00
Olivier Goffart
a3adfd94b1 Const propagation
Inline access to constant properties
2021-11-11 11:14:59 +01:00
Olivier Goffart
125ab12816 Don't take the binding when calling visit_element_expressions
So that we can visit the expression and the property reference
still have a meaning
2021-11-11 11:14:59 +01:00
Olivier Goffart
dd3fa1c221 Make the BindingMap hold RefCell of the BindingExpression
This will allow later to be able to operate on the binding despite the
element is borrowed.

Since the Binding itself is in a RefCell, the analysis don't need to
be anymore.
To do this change, a small change in the binding_analysis logic was required
which means that we will now detect binding loop if a binding was causing
two binding loop. (before, only one binding loop was detected)
2021-11-11 11:14:59 +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
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
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
Olivier Goffart
2f1f697e08 Fix the tests after the last commit
Since we add a window earlier in the pass, the warning was no more shown

Also don't add a window in front of a PopupWindow
2021-11-04 10:23:56 +01:00
Olivier Goffart
f316c38d54 Do the apply_default_properties_from_style before the lower_states pass
because we don't want the lowered state property to look like we set a property on it.

Also do the ensure_window before because it need to be done before to be assigned
the default color
2021-11-04 10:08:30 +01:00
Olivier Goffart
d438374792 Refactor the build_item_tree
Use a trait instead of two functions
2021-11-03 17:46:48 +01:00
Olivier Goffart
025b34e8e3 Fix wrong analysis leading to wrong optimization
We need to mark property as set externally before propagating
the is_set on aliases

Fixes test_cpp_bindings_two_way_model without inlining
2021-11-03 13:13:53 +01:00
Olivier Goffart
114137ddfa Make sure to mark declared aliases as set
Fix the dialog test when not inlining, because it declared all these
xxx-clicked aliases and if we don't propagate their usage, they will be
optimized away
2021-11-03 09:55:04 +01:00
Simon Hausmann
da169b0e3c Fix calling focus() in sub-components when inlining is disabled
focus() is implemented by calling set_focus() on the window with the absolute item
index as a parameter. The
generate_item_indices pass generates local item indicies,
which need to made absolute.

Sadly there exists a gap in the item tree between the root element of a sub-component
and its children. Therefore each sub-component gets two members passed to the constructor,
the tree_index and tree_index_of_first_child.
The former is to be used when the local index is zero (indicates the root).
The latter is used as base for any children.
2021-11-03 09:45:35 +01:00
Simon Hausmann
bd971eda25 Fix local item indicies when using sub-components before other children
In a tree like this:

```
SubCompo := Rectangle { Image {} }
MainCompo := Window {
    TouchArea {}
    SubCompo {}
    Text {
        Path {}
    }
}
```

The path element would have a local item index of 4, which is wrong. Right before the path
there would be the child(ren) of the sub-component, which
were not accounted for.
2021-11-03 08:27:49 +01:00
Olivier Goffart
3a27a18188 Fix detection of is_set_externally
Otherwise aliases can be optimized when they shouldn't
2021-11-02 11:14:20 +01:00
Olivier Goffart
e6d1f91948 The binding analysis also need to go in callback to detect usages 2021-11-02 10:35:42 +01:00
Olivier Goffart
e13263e760 Prefer keeping the global property when there is an alias to a global
That's because the global must stay in case it is used by more components

(That's a better fix than the one reverted in the previous commit)
2021-11-02 10:25:55 +01:00
Olivier Goffart
fa73833cc1 Revert "Aliases in global can no longer be optimized"
This reverts commit b4a2d0a902.

That was not the correct fix, because we need that for
aliases to global callbacks (these can't be actual two way binding
at runtime)
2021-11-02 10:08:21 +01:00
Olivier Goffart
b4a2d0a902 Aliases in global can no longer be optimized
Because they can be used by other components
2021-11-02 09:46:41 +01:00
Olivier Goffart
ab772828e9 Don't try to keep the used_component while doing the inline pass
Because some Component might be inlined, and some other not.
Instead, just call the collect_subcomponents pass.
2021-11-01 13:47:09 +01:00
Simon Hausmann
4316e1baac Fix asserts in item tree generator when using sub-components
There's a check that verifies that the relative item indices match, between what
the item tree building code in the generator sees and the generate_item_indices pass.

The counting of the relative indices was incorrect with regards to the sub-trees.
2021-11-01 13:40:08 +01:00
Simon Hausmann
3987eafa5a Fix child count in item tree when using sub-components
Inline sub-components that are used along with children, similar to @children. This way
we don't need to jump through hoops for the correct children
count in the item tree (or their placement/offset).
2021-10-28 15:52:29 +02:00
Simon Hausmann
cebb415b08 Replace two uses of build_array_helper with a new recurse_elem variant
For the item index generation and the member population for the C++
structs, a level-order variant of `recurse_elem` is sufficient - as also
indicate by the unused item index parameters.
2021-10-28 15:52:29 +02:00
Olivier Goffart
5af4e827a2 Properly visit more binding and keep analysis
This fix a bunch of test broken by the previous commit
2021-10-28 15:52:29 +02:00
Olivier Goffart
f833c944de Make sure we do not optimize away properties used from other components 2021-10-28 15:52:29 +02:00
Olivier Goffart
c823b41942 Rename is_set_derived by is_set_externally
Because this hasn"t much to do with derived
2021-10-28 15:52:29 +02:00
Simon Hausmann
c2d757013e Revert "Fix assert in code generator when using sub-components as repeated elements"
This reverts commit 6e8d463d4bb88720a9682c839c5754959dd57c20.

It's better if the generated code for sub-components implements a
root_item function, instead of blowing up the generated code.
2021-10-28 15:52:29 +02:00
Simon Hausmann
0898248044 Fix assert in code generator when using sub-components as repeated elements
We need to inline those because the generator asserts that it's
a built-in element in order to implement `root_item`.
2021-10-28 15:52:29 +02:00
Simon Hausmann
82b5c3bcce Fix the item index generation to take sub-components into account
A regular element where the base type is a built-in item uses one slot,
while a sub-component expands to multiple nested built-in items.
2021-10-28 15:52:29 +02:00
Simon Hausmann
98f6cab553 Make it easier to distinguish between the component types in the generators
Besides `is_global()` add `is_root_component` to Rc<Component>, so that
we can distinguish between the main component (that should have the full
API, etc.) and supplementary components.

This also avoids the generation of unnecessary members when inlining is
disabled.
2021-10-28 15:52:29 +02:00
Olivier Goffart
bcc973bb63 Make sure the ids are unique globally
For the inner elements, they don't need to be unique, but that might
make debugging easier.
For the globals, their name need to be unique.
2021-10-28 15:52:29 +02:00
Olivier Goffart
c9c43766f4 fixup previous commit: remove stray debug 2021-10-28 15:52:29 +02:00
Olivier Goffart
9c6bc6afc7 Do the property analysis accounting for several component 2021-10-28 15:52:29 +02:00
Simon Hausmann
bc81d80f4a Fix structure collection with non-inlined components
Make sure that doc.root_component.used_types.structs has all the
structs, instead of storing them in used_types for each sub-component.
That should also account for the same structures used by different
components.
2021-10-28 15:52:29 +02:00
Simon Hausmann
370e2ca14b Make the inlining pass remove inlined componts from used_types.sub_components
It seems cleaner to do this in the inlining pass, as we initially selectively inline.
2021-10-28 15:52:29 +02:00
Olivier Goffart
25dfc218b0 Collect globals before inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
32668eed9c Fix a bunch of panic that might occur later as the optimizations happen per component 2021-10-28 15:52:29 +02:00
Olivier Goffart
8622dcb910 Do the default_geometry pass without inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
67dd409f87 Move a few more passes before inlining 2021-10-28 15:52:29 +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
Olivier Goffart
5f07678478 Make the layout pass work on non-inlined tree 2021-10-28 15:52:29 +02:00
Olivier Goffart
7b41f8a4bc Do the popup window pass before inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
6e5596cdfc Make the repeater pass work on the non-inlined object tree 2021-10-28 15:52:29 +02:00