Skip to content

Instantly share code, notes, and snippets.

@jtanx
Created March 24, 2019 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtanx/dac8542dde64143794ac27504295fcb8 to your computer and use it in GitHub Desktop.
Save jtanx/dac8542dde64143794ac27504295fcb8 to your computer and use it in GitHub Desktop.
Minimal GTK custom widget implementation
#include "ggtkwindow.h"
// Define the structure of the type
struct _GGtkWindow
{
GtkLayout parent_instance;
// private data here
// because this is a final type, I don't need to use G_DEFINE_TYPE_WITH_PRIVATE
// and jump through all the hoops that entails. That is required
// when this can be derivable, because otherwise changing private members
// would affect the size of the struct (and hence ABI compatibility)
};
static void ggtk_window_class_init(GGtkWindowClass *a)
{
// Used to initialise property getters/setters and virtual functions
// https://developer.gnome.org/gobject/stable/howto-gobject-methods.html#virtual-public-methods
}
static void ggtk_window_init(GGtkWindow *a)
{
// Used to perform initialisation of an instance of this object
}
GtkWidget* ggtk_window_new(void)
{
return GTK_WIDGET(GGTK_WINDOW(g_object_new(GGTK_TYPE_WINDOW, NULL)));
}
G_DEFINE_TYPE(GGtkWindow, ggtk_window, GTK_TYPE_LAYOUT)
#include <gtk/gtk.h>
#ifndef __GGTK_WINDOW_H
#define _GGTK_WINDOW_H
#define GGTK_TYPE_WINDOW ggtk_window_get_type()
G_DECLARE_FINAL_TYPE(GGtkWindow, ggtk_window, GGTK, WINDOW, GtkLayout)
struct _GGtkWindowClass
{
GtkLayoutClass parent_class;
// virtual methods here, no pad because screw ABI compat, it's internal
};
#endif __GTTK_WINDOW_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment