mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-30 23:27:22 +00:00
C++: Added ComponentInstance::definition()
getter to retrieve the ComponentDefinition
for an instance
Fixes #4087
This commit is contained in:
parent
d104238cac
commit
75f24163ed
4 changed files with 34 additions and 0 deletions
|
@ -542,6 +542,8 @@ inline Struct::iterator::~iterator()
|
|||
}
|
||||
}
|
||||
|
||||
class ComponentDefinition;
|
||||
|
||||
/// The ComponentInstance represents a running instance of a component.
|
||||
///
|
||||
/// You can create an instance with the ComponentDefinition::create() function.
|
||||
|
@ -806,6 +808,9 @@ public:
|
|||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the ComponentDefinition that was used to create this instance.
|
||||
inline ComponentDefinition definition() const;
|
||||
};
|
||||
|
||||
/// ComponentDefinition is a representation of a compiled component from .slint markup.
|
||||
|
@ -819,6 +824,7 @@ public:
|
|||
class ComponentDefinition
|
||||
{
|
||||
friend class ComponentCompiler;
|
||||
friend class ComponentInstance;
|
||||
|
||||
using ComponentDefinitionOpaque = slint::cbindgen_private::ComponentDefinitionOpaque;
|
||||
ComponentDefinitionOpaque inner;
|
||||
|
@ -925,6 +931,13 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
inline ComponentDefinition ComponentInstance::definition() const
|
||||
{
|
||||
cbindgen_private::ComponentDefinitionOpaque result;
|
||||
cbindgen_private::slint_interpreter_component_instance_component_definition(inner(), &result);
|
||||
return ComponentDefinition(result);
|
||||
}
|
||||
|
||||
/// ComponentCompiler is the entry point to the Slint interpreter that can be used
|
||||
/// to load .slint files or compile them on-the-fly from a string
|
||||
/// (using build_from_source()) or from a path (using build_from_source())
|
||||
|
|
|
@ -331,6 +331,13 @@ SCENARIO("Component Definition Properties")
|
|||
auto callback_names = comp_def.callbacks();
|
||||
REQUIRE(callback_names.size() == 1);
|
||||
REQUIRE(callback_names[0] == "dummy");
|
||||
|
||||
auto instance = comp_def.create();
|
||||
ComponentDefinition new_comp_def = instance->definition();
|
||||
auto new_props = new_comp_def.properties();
|
||||
REQUIRE(new_props.size() == 1);
|
||||
REQUIRE(new_props[0].property_name == "test");
|
||||
REQUIRE(new_props[0].property_type == Value::Type::String);
|
||||
}
|
||||
|
||||
SCENARIO("Component Definition Properties / Two-way bindings")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue