mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
C++ Interpreter: add API to get/set global value
This commit is contained in:
parent
c5d2ac2dd3
commit
81688906f7
4 changed files with 140 additions and 1 deletions
|
@ -709,6 +709,38 @@ public:
|
|||
inner(), sixtyfps::private_api::string_to_slice(name), actual_cb,
|
||||
new F(std::move(callback)), [](void *data) { delete reinterpret_cast<F *>(data); });
|
||||
}
|
||||
|
||||
/// Set the value for a property within an exported global
|
||||
///
|
||||
/// For example, if the main file has a global `TheGlobal` with a `property <int> hello`,
|
||||
/// we can set this property
|
||||
/// ```
|
||||
/// instance->set_global_property("TheGlobal", "hello", 42);
|
||||
/// ```
|
||||
///
|
||||
/// Returns true if the property was correctly set. Returns false if the property
|
||||
/// could not be set because it either do not exist (was not declared in .60) or if
|
||||
/// the value is not of the proper type for the property's type.
|
||||
bool set_global_property(std::string_view global, std::string_view prop_name, const Value &value) const
|
||||
{
|
||||
using namespace cbindgen_private;
|
||||
return sixtyfps_interpreter_component_instance_set_global_property(
|
||||
inner(), sixtyfps::private_api::string_to_slice(global),
|
||||
sixtyfps::private_api::string_to_slice(prop_name), &value.inner);
|
||||
}
|
||||
/// Returns the value behind a property in a exported global.
|
||||
std::optional<Value> get_global_property(std::string_view global, std::string_view prop_name) const
|
||||
{
|
||||
using namespace cbindgen_private;
|
||||
ValueOpaque out;
|
||||
if (sixtyfps_interpreter_component_instance_get_global_property(
|
||||
inner(), sixtyfps::private_api::string_to_slice(global),
|
||||
sixtyfps::private_api::string_to_slice(prop_name), &out)) {
|
||||
return Value(out);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(DOXYGEN)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue