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.
The variable in C++ sub-components is sometimes unused. We could try to lazily emit it, but
that requires more work and this is distracting :-). This silencing should hopefully also work for gcc.
This reverts commit fde3846392 because it
breaks the gcc build ("error: 'maybe_unused' attribute ignored
[-Werror=attributes]"). Will need a different solution that works for
clang (which warns about m_root_ being unused).
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)
Calling init on sub-components with self_weak as argument only works after self_weak is
initialized, which happens in create(). So a new init() function for root components is called afterwards.
We never ended up passing the right index but always zero.
Fix by rewriting build_item_tree to be basically the same as build_array_helper,
with two differences:
(1) we maintain absolute and relative children offsets and parent indices
(2) When traversing over the children of an element there are two scenarios: either
the element is a sub-component, in which case we iterate through the children of the root element,
or we can use ElementRc's children directly
We need to maintain the order of declaration and the sub-trees
of children need to be emitted before continuing with the parent.
This fixes the tab widget in the galler.y
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.
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.
By accident the tree was still depth-first instead of level-order. This implementation works better,
by placing the root element of sub-components as
parents and the children into the children space later.
There's still more work to do to clean it up and make work with more complex scenarios.
When the use-site of a component tries to set a binding on a property that is an alias,
it might be that the alias was optimized away.
To avoid needeless recursion, this patch generates a mutable property getter
for declared properties (which takes care of alias redirection).
This also removes the use of root_item() because it's insufficient: If the property is custom (and/or an alias), then we need to use the getter,
otherwise we need to recurse.
So there are three cases:
```
MyButton {
text: "Ok";
}
```
If `MyButton` is `MyButton := Rectangle { property<string> text; }` then
we go through the mutable prop reference getter. This also works for aliases.
If it's `MyButton := Text { ... }` or (more complex) `L := Text {} MyButton := L {}` then
we recurse.
Traditionally the recursion is not needed because in public API the "inherited" properties
aren't expose. But since in the language they are exposed, we need to continue.
As a bonus this cleans up the property access code a little by re-using access_member.
* Forward declare the root component
* Pass it as a parameter to the constructor and save it as m_root pointer and use it to access globals
* Make the sub-components friends of the root component, in order to access the globals
* Delay binding initialization to an explicit init() call in sub-components
The parent commit accidentally removed the case of the generation for
the implicit layout info call where the layout info property is
available on a component (i.e. it is in a layout).
Amends commit ae25dd3d07
Provide a layout_info implementation for sub-components and call it. This
disables the lowering the implicit_layout_info call again,
also to ensure that when this
is installed from the use-site of the sub-component, the self can be used to obtain
the info (by calling the new generated function).
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).
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.
In the generator for producing the members of built-in items, repeaters
or sub-components, we don't need to traverse into sub-components. The
C++ compiler will take care of instantiating the fields of
sub-components after all.
For the item tree however we do need to recurse, so this change attempts
to do that. Repeaters are explicitly not handled yet though.