Commit graph

495 commits

Author SHA1 Message Date
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
Simon Hausmann
2a7976abda C++ generator: generate members for sub-components 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
Simon Hausmann
5e7175b1e3 C++ generator: Don't generate a class initialize for the m_window member for child components
The constructor initializes it property, so don't generate code that
when read might give the false impression that we allocate a new window.
2021-10-28 15:52:29 +02:00
Simon Hausmann
9028f69f27 C++ generator cleanup: Remove supplementary_components field again
This amends the parent commit, we don't need a separate vec, after
inlining the sub_components should simply be empty.
2021-10-28 15:52:29 +02:00
Simon Hausmann
b5f4a2c27c C++ generator: begin generating code for supplementary components
The generation is still incomplete, but this change passes them to the C++ generator
when not inlining.

Another option would've been a "inline: bool", but that won't suffice in
the future when we may want to use heuristics to selectively inline some
and others not. And always taking used_types.sub_components is wrong
when inlining as those are ... inlined.
2021-10-28 15:52:29 +02:00
Simon Hausmann
4183c7122b C++ generator cleanup: move component vtable generation into a helper function
Despite only being called from one place, this reduces the size
of `generate_component`, in an effort to make it more readable.
2021-10-28 15:52:29 +02:00
Simon Hausmann
007fe36839 C++ Generator: more cleanups
Move all `!component.is_global()` related code generation into one block.
2021-10-28 15:52:29 +02:00
Simon Hausmann
545ec38ed3 C++ generator: minor cleanup
Also de-duplicate the self_weak member emission
2021-10-28 15:52:29 +02:00
Simon Hausmann
13e8b36c33 Minor cleanup in C++ generator
Have one place to emit the m_window member
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
Simon Hausmann
7d12fd7b4e Add support for tracking the length of a model in C++
Similar to the parent commit, the model tracks changes to the rows and
marks an internal property dirty. Since we have a base class this is a
little less intrusive.

cc #98
2021-10-20 15:25:28 +02:00
James Blacklock
a3ba958197 remove cast 2021-10-18 10:21:06 +02:00
James Blacklock
642e4b539a (hopefully) fix cpp generation 2021-10-18 10:21:06 +02:00
James Blacklock
cc4105e274 no need for InferredGenericType! 2021-10-18 10:21:06 +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
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
df9e9dd1de Minor cleanup in C++ code generator
Use Cow<[u8]> to avoid making a copy of the file data embedded in the compiler.
2021-10-05 23:16:46 +02:00
Simon Hausmann
4a26faef9a Add AboutSixtyFPS element 2021-10-05 23:16:46 +02:00