INSTALL = install -D
INSTALL_PROGRAM = $(INSTALL)
-batteryviewer: batteryviewer.c
- gcc $(shell pkg-config --cflags gtk+-3.0) -o $@ $(CFLAGS) $< $(shell pkg-config --libs gtk+-3.0)
+batteryviewer: batteryviewer.c chart.c
+ gcc $(shell pkg-config --cflags gtk+-3.0) -o $@ $(CFLAGS) $^ $(shell pkg-config --libs gtk+-3.0)
all: batteryviewer
+#include "chart.h"
#include <gtk/gtk.h>
-static void print_hello(GtkWidget *widget __attribute__((unused)),
- gpointer data __attribute__((unused))) {
- g_print("Hello World\n");
-}
-
static void activate(GtkApplication *app,
gpointer user_data __attribute__((unused))) {
gtk_window_set_title(GTK_WINDOW(window), "Window");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
- GtkWidget *button_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
- gtk_container_add(GTK_CONTAINER(window), button_box);
+ GtkWidget *chart_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
+ gtk_container_add(GTK_CONTAINER(window), chart_box);
- GtkWidget *button = gtk_button_new_with_label("Hello World");
- g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
- g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy),
- window);
- gtk_container_add(GTK_CONTAINER(button_box), button);
+ GtkWidget *chart = bv_chart_new();
+ gtk_container_add(GTK_CONTAINER(chart_box), chart);
gtk_widget_show_all(window);
}
--- /dev/null
+/*
+ * h/t https://ptomato.name/advanced-gtk-techniques/html/custom-container.html
+ * for examples of how to make GTK widgets
+ */
+
+#include "chart.h"
+#include <gtk/gtk.h>
+
+#define BV_CHART_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), BV_CHART_TYPE, BVChartPrivate))
+
+typedef struct _BVChartPrivate BVChartPrivate;
+
+struct _BVChartPrivate {
+ int temp;
+};
+
+G_DEFINE_TYPE_WITH_CODE(BVChart, bv_chart, GTK_TYPE_DRAWING_AREA,
+ G_ADD_PRIVATE(BVChart))
+
+static void bv_chart_class_init(BVChartClass *klass __attribute__((unused))) {}
+
+static void bv_chart_init(BVChart *chart) {
+ gtk_widget_set_has_window(GTK_WIDGET(chart), FALSE);
+}
+
+GtkWidget *bv_chart_new() {
+ return GTK_WIDGET(g_object_new(bv_chart_get_type(), NULL));
+}
--- /dev/null
+#ifndef BV_CHART_H
+#define BV_CHART_H
+
+/*
+ * h/t https://ptomato.name/advanced-gtk-techniques/html/custom-container.html
+ * for examples of how to make GTK widgets
+ */
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BV_CHART_TYPE (bv_chart_get_type())
+#define BV_CHART(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), BV_CHART_TYPE, BVChart))
+#define BV_CHART_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), BV_CHART_TYPE, BVChartClass))
+#define BV_IS_CHART(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), BV_CHART_TYPE))
+#define BV_IS_CHART_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), BV_CHART_TYPE))
+
+typedef struct _BVChart BVChart;
+typedef struct _BVChartClass BVChartClass;
+
+struct _BVChart {
+ GtkDrawingArea parent_instance;
+};
+
+struct _BVChartClass {
+ GtkDrawingAreaClass parent_class;
+};
+
+GType bv_chart_get_type(void) G_GNUC_CONST;
+GtkWidget *bv_chart_new(void);
+
+G_END_DECLS
+
+#endif /* BV_CHART_H */