Add some informative labels about water levels

This commit is contained in:
Gergely Polonkai 2018-07-27 20:29:09 +02:00
parent 5260efb552
commit 0c5fa3a539
2 changed files with 77 additions and 8 deletions

View File

@ -7,19 +7,19 @@
<property name="default_width">600</property>
<property name="default_height">300</property>
<child>
<object class="GtkBox">
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GwrWaterLevel" id="remaining">
<property name="visible">True</property>
<property name="level">1.0</property>
<property name="style">bottle</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
@ -28,9 +28,50 @@
<property name="level">0.0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Remaining</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hydration level</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="remaining_value">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="current_value">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>

View File

@ -17,6 +17,8 @@
*/
#include "gwr-config.h"
#include <glib/gi18n-lib.h>
#include "gwr-window.h"
#include "gwr-water-level.h"
@ -28,6 +30,9 @@ struct _GwrWindow
GtkHeaderBar *header_bar;
GwrWaterLevel *level;
GwrWaterLevel *remaining;
GtkLabel *remaining_value;
GtkLabel *current_value;
};
G_DEFINE_TYPE (GwrWindow, gwr_window, GTK_TYPE_APPLICATION_WINDOW)
@ -49,6 +54,23 @@ gwr_window_class_init (GwrWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GwrWindow, header_bar);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, level);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, remaining);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, current_value);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, remaining_value);
}
static void
level_changed(GwrWaterLevel *level,
GParamSpec *pspec,
GwrWindow *self)
{
gchar *text;
GtkLabel *label = (level == self->level) ? self->current_value : self->remaining_value;
g_debug("level changed");
text = g_strdup_printf(_("Value: %.0f%%"), gwr_water_level_get_level (level) * 100);
gtk_label_set_text(label, text);
g_free(text);
}
static void
@ -59,6 +81,12 @@ gwr_window_init (GwrWindow *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);
g_signal_connect(self->level, "notify::level", G_CALLBACK(level_changed), self);
g_signal_connect(self->remaining, "notify::level", G_CALLBACK(level_changed), self);
level_changed(self->level, NULL, self);
level_changed(self->remaining, NULL, self);
}
static void