Commit graph

560 commits

Author SHA1 Message Date
Tobias Hunger
e6b24bceec [reorg]: Set up and populate the internal directory
Move "internal" crates into the `internal` directory. This first batch
includes most of sixtyfps_runtime but leaves the rendering backends
alone for now.

pre-commit applied some cleanups to the moved files:
 - Consistent newline at end of file policy
 - trimming trailing whitespace
 - Formatting Cargo.toml files.
2022-01-31 16:00:50 +01:00
Olivier Goffart
e28586ede0 Test (and fix) using [] on a temporary array
The C++ code did not compile because it couldn't deduce the template parameter
properly. Since the lambda became a bit big to be placed in one small string,
I moved it into a real function in the header

Example of error:   (sorry for the long lines :-))

```
tmp/.tmpE42a4c.cpp: In member function 'void TestCase::init(const TestCase*, sixtyfps::cbindgen_private::ComponentWeak, uintptr_t, uintptr_t)':

/tmp/.tmpE42a4c.cpp:67:238: error: no match for call to '(TestCase::init(const TestCase*, sixtyfps::cbindgen_private::ComponentWeak, uintptr_t, uintptr_t)::<lambda(const std::shared_ptr<sixtyfps::Model<ModelData> >&, const auto:24&)>) (std::shared_ptr<sixtyfps::private_api::ArrayModel<2, sixtyfps::SharedString> >, int)'
   67 |     self->root_window_1_hello_world.set([&]<typename D>(const std::shared_ptr<sixtyfps::Model<D>> &model, const auto &index) -> D { model->track_row_data_changes(index); if (const auto v = model->row_data(index)) return *v; return D(); }(std::make_shared<sixtyfps::private_api::ArrayModel<2,sixtyfps::SharedString>>(sixtyfps::SharedString ( sixtyfps::SharedString(u8"hello") ), sixtyfps::SharedString ( sixtyfps::SharedString(u8"world") )), 1));
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/.tmpE42a4c.cpp:67:41: note: candidate: 'template<class D, class auto:24> TestCase::init(const TestCase*, sixtyfps::cbindgen_private::ComponentWeak, uintptr_t, uintptr_t)::<lambda(const std::shared_ptr<sixtyfps::Model<ModelData> >&, const auto:24&)>'
   67 |     self->root_window_1_hello_world.set([&]<typename D>(const std::shared_ptr<sixtyfps::Model<D>> &model, const auto &index) -> D { model->track_row_data_changes(index); if (const auto v = model->row_data(index)) return *v; return D(); }(std::make_shared<sixtyfps::private_api::ArrayModel<2,sixtyfps::SharedString>>(sixtyfps::SharedString ( sixtyfps::SharedString(u8"hello") ), sixtyfps::SharedString ( sixtyfps::SharedString(u8"world") )), 1));
      |                                         ^
/tmp/.tmpE42a4c.cpp:67:41: note:   template argument deduction/substitution failed:
/tmp/.tmpE42a4c.cpp:67:238: note:   mismatched types 'sixtyfps::Model<ModelData>' and 'sixtyfps::private_api::ArrayModel<2, sixtyfps::SharedString>'
   67 |     self->root_window_1_hello_world.set([&]<typename D>(const std::shared_ptr<sixtyfps::Model<D>> &model, const auto &index) -> D { model->track_row_data_changes(index); if (const auto v = model->row_data(index)) return *v; return D(); }(std::make_shared<sixtyfps::private_api::ArrayModel<2,sixtyfps::SharedString>>(sixtyfps::SharedString ( sixtyfps::SharedString(u8"hello") ), sixtyfps::SharedString ( sixtyfps::SharedString(u8"world") )), 1));
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2022-01-28 20:32:35 +01:00
Tobias Hunger
e3c4209b1f
Change Model::row_data to return an Option<T> (#873)
Change Model::row_data to return an Option<T> (rust) or std::optional<T> (c++)

Co-authored-by: Olivier Goffart <olivier@woboq.com>
Co-authored-by: Simon Hausmann <hausmann@gmail.com>
2022-01-26 13:55:38 +01:00
Olivier Goffart
319704d3fb C++: use default operator==
Since we now use C++20, we can simplify our code a bit
2022-01-24 17:16:55 +01:00
Olivier Goffart
973c5960b7 C++ interpreter: Use std::span instead of the internal Slice in the public API 2022-01-24 13:04:12 +01:00
Olivier Goffart
1db34682ee C++: fix crash when closing window
the m_window needs to be destroyed after the destructor of the repeater
2022-01-20 08:42:32 +01:00
Simon Hausmann
e2838a87ab Fix missing calls to init() of native items in repeater item trees when using C++
Like in the Rust generator, we need to always call init_items().
2022-01-19 16:56:02 +01:00
Simon Hausmann
9bbcf16124 Fix typo
Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2022-01-19 15:42:43 +01:00
Simon Hausmann
1fcfc58975 cpp generator: reduce surface of public C++ API
Use Access::Private as access for properties, items, helper fields (tree
index, etc.), and vtable functions of the public component.

All meanwhile added declarations for sub-components (such as popups, child repeaters)
still get access through friendship.
2022-01-19 15:42:43 +01:00
Olivier Goffart
f9f90e1b4e C++: Do not expose private types in the sixtyfps namespace 2022-01-19 11:19:47 +01:00
Simon Hausmann
12e2aa3941 cpp llr: Simplify generate() signature
Since the function always returns Some(), we can remove the Option from the return type.
2022-01-19 10:02:23 +01:00
Tobias Hunger
81d1c8129f Remove some commented out code 2022-01-19 10:02:23 +01:00
Tobias Hunger
fb3d5ef263 LLR-C++: Implement ShowPopupWindow 2022-01-19 10:02:23 +01:00
Simon Hausmann
96a5682fd8 cpp llr: remove some old code that was commented out 2022-01-19 10:02:23 +01:00
Simon Hausmann
3ec6c0fc63 cpp llr: fix disappearing items when rendering repeaters
Creating a repeater component would use the same setup code as a public component,
which replaces the component rc in the window among other things.

Handle this in generate_item_tree just like in the Rust generator.
2022-01-19 10:02:23 +01:00
Olivier Goffart
67c6a352ea llr-cpp: fix a warning in the generated code 2022-01-19 10:02:23 +01:00
Simon Hausmann
569fee695e cpp llr: fix use of properties of native items in if conditionals
InNative assumed that the current sub-compo is accessed using "this",
which happens to also be part of regular binding captures. But it isn't for model binding,
for example.

Let's use "self" throughout, like everywhere else.
2022-01-19 10:02:23 +01:00
Simon Hausmann
5e5622a947 cpp llr: Implement RegisterCustomFontByMemory and RegisterCustomFontByPath 2022-01-19 10:02:23 +01:00
Simon Hausmann
4a89cc106c llr cpp: fix initial_focus test
Don't call set_focus_item() followed by set_component() on the window, which clears the focus item again.

Like in Rust, call set_component first, then init_items() and finally all the init/setup code.
2022-01-19 10:02:23 +01:00
Simon Hausmann
5631098f91 cpp llr: invoke generated sub-component init code
The initial focus handling generates setup code, which needs inclusion.
2022-01-19 10:02:23 +01:00
Simon Hausmann
f451e4eaf7 cpp llr: fix set_focus_item builtin method calls
End the function call with a semicolon.
2022-01-19 10:02:23 +01:00
Simon Hausmann
c58668a600 cpp llr: fix test_cpp_7gui_timer
Port commit 242dfcf7cf to catch all conversions from numbers to string.
2022-01-19 10:02:23 +01:00
Simon Hausmann
85fa56ac32 cpp llr: minor cleanup
Fold unused variables into their use-site
2022-01-19 10:02:23 +01:00
Olivier Goffart
1f3620acfa llr-cpp: fix crash computing path
The events and point were referencing temporaries.
Fix that by passing them as argument to the lambda so the temporaries
don't get destroyed before being used.
2022-01-19 10:02:23 +01:00
Olivier Goffart
35cb9ed338 llr-cpp: Fix Dialog 2022-01-19 10:02:23 +01:00
Olivier Goffart
0259c0dc9b Give a return type to llr::Expression::ExtraBuiltinFunctionCall
Some code in the C++ generator needs the type of such expressions
2022-01-19 10:02:23 +01:00
Simon Hausmann
c2ae82c74f cpp llr: fix crashes_issue_422_enclosing_component
Make sub-compo fields public
2022-01-19 10:02:23 +01:00
Simon Hausmann
80768fd011 cpp llr: fix color and string builtin function calls 2022-01-19 10:02:23 +01:00
Simon Hausmann
44857ff0f2 cpp llr: Fix BuiltinFunction::Debug to stream into std::cout 2022-01-19 10:02:23 +01:00
Olivier Goffart
83136f5bca llr-cpp: fix test_cpp_properties_property_animation 2022-01-19 10:02:23 +01:00
Simon Hausmann
4a3678fe55 cpp llr: Fix support for the Close {} path element 2022-01-19 10:02:23 +01:00
Olivier Goffart
270d8ab2c7 llr-cpp: Transitions 2022-01-19 10:02:23 +01:00
Simon Hausmann
708c4a55de cpp llr: add support for path events 2022-01-19 10:02:23 +01:00
Simon Hausmann
7e695ae4e6 cpp llr: add support for path elements
This is mostly covered by the cast produced by the llr lowering.
2022-01-19 10:02:23 +01:00
Olivier Goffart
1464da3a68 llr-cpp: Public API for globals 2022-01-19 10:02:23 +01:00
Olivier Goffart
23a2900b66 llr-cpp: init global bindings 2022-01-19 10:02:23 +01:00
Simon Hausmann
34825e0a2b cpp llr: Fix ensure_updated for listview 2022-01-19 10:02:23 +01:00
Simon Hausmann
7c3f8b78cb cpp llr: Provide access to user-defined globals 2022-01-19 10:02:23 +01:00
Olivier Goffart
37707ac98e llr-cpp: Flickable 2022-01-19 10:02:23 +01:00
Olivier Goffart
99adc25a81 llr-cpp: Fix for within layout 2022-01-19 10:02:23 +01:00
Simon Hausmann
f5459177f3 cpp llr: Implement ModelDataAssignment and ArrayIndexAssignment
Also make repeaters friends of the App, for field access.
2022-01-19 10:02:23 +01:00
Olivier Goffart
55f66b36d5 C++: Remove a bunch of commented out code that was already ported
Or which is still commented out somewhere else
2022-01-19 10:02:23 +01:00
Simon Hausmann
339dde64f1 cpp llr: fix test_cpp_models_for
Make the parent accessible to sub-components
2022-01-19 10:02:23 +01:00
Olivier Goffart
d62b788829 C++: Do wrapper to the layout function
That returns and take their argument in a C++-like way instead of by pointer.
2022-01-19 10:02:23 +01:00
Simon Hausmann
4b0ae4d5a1 cpp llr: Fix BuiltinFunction::ArrayLength
Evaluate the model only once, and invoke the lambda that tracks the row count and returns it.
2022-01-19 10:02:23 +01:00
Simon Hausmann
3fe33df56b cpp llr: Fix -Werror errors with unused parameters in update_data for repeaters
Fixes three more tests
2022-01-19 10:02:23 +01:00
Simon Hausmann
f9bbe9c3a2 cpp llr: make self_weak accessible to child repeaters 2022-01-19 10:02:23 +01:00
Tobias Hunger
0999e9ccf5 C++: Implement SetFocusItem builtin 2022-01-19 10:02:23 +01:00
Olivier Goffart
708fc0b8a7 C++: Don't rely on the order of struct members
When initializing a Type::Struct, don't use agregate initialization that
relies on the orde of fields.

This is important because the builtin layout struct are not ordered
lexicographicly.
2022-01-19 10:02:23 +01:00
Simon Hausmann
4544e4c7c1 cpp llr: extend comment about public fields in globals 2022-01-19 10:02:23 +01:00