[gtk+/gtk-3-22] gtkplacesviewrow: stop busy_spinner from offsetting the other widgets when visible
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] gtkplacesviewrow: stop busy_spinner from offsetting the other widgets when visible
- Date: Mon, 10 Oct 2016 19:14:57 +0000 (UTC)
commit bfc6287910011002cda3eb90b149b70eef4f9f47
Author: djb <db0451 gmail com>
Date: Sun Oct 2 23:16:46 2016 +0100
gtkplacesviewrow: stop busy_spinner from offsetting the other widgets when visible
...by putting it in a stack. The busy_spinner and eject_button are
mutually exclusive, but only the latter was coded to ensure that its
visibility did not cause the rest of the row to reflow. By putting both
widgets in a stack and setting child_visible on that, the row allocates
enough space to show one - or none - at once, avoiding any misalignment.
https://bugzilla.gnome.org/show_bug.cgi?id=772345
https://bugzilla.gnome.org/show_bug.cgi?id=772348
gtk/gtkplacesviewrow.c | 31 ++++++++++++++++++++---------
gtk/ui/gtkplacesviewrow.ui | 45 +++++++++++++++++++++++++------------------
2 files changed, 47 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
index 8f54ee6..61dd1f5 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -33,6 +33,7 @@
#include "gtkintl.h"
#include "gtklabel.h"
#include "gtkspinner.h"
+#include "gtkstack.h"
#include "gtktypebuiltins.h"
#else
#include <gtk/gtk.h>
@@ -43,6 +44,7 @@ struct _GtkPlacesViewRow
GtkListBoxRow parent_instance;
GtkLabel *available_space_label;
+ GtkStack *mount_stack;
GtkSpinner *busy_spinner;
GtkButton *eject_button;
GtkImage *eject_icon;
@@ -285,15 +287,15 @@ gtk_places_view_row_set_property (GObject *object,
case PROP_MOUNT:
g_set_object (&self->mount, g_value_get_object (value));
-
- /*
- * When we hide the eject button, no size is allocated for it. Since
- * we want to have alignment between rows, it needs an empty space
- * when the eject button is not available. So, call then
- * gtk_widget_set_child_visible(), which makes the button allocate the
- * size but it stays hidden when needed.
- */
- gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
+ if (self->mount != NULL)
+ {
+ gtk_stack_set_visible_child (self->mount_stack, GTK_WIDGET (self->eject_button));
+ gtk_widget_set_child_visible (GTK_WIDGET (self->mount_stack), TRUE);
+ }
+ else
+ {
+ gtk_widget_set_child_visible (GTK_WIDGET (self->mount_stack), FALSE);
+ }
measure_available_space (self);
break;
@@ -376,6 +378,7 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkplacesviewrow.ui");
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, available_space_label);
+ gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, mount_stack);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, busy_spinner);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, eject_button);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, eject_icon);
@@ -447,7 +450,15 @@ gtk_places_view_row_set_busy (GtkPlacesViewRow *row,
{
g_return_if_fail (GTK_IS_PLACES_VIEW_ROW (row));
- gtk_widget_set_visible (GTK_WIDGET (row->busy_spinner), is_busy);
+ if (is_busy)
+ {
+ gtk_stack_set_visible_child (row->mount_stack, GTK_WIDGET (row->busy_spinner));
+ gtk_widget_set_child_visible (GTK_WIDGET (row->mount_stack), TRUE);
+ }
+ else
+ {
+ gtk_widget_set_child_visible (GTK_WIDGET (row->mount_stack), FALSE);
+ }
}
gboolean
diff --git a/gtk/ui/gtkplacesviewrow.ui b/gtk/ui/gtkplacesviewrow.ui
index e39aa0a..cce5732 100644
--- a/gtk/ui/gtkplacesviewrow.ui
+++ b/gtk/ui/gtkplacesviewrow.ui
@@ -60,35 +60,42 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="eject_button">
+ <object class="GtkStack" id="mount_stack">
<property name="visible">1</property>
- <property name="halign">end</property>
- <property name="valign">center</property>
- <property name="tooltip-text" translatable="yes">Unmount</property>
+ <property name="hhomogeneous">1</property>
+ <property name="vhomogeneous">1</property>
<child>
- <object class="GtkImage" id="eject_icon">
+ <object class="GtkButton" id="eject_button">
<property name="visible">1</property>
- <property name="icon-name">media-eject-symbolic</property>
- <property name="icon-size">1</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="tooltip-text" translatable="yes">Unmount</property>
+ <child>
+ <object class="GtkImage" id="eject_icon">
+ <property name="visible">1</property>
+ <property name="icon-name">media-eject-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="image-button"/>
+ <class name="sidebar-button"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinner" id="busy_spinner">
+ <property name="visible">1</property>
+ <property name="active">1</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
</object>
</child>
- <style>
- <class name="image-button"/>
- <class name="sidebar-button"/>
- </style>
</object>
<packing>
<property name="position">4</property>
</packing>
</child>
- <child>
- <object class="GtkSpinner" id="busy_spinner">
- <property name="active">1</property>
- </object>
- <packing>
- <property name="position">5</property>
- </packing>
- </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]