Commit graph

465 commits

Author SHA1 Message Date
Olivier Goffart
53775465dc
C++: add version macro
Fixes #705
2021-12-06 15:36:16 +01:00
Olivier Goffart
47a4463abc Rename the sub component id to avoid error in the generated code with duplicated names 2021-11-23 12:03:03 +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
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
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
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
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
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
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
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
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
Simon Hausmann
90a97cd737 Remove unused variable 2021-11-03 18:37:40 +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
ab88e3553e Fix the item tree building for components whose base is a component
We should only visit element that are native item with the visit_item function
2021-11-03 14:59:27 +01:00
Simon Hausmann
2a8c004a7e Fix repeated elements in C++ sub-components
Delegate the visitation of dynamic children. Fixes test_cpp_models_for.
2021-11-03 12:35:32 +01:00
Olivier Goffart
db52f8e726 Fix the C++ compilation of the gallery without inlining
Some code like this was generated:
`if (*self->checkbox_31.get_checked()).get()`
the remove_parentheses function removed a parentheses that it shouldn't have removed
2021-11-03 11:48:05 +01:00
Simon Hausmann
8ddd01ad9a Remove unused variable in the C++ code generator 2021-11-03 11:40:24 +01:00
Simon Hausmann
76b4d7ec75 Remove trailing whitespace 2021-11-03 10:53:40 +01:00
Simon Hausmann
a0c644ab25 Fix compilation of root_item() implementation for the ComponentVTable in C++
... when the root item is a sub-component.
2021-11-03 10:47:11 +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
dd9f6787fd Silence clang warning about unused m_root variable
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.
2021-11-02 20:58:32 +01:00
Simon Hausmann
88d050d8ce Revert "Silence warning about unused m_root member in C++ sub-components"
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).
2021-11-02 11:56:08 +01:00
Olivier Goffart
4b73cce76e C++: make the member funciton layout_info and root_item const
It might be called with a const pointer
2021-11-02 11:49:30 +01:00
Simon Hausmann
fde3846392 Silence warning about unused m_root member in C++ sub-components
There are a few things we could probably do lazily in the code generator, but
for now this is distracting :-)
2021-11-02 11:29:07 +01:00
Olivier Goffart
e17e035251 Fix warning about unused variable in the C++ generated code 2021-11-02 09:58:26 +01:00
Olivier Goffart
08c1d875d3 C++: The property getter should be const
Because it is sompetimes used with const pointers
2021-11-02 09:51:38 +01:00
Olivier Goffart
54f9ccfa8e Add all repeated components as friend of the root items
They need to be in order to access the globals

Now the test_cpp_models_for compiles, but it crashes at runtime
2021-11-02 09:20:48 +01:00
Simon Hausmann
167fa790fe Fix initialization of self_weak in sub-components in C++
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.
2021-11-01 20:04:46 +01:00
Olivier Goffart
efa1448565 C++: Pass the right root pointer 2021-11-01 17:04:31 +01:00
Olivier Goffart
789ac719eb Make the parent_item function work with repeater component 2021-11-01 16:11:38 +01:00
Olivier Goffart
199fe1c676 C++: fix warning about unused variable and unordered initialization 2021-11-01 14:09:28 +01:00
Simon Hausmann
096fbab93d Simplify the destructor of generated C++ components
Similar to the parent commit, avoid creating an array of item refs and pass the item tree instead
to a run-time helper function.
2021-11-01 10:19:17 +01:00
Simon Hausmann
db64d30a29 First attempt at fixing the item tree for sub-components
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.
2021-10-29 19:05:25 +02:00
Simon Hausmann
f205a2806c Fix accessing aliases on sub-components in C++
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.
2021-10-29 14:10:43 +02:00
Simon Hausmann
efc09dd17b Fix setting bindings at use-site on custom properties of sub-components in C++
* Make sure the fields are public
* Detect when the target property is not in the item itself but a custom property
2021-10-29 11:15:56 +02:00
Simon Hausmann
342d908a10 Fix build of bindings in sub-components in C++ that access the window
To keep the rest of the C++ generator simpler, let's also add an m_window member
2021-10-29 10:56:23 +02:00
Simon Hausmann
8dbf78c95d Fix access to globals from within sub-components in C++
* 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
2021-10-29 10:32:25 +02:00
Simon Hausmann
ae25dd3d07 Fix calls to BuiltinFunction::ImplicitLayoutInfo for sub-components in C++
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).
2021-10-28 21:49:07 +02:00
Simon Hausmann
08c49a5ff4 Fix call to free_graphics_resources in C++ when using sub-components
The fields in item_names_and_vt_symbols need to be prefixed with the sub-component field names.
2021-10-28 16:56:49 +02:00
Simon Hausmann
59898429e8 Fix compilation of bindings on sub-components in C++
We need to install them on the root item (which can be subject to indirection).
2021-10-28 16:44:30 +02:00
Simon Hausmann
8efca487dd Fix access rights of fields in sub-components
They need to be public for now,
in order to install bindings from
the use-site.
2021-10-28 16:31:43 +02:00
Simon Hausmann
d64990460f Fix access of sub-component fields in the root component
Make them private
2021-10-28 16:25:56 +02:00
Simon Hausmann
5c5d9b7988 Fix broken constructor calls to sub-components in C++
The constructor needs to be accessible.
2021-10-28 16:05:56 +02:00
Simon Hausmann
529db12ee8 Fix child offset in the item tree when using sub-components
The base is advanced by taking the item index of the element that has the sub-component base type,
not the one of the root element or any children.
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
Simon Hausmann
90abcf3066 WIP: Implement item tree generation for sub-components in C++
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.
2021-10-28 15:52:29 +02:00
Simon Hausmann
467a02310c Fix assert in C++ code generator when using repeated sub-components
Instead of requiring inlining, assume that the generated code will provide an
implementation of layouting_info as well as root_item.

They're not implemented yet though.
2021-10-28 15:52:29 +02:00
Simon Hausmann
125a2ae125 C++ generator: forward the sub-component start indicies
Within sub-components we only know the local item index, and together with the
offset provided in the constructor we'll be able to
compute the correct index for items that's needed sometimes,
for example for focus setting.

The item indices are still wrong though, that'll need fixing in the corresponding pass.
2021-10-28 15:52:29 +02:00
Simon Hausmann
d0216a4291 C++ generator: don't generate m_window and self_weak for sub-components 2021-10-28 15:52:29 +02:00