Commit graph

427 commits

Author SHA1 Message Date
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
Simon Hausmann
9868b693e2 Only publish exported globals in C++ and Rust 2021-08-27 13:36:48 +02:00
Olivier Goffart
81688906f7 C++ Interpreter: add API to get/set global value 2021-08-27 13:36:48 +02:00
Simon Hausmann
5e833e5d23 Add support for accessing globals from C++ 2021-08-27 13:36:48 +02:00
Olivier Goffart
b07d52cd23 Support aliases to callbacks in globals 2021-08-24 12:36:16 +02:00
Olivier Goffart
b42c187ed1 Refactor the way the two-ways biding are represented internaly
Don't put them in a fake expression.
This simplifies a bit the expression handling, and will make
possible to fix analysis that needs a vew into the aliases
2021-08-20 18:26:36 +02:00
Simon Hausmann
2458ac5d02 Fix panic when calling focus() on a repeated element
When trying to reference an instance of a repeated item, for use with
ItemRc or VRef<Item>, the item_index (or id) of the ElementRc is not
directly what we want.

Adjust any element references to the repeater to to the inner instance
after creating them. Also make sure that the enclosing component is
respected in the C++ and Rust generators.

Fixes #422
2021-08-20 15:39:54 +02:00
Tobias Hunger
a387c0f60f Janitor: Fix clippy::needless_borrow 2021-08-18 00:24:51 +02:00
Olivier Goffart
c25538c982 Normalize identifiers to - instead of _
As a result
 - The error messages will now show the error with `-` instead of `_`
 - The LSP will auto-complete with -
 - The interpreter's list of properties will list the property with '-'
   (but we made the change so that set_property, get_property, and so on
   work also if passed a '-')
2021-08-10 22:21:01 +02:00