Update language-specific docs to document that public functions can be called from the backend code (#5522)

* Examples for calling public functions in language-specific docs.

* Update the function example so it actually uses its parameter.

(This broke some c++ tests because of the unused argument warning)
This commit is contained in:
Danut Enachioiu 2024-07-03 12:13:08 +02:00 committed by GitHub
parent 07e10f37ab
commit 033e4de9b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 54 additions and 9 deletions

View file

@ -26,6 +26,7 @@ These classes have the same name as the component will have the following public
* `invoke_<callback_name>` function which takes the callback argument as parameter and call the callback.
* `on_<callback_name>` function which takes a functor as an argument and sets the callback handler
for this callback. the functor must accept the type parameter of the callback
* For each public function declared in the root component, an `invoke_<function_name>` function to call the function.
* A `global` function to access exported global singletons.
The `create` function creates a new instance of the component, which is wrapped
@ -48,10 +49,13 @@ Let's assume we've this code in our `.slint` file:
```slint,no-preview
export component SampleComponent inherits Window {
in-out property<int> counter;
// note that dashes will be replaced by underscores in the generated code
in-out property<string> user_name;
callback hello;
public function do-something(x: int) -> bool { return x > 0; }
// ... maybe more elements here
}
```
This generates a header with the following contents (edited for documentation purpose)
@ -94,6 +98,9 @@ public:
/// Sets the callback handler for the `hello` callback.
template<typename Functor> inline void on_hello (Functor && callback_handler) const;
/// Call this function to call the `do-something` function.
inline bool invoke_do_something (int x) const;
/// Returns a reference to a global singleton that's exported.
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will