Polish the ComponentDefinition docs a little bit

This commit is contained in:
Simon Hausmann 2021-03-23 17:21:36 +01:00
parent 1dba04721a
commit 8e05a15704
2 changed files with 21 additions and 6 deletions

View file

@ -20,7 +20,6 @@ LICENSE END */
class QWidget; class QWidget;
#endif #endif
namespace sixtyfps::cbindgen_private { namespace sixtyfps::cbindgen_private {
// This has to stay opaque, but VRc don't compile if it is just forward declared // This has to stay opaque, but VRc don't compile if it is just forward declared
struct ErasedComponentBox : vtable::Dyn struct ErasedComponentBox : vtable::Dyn
@ -511,11 +510,12 @@ public:
/// Return a QWidget for this instance. /// Return a QWidget for this instance.
/// This function is only available if the qt graphical backend was compiled in, and /// This function is only available if the qt graphical backend was compiled in, and
/// it may return nullptr if the Qt backend is not used at runtime. /// it may return nullptr if the Qt backend is not used at runtime.
QWidget *qwidget() const { QWidget *qwidget() const
{
cbindgen_private::ComponentWindowOpaque win; cbindgen_private::ComponentWindowOpaque win;
cbindgen_private::sixtyfps_interpreter_component_instance_window(inner(), &win); cbindgen_private::sixtyfps_interpreter_component_instance_window(inner(), &win);
return reinterpret_cast<QWidget *>(cbindgen_private::sixtyfps_qt_get_widget( return reinterpret_cast<QWidget *>(cbindgen_private::sixtyfps_qt_get_widget(
reinterpret_cast<cbindgen_private::ComponentWindow *>(&win))); reinterpret_cast<cbindgen_private::ComponentWindow *>(&win)));
} }
#endif #endif
@ -565,6 +565,14 @@ public:
} }
}; };
/// ComponentDefinition is a representation of a compiled component from .60 markup.
///
/// It can be constructed from a .60 file using the ComponentCompiler::build_from_path() or
/// ComponentCompiler::build_from_source() functions. And then it can be instantiated with the
/// create() function.
///
/// The ComponentDefinition acts as a factory to create new instances. When you've finished
/// creating the instances it is safe to destroy the ComponentDefinition.
class ComponentDefinition class ComponentDefinition
{ {
friend class ComponentCompiler; friend class ComponentCompiler;
@ -577,10 +585,12 @@ class ComponentDefinition
explicit ComponentDefinition(ComponentDefinitionOpaque &inner) : inner(inner) { } explicit ComponentDefinition(ComponentDefinitionOpaque &inner) : inner(inner) { }
public: public:
/// Constructs a new ComponentDefinition as a copy of \a other.
ComponentDefinition(const ComponentDefinition &other) ComponentDefinition(const ComponentDefinition &other)
{ {
sixtyfps_interpreter_component_definition_clone(&other.inner, &inner); sixtyfps_interpreter_component_definition_clone(&other.inner, &inner);
} }
/// Assigns \a other to this ComponentDefinition.
ComponentDefinition &operator=(const ComponentDefinition &other) ComponentDefinition &operator=(const ComponentDefinition &other)
{ {
using namespace sixtyfps::cbindgen_private; using namespace sixtyfps::cbindgen_private;
@ -593,7 +603,9 @@ public:
return *this; return *this;
} }
/// Destroys this ComponentDefinition.
~ComponentDefinition() { sixtyfps_interpreter_component_definition_destructor(&inner); } ~ComponentDefinition() { sixtyfps_interpreter_component_definition_destructor(&inner); }
/// Creates a new instance of the component and returns a shared handle to it.
ComponentHandle<ComponentInstance> create() const ComponentHandle<ComponentInstance> create() const
{ {
union CI { union CI {

View file

@ -463,17 +463,20 @@ impl ComponentCompiler {
} }
} }
/// ComponentDefinition is a representation of a compiled component from .60 /// ComponentDefinition is a representation of a compiled component from .60 markup.
/// ///
/// It can be constructed from a .60 file using the [`ComponentCompiler::build_from_path`] or [`ComponentCompiler::build_from_source`] functions. /// It can be constructed from a .60 file using the [`ComponentCompiler::build_from_path`] or [`ComponentCompiler::build_from_source`] functions.
/// And then it can be instentiated with the [`Self::create`] function /// And then it can be instantiated with the [`Self::create`] function.
///
/// The ComponentDefinition acts as a factory to create new instances. When you've finished
/// creating the instances it is safe to drop the ComponentDefinition.
#[derive(Clone)] #[derive(Clone)]
pub struct ComponentDefinition { pub struct ComponentDefinition {
inner: Rc<crate::dynamic_component::ComponentDescription<'static>>, inner: Rc<crate::dynamic_component::ComponentDescription<'static>>,
} }
impl ComponentDefinition { impl ComponentDefinition {
/// Instantiate the component /// Creates a new instance of the component and returns a shared handle to it.
pub fn create(&self) -> ComponentInstance { pub fn create(&self) -> ComponentInstance {
ComponentInstance { ComponentInstance {
inner: self.inner.clone().create( inner: self.inner.clone().create(