Derive Macro gtk3_macros::CompositeTemplate[][src]

    // Attributes available to this derive:
Expand description

Derive macro for using a composite template in a widget.

The template attribute specifies where the template should be loaded from; it can be a file, a resource, or a string.

The template_child attribute is used to mark all internal widgets we need to have programmatic access to.


Specify that MyWidget is using a composite template and load the template file the composite_template.ui file.

use gtk::prelude::*;
use gtk::CompositeTemplate;

#[derive(Debug, Default, CompositeTemplate)]
#[template(file = "composite_template.ui")]
struct MyWidget {
    pub label: TemplateChild<gtk::Label>,

Then, in the ObjectSubclass implementation you will need to call bind_template in the class_init function, and init_template in instance_init function.

impl ObjectSubclass for MyWidget {
       const NAME: &'static str = "MyWidget";
       type Type = super::MyWidget;
       type ParentType = gtk::Widget;

       fn class_init(klass: &mut Self::Class) {

       fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {