C++: Added ComponentInstance::definition() getter to retrieve the ComponentDefinition for an instance

Fixes #4087
This commit is contained in:
Simon Hausmann 2023-12-14 00:46:47 +01:00 committed by Simon Hausmann
parent d104238cac
commit 75f24163ed
4 changed files with 34 additions and 0 deletions

View file

@ -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())