TemplateWidgetType
open class TemplateWidgetType<T : Widget>(typeClass: KClass<T>, parentType: <Error class: unknown class><Widget>, templateId: String)
Companion object base class used for deriving Widget subclasses that make use of widget templates.
This is a specialization of ObjectType that takes care of:
registering the widget template during class init
binding the template children during class init
initializing the template on new instance creation
Example usage
This example shows the definition of an ExampleWidget
class that extends the Box
widget. The companion object constructor takes the template id as a constructor argument.
The body of the companion object uses templateChild to register all template children that can be accessed by instances of this class.
The body of ExampleWidget
uses delegates from its Type
companion to access the child widgets.
class ExampleWidget : Box(newInstancePointer()) {
val entry by Type.entry
val button by Type.button
companion object Type : TemplateWidgetType<ExampleWidget>(
ExampleWidget::class, Box.type, "/ui/examplewidget.ui"
) {
val entry by templateChild<Entry>()
val button by templateChild<Button>()
}
}
Content copied to clipboard
/* /ui/examplewidget.ui */
<interface>
<template class="ExampleWidget" parent="GtkBox">
<child>
<object class="GtkEntry" id="entry">
</object>
</child>
<child>
<object class="GtkButton" id="button">
<property name="label">Hello</property>
</object>
</child>
</template>
</interface>
Content copied to clipboard
See Widget Templates for more info.
Functions
Link copied to clipboard
Link copied to clipboard
inline fun <CHILD_TYPE> templateChild(name: String? = null): TemplateChildDelegateProvider<T, CHILD_TYPE>