Created
March 24, 2019 03:16
-
-
Save jtanx/dac8542dde64143794ac27504295fcb8 to your computer and use it in GitHub Desktop.
Minimal GTK custom widget implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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