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>()
}
}
/* /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>

See Widget Templates for more info.

Constructors

Link copied to clipboard
constructor(typeClass: KClass<T>, parentType: <Error class: unknown class><Widget>, templateId: String)

Functions

Link copied to clipboard
open fun classInit(objectClass: <Error class: unknown class><<Error class: unknown class>>)
Link copied to clipboard
open fun <T> newInstancePointer(): <Error class: unknown class><T>
Link copied to clipboard