Add a button to increase water level
This commit is contained in:
parent
1ca33bdd9d
commit
1503eea2d2
@ -22,6 +22,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
|
<property name="action_name">win.add</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage">
|
<object class="GtkImage">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -32,7 +32,19 @@ void
|
|||||||
gwr_water_level_set_level(GwrWaterLevel *self,
|
gwr_water_level_set_level(GwrWaterLevel *self,
|
||||||
gfloat level)
|
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]);
|
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_LEVEL]);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,14 @@ struct _GwrWindow
|
|||||||
|
|
||||||
G_DEFINE_TYPE (GwrWindow, gwr_window, GTK_TYPE_APPLICATION_WINDOW)
|
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
|
static void
|
||||||
gwr_window_class_init (GwrWindowClass *klass)
|
gwr_window_class_init (GwrWindowClass *klass)
|
||||||
{
|
{
|
||||||
@ -47,4 +55,16 @@ gwr_window_init (GwrWindow *self)
|
|||||||
g_type_ensure(GWR_TYPE_WATER_LEVEL);
|
g_type_ensure(GWR_TYPE_WATER_LEVEL);
|
||||||
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user