Reputation: 67
Im trying to understand the fundamentals of this basic GTK program. I can't figure out how G_DEFINE_TYPE
works. It looks similar to a function declaration like those in C`
struct _LearnWindow
{
GtkApplicationWindow parent_instance;
/* Template widgets */
GtkHeaderBar *header_bar;
GtkLabel *label;
};
G_DEFINE_TYPE (LearnWindow, learn_window, GTK_TYPE_APPLICATION_WINDOW)
static void
learn_window_class_init (LearnWindowClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Learn/learn-window.ui");
gtk_widget_class_bind_template_child (widget_class, LearnWindow, header_bar);
gtk_widget_class_bind_template_child (widget_class, LearnWindow, label);
}
static void
learn_window_init (LearnWindow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
Upvotes: 5
Views: 3243
Reputation: 28830
As per the documentation
#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
A convenience macro for type implementations, which declares a class initialization function, an instance initialization function (see GTypeInfo for information about these) and a static variable named t_n_parent_class pointing to the parent class. Furthermore, it defines a *_get_type() function.
Upvotes: 3