mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Add a section to the C++ intepreter intro about global singletons
Also minor fixes to the generated C++ global singleton docs.
This commit is contained in:
parent
3212cda271
commit
54182ff54b
2 changed files with 15 additions and 6 deletions
|
@ -96,10 +96,9 @@ private:
|
|||
## Global Singletons
|
||||
|
||||
In `.60` files it is possible to declare [singletons that are globally available](markdown/langref.md#global-singletons).
|
||||
It's possible to make these global singletons accessible to your C++ code, by exporting them and using the
|
||||
`global()` getter function in the C++ class generated for your entry component. Each global singleton
|
||||
creates a class that has getter/setter functions for properties and callbacks, similar to API that's
|
||||
created for your `.60` component, as demonstrated in the previous section.
|
||||
You can access them from to your C++ code by exporting them and using the `global()` getter function in the
|
||||
C++ class generated for your entry component. Each global singleton creates a class that has getter/setter functions
|
||||
for properties and callbacks, similar to API that's created for your `.60` component, as demonstrated in the previous section.
|
||||
|
||||
For example the following `.60` markup defines a global `Logic` singleton that's also exported:
|
||||
|
||||
|
@ -115,7 +114,7 @@ like this:
|
|||
```cpp
|
||||
auto app = SampleComponent::create();
|
||||
// ...
|
||||
app.global<Logic>().on_to_uppercase([](SharedString str) -> SharedString {
|
||||
app->global<Logic>().on_to_uppercase([](SharedString str) -> SharedString {
|
||||
std::string arg(str);
|
||||
std::transform(arg.begin(), arg.end(), arg.begin(), toupper);
|
||||
return SharedString(arg);
|
||||
|
|
|
@ -44,4 +44,14 @@ For more complex UIs it is common to supply data in the form of an abstract data
|
|||
[`for` - `in`](markdown/langref.md#repetition) repetitions or [`ListView`](markdown/widgets.md#listview) elements in the `.60` language.
|
||||
All models in C++ with the interpreter API are sub-classes of the {cpp:class}`sixtyfps::Model` where the template
|
||||
parameter is {cpp:class}`sixtyfps::interpreter::Value`. Therefore to provide your own data model, you can subclass
|
||||
`sixtyfps::Model<sixtyfps::interpreter::Value>`.
|
||||
`sixtyfps::Model<sixtyfps::interpreter::Value>`.
|
||||
|
||||
In `.60` files it is possible to declare [singletons that are globally available](markdown/langref.md#global-singletons).
|
||||
You can access them from to your C++ code by exporting them and using the getter and setter functions on
|
||||
{cpp:class}`sixtyfps::interpreter::ComponentInstance` to change properties and callbacks:
|
||||
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::set_global_property()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::get_global_property()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::set_global_callback()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::invoke_global_callback()`
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue