diff --git a/data/gwr-window.ui b/data/gwr-window.ui index 68f6dee..f9eddca 100644 --- a/data/gwr-window.ui +++ b/data/gwr-window.ui @@ -22,6 +22,7 @@ True True True + win.add True diff --git a/src/gwr-water-level.c b/src/gwr-water-level.c index d514e27..58324f9 100644 --- a/src/gwr-water-level.c +++ b/src/gwr-water-level.c @@ -32,7 +32,19 @@ void gwr_water_level_set_level(GwrWaterLevel *self, gfloat level) { - self->level = MAX(0, MIN(level, 1.0)); + g_debug("Setting level to %.2f", level); + + if (G_UNLIKELY(level > 1.0)) { + g_warning("Value (%.2f) is too large. Scaling down to 1.0", level); + level = 1.0; + } else if (G_UNLIKELY(level < 0.0)) { + g_warning("Value (%.2f) is too small. Scaling up to 0.0", level); + level = 0.0; + } + + self->level = level; + + gtk_widget_queue_draw(GTK_WIDGET(self)); g_object_notify_by_pspec(G_OBJECT(self), props[PROP_LEVEL]); } diff --git a/src/gwr-window.c b/src/gwr-window.c index b45602c..042aae8 100644 --- a/src/gwr-window.c +++ b/src/gwr-window.c @@ -31,6 +31,14 @@ struct _GwrWindow G_DEFINE_TYPE (GwrWindow, gwr_window, GTK_TYPE_APPLICATION_WINDOW) +static void gwr_window_add_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data); + +static GActionEntry win_entries[] = { + { "add", gwr_window_add_action, NULL, NULL, NULL }, +}; + static void gwr_window_class_init (GwrWindowClass *klass) { @@ -47,4 +55,16 @@ gwr_window_init (GwrWindow *self) g_type_ensure(GWR_TYPE_WATER_LEVEL); gtk_widget_init_template (GTK_WIDGET (self)); + + g_action_map_add_action_entries(G_ACTION_MAP(self), win_entries, G_N_ELEMENTS(win_entries), self); +} + +static void + gwr_window_add_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GwrWindow *self = GWR_WINDOW(user_data); + + gwr_water_level_set_level (self->level, gwr_water_level_get_level (self->level) + 0.1); }