[gtk+] gtk-demo: Allow locking of icon count in fishbowl demo
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk-demo: Allow locking of icon count in fishbowl demo
- Date: Sun, 20 Nov 2016 04:31:49 +0000 (UTC)
commit 1912d992d88f4c9e02207329b73c3474dd72817d
Author: Benjamin Otte <otte redhat com>
Date: Sun Nov 20 05:29:03 2016 +0100
gtk-demo: Allow locking of icon count in fishbowl demo
I'm not sure I'm proud of the hack to get the changing icon into the UI
file without having to write code. But it works.
demos/gtk-demo/fishbowl.c | 25 ++++++++++++++++---------
demos/gtk-demo/fishbowl.ui | 22 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/fishbowl.c b/demos/gtk-demo/fishbowl.c
index 9350e4e..766bcdc 100644
--- a/demos/gtk-demo/fishbowl.c
+++ b/demos/gtk-demo/fishbowl.c
@@ -10,6 +10,8 @@
char **icon_names = NULL;
gsize n_icon_names = 0;
+GtkWidget *allow_changes;
+
static void
init_icon_names (GtkIconTheme *theme)
{
@@ -24,7 +26,7 @@ init_icon_names (GtkIconTheme *theme)
for (l = icon_list; l; l = l->next)
{
- if (g_str_has_suffix (l->data, "-symbolic"))
+ if (g_str_has_suffix (l->data, "symbolic"))
continue;
g_ptr_array_add (icons, g_strdup (l->data));
@@ -119,7 +121,6 @@ do_stats (GtkWidget *widget,
stats->last_suggestion *= 2;
else
stats->last_suggestion = 1;
- *suggested_change = stats->last_suggestion;
}
else
{
@@ -128,17 +129,22 @@ do_stats (GtkWidget *widget,
else
stats->last_suggestion = -1;
stats->last_suggestion = MAX (stats->last_suggestion, 1 - (int)
stats->item_counter[stats->stats_index]);
- *suggested_change = stats->last_suggestion;
}
stats->stats_index = (stats->stats_index + 1) % N_STATS;
stats->frame_counter[stats->stats_index] = 0;
stats->item_counter[stats->stats_index] = stats->item_counter[(stats->stats_index + N_STATS - 1) %
N_STATS];
stats->last_stats = frame_time;
+
+ if (suggested_change)
+ *suggested_change = stats->last_suggestion;
+ else
+ stats->last_suggestion = 0;
}
else
{
- *suggested_change = 0;
+ if (suggested_change)
+ *suggested_change = 0;
}
stats->last_frame = frame_time;
@@ -284,9 +290,11 @@ move_fish (GtkWidget *bowl,
gpointer info_label)
{
gint64 elapsed;
- gint suggested_change;
+ gint suggested_change = 0;
- elapsed = do_stats (bowl, info_label, &suggested_change);
+ elapsed = do_stats (bowl,
+ info_label,
+ !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (allow_changes)) ? &suggested_change
: NULL);
gtk_container_foreach (GTK_CONTAINER (bowl), move_one_fish, &elapsed);
@@ -313,6 +321,7 @@ do_fishbowl (GtkWidget *do_widget)
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
bowl = GTK_WIDGET (gtk_builder_get_object (builder, "bowl"));
info_label = GTK_WIDGET (gtk_builder_get_object (builder, "info_label"));
+ allow_changes = GTK_WIDGET (gtk_builder_get_object (builder, "changes_allow"));
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (do_widget));
g_signal_connect (window, "destroy",
@@ -320,12 +329,10 @@ do_fishbowl (GtkWidget *do_widget)
gtk_widget_realize (window);
gtk_widget_add_tick_callback (bowl, move_fish, info_label, NULL);
-
- //add_fish (bowl, 300);
}
if (!gtk_widget_get_visible (window))
- gtk_widget_show_all (window);
+ gtk_widget_show (window);
else
gtk_widget_destroy (window);
diff --git a/demos/gtk-demo/fishbowl.ui b/demos/gtk-demo/fishbowl.ui
index e46851b..f578085 100644
--- a/demos/gtk-demo/fishbowl.ui
+++ b/demos/gtk-demo/fishbowl.ui
@@ -16,6 +16,28 @@
<property name="pack_type">end</property>
</packing>
</child>
+ <child>
+ <object class="GtkToggleButton" id="changes_allow">
+ <property name="active">False</property>
+ <property name="visible" bind-source="changes_allow" bind-property="active"
bind-flags="invert-boolean">True</property>
+ <property name="icon-name">changes-allow</property>
+ <property name="relief">none</property>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="changes_prevent">
+ <property name="active" bind-source="changes_allow" bind-property="active"
bind-flags="bidirectional|invert-boolean">True</property>
+ <property name="visible" bind-source="changes_prevent" bind-property="active"
bind-flags="invert-boolean">False</property>
+ <property name="icon-name">changes-prevent</property>
+ <property name="relief">none</property>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]