Commit graph

435 commits

Author SHA1 Message Date
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
Simon Hausmann
4058f95ebb C++: Improve the embedded image generation code
* Allocate less by using only two format!() calls
* Escape the extension properly and mark the string as u8 literal, like
  we also do for paths.
2021-10-05 15:05:50 +02:00
Simon Hausmann
7cb30e1e07 C++: Reduce extra allocations when formatting string for data embedding 2021-10-05 15:05:50 +02:00
Simon Hausmann
19b2415ba4 Minor formatting cleanups 2021-10-05 15:05:50 +02:00
Simon Hausmann
c91a38cdce Add support for embedding data in generated C++ code
This allows compiling with SIXTYFPS_EMBED_RESOURCES=true and
images/fonts are embedded as inline variables.

Generated data is emitted into the header file as

   inline uint8_t sfps_embedded_resources_123[789] = {
       0x1, 0x2, 0x3,
   };
2021-10-05 15:05:50 +02:00
Olivier Goffart
7f05bfa309 Add the Dialog element 2021-09-29 16:25:44 +02:00
Olivier Goffart
fafcbfde2c Fix panic when trying to access layout cache of destroyed items
This can be reproduced by deleting the last item of the printer queue in the
printer demo.
It is a regression showing up because we now emit the MouseExit event after
the mouse grab as released.
The problem is that we upgrade the weak item, and call geometry() on it.
Calling geometry will re-evaluate the layout cache which will re-evaluate
the model which will result in the component being removed and the cache
entry having less item than expected.

It is ok to simply return 0. for these layout location since the item will
disapear anyway.
2021-09-08 14:42:08 +02:00
Olivier Goffart
dedc9b3b9b C++: Fix struct literal for builtin structs 2021-09-05 09:29:00 +02:00
Olivier Goffart
131d14058b Fix C++ generated code when the numbers are too big 2021-09-05 09:29:00 +02:00
Simon Hausmann
ee8e5699e5 Clean up global alias handling
Remove the internal name again and pick the first exported one when
assigning ids. This avoids internal names showing up in code completion
or the internal types leaking into generated code.
2021-08-31 17:09:11 +02:00
Simon Hausmann
0d19e2d9b9 Add support for global aliases
When exporting an global multiple times under different names, make sure
that they alias in the generated code.

As a consequence, the compiler maintains the original unique name and in
Rust and C++ makes only the exported names public. In the interpreter
the internal name is theoretically still accessible from the outside.
2021-08-31 17:09:11 +02:00