]> git.scottworley.com Git - batteryviewer/blob - batteryviewer.c
Keep the charts in State
[batteryviewer] / batteryviewer.c
1 #include "chart.h"
2 #include <gtk/gtk.h>
3
4 struct State {
5 BVChart *voltage;
6 BVChart *current;
7 };
8
9 static void activate(GtkApplication *app, gpointer user_data) {
10
11 GtkWidget *window = gtk_application_window_new(app);
12 gtk_window_set_title(GTK_WINDOW(window), "BatteryViewer");
13 gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
14
15 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
16 gtk_container_add(GTK_CONTAINER(window), box);
17
18 struct State *state = (struct State *)user_data;
19 state->voltage = BV_CHART(bv_chart_new());
20 bv_chart_add_point(state->voltage, 0.0, 0.0);
21 bv_chart_add_point(state->voltage, 1.0, 1.0);
22 bv_chart_add_point(state->voltage, 3.0, 2.0);
23 gboolean expand = TRUE;
24 gboolean fill = TRUE;
25 guint padding = 0;
26 gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(state->voltage), expand, fill,
27 padding);
28
29 state->current = BV_CHART(bv_chart_new());
30 bv_chart_add_point(state->current, 0.0, 1.0);
31 bv_chart_add_point(state->current, 1.0, 0.0);
32 gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(state->current), expand, fill,
33 padding);
34
35 gtk_widget_show_all(window);
36 }
37
38 int main(int argc, char **argv) {
39 struct State state;
40
41 GtkApplication *app = gtk_application_new("com.scottworley.batteryviewer",
42 G_APPLICATION_DEFAULT_FLAGS);
43 g_signal_connect(app, "activate", G_CALLBACK(activate), &state);
44 int status = g_application_run(G_APPLICATION(app), argc, argv);
45 g_object_unref(app);
46
47 return status;
48 }