[libhandy/wip/exalm/leaflet-transltions: 33/37] stackable-box: Add child-visible-changed signal
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/exalm/leaflet-transltions: 33/37] stackable-box: Add child-visible-changed signal
- Date: Tue, 16 Jun 2020 12:44:30 +0000 (UTC)
commit f047ce680aa60f0388d2141700cfaea1f9d7e0f6
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri May 29 01:00:39 2020 +0500
stackable-box: Add child-visible-changed signal
This will be used as a replacement for transition-running that takes into
account visibility of each page individually.
Signed-off-by: Alexander Mikhaylenko <alexm gnome org>
src/hdy-stackable-box.c | 65 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 56 insertions(+), 9 deletions(-)
---
diff --git a/src/hdy-stackable-box.c b/src/hdy-stackable-box.c
index 1e50299b..bb0f7082 100644
--- a/src/hdy-stackable-box.c
+++ b/src/hdy-stackable-box.c
@@ -79,6 +79,11 @@ enum {
LAST_CHILD_PROP,
};
+enum {
+ SIGNAL_CHILD_VISIBLE_CHANGED,
+ SIGNAL_LAST_SIGNAL,
+};
+
#define HDY_FOLD_UNFOLDED FALSE
#define HDY_FOLD_FOLDED TRUE
#define HDY_FOLD_MAX 2
@@ -172,6 +177,7 @@ struct _HdyStackableBox
static GParamSpec *props[LAST_PROP];
static GParamSpec *child_props[LAST_CHILD_PROP];
+static guint signals[SIGNAL_LAST_SIGNAL];
static gint HOMOGENEOUS_PROP[HDY_FOLD_MAX][GTK_ORIENTATION_MAX] = {
{ PROP_HHOMOGENEOUS_UNFOLDED, PROP_VHOMOGENEOUS_UNFOLDED},
@@ -337,6 +343,26 @@ get_child_window_y (HdyStackableBox *self,
return 0;
}
+static void
+set_child_visible (HdyStackableBox *self,
+ HdyStackableBoxChildInfo *child_info,
+ gboolean visible)
+{
+ GtkWidget *widget;
+
+ if (!child_info || !child_info->widget)
+ return;
+
+ widget = child_info->widget;
+
+ if (gtk_widget_get_child_visible (widget) == visible)
+ return;
+
+ gtk_widget_set_child_visible (widget, visible);
+
+ g_signal_emit (self, signals[SIGNAL_CHILD_VISIBLE_CHANGED], 0, widget, visible);
+}
+
static void
hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
{
@@ -353,8 +379,8 @@ hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
if (self->child_transition.is_cancelled) {
if (self->last_visible_child != NULL) {
if (self->folded) {
- gtk_widget_set_child_visible (self->last_visible_child->widget, TRUE);
- gtk_widget_set_child_visible (self->visible_child->widget, FALSE);
+ set_child_visible (self, self->last_visible_child, TRUE);
+ set_child_visible (self, self->visible_child, FALSE);
}
self->visible_child = self->last_visible_child;
self->last_visible_child = NULL;
@@ -369,7 +395,7 @@ hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
} else {
if (self->last_visible_child != NULL) {
if (self->folded)
- gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+ set_child_visible (self, self->last_visible_child, FALSE);
self->last_visible_child = NULL;
}
}
@@ -444,7 +470,7 @@ hdy_stackable_box_stop_child_transition (HdyStackableBox *self)
self->child_transition.active_type = HDY_STACKABLE_BOX_TRANSITION_TYPE_NONE;
gtk_progress_tracker_finish (&self->child_transition.tracker);
if (self->last_visible_child != NULL) {
- gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
+ set_child_visible (self, self->last_visible_child, FALSE);
self->last_visible_child = NULL;
}
@@ -547,7 +573,7 @@ set_visible_child_info (HdyStackableBox *self,
/* } */
if (self->last_visible_child)
- gtk_widget_set_child_visible (self->last_visible_child->widget, !self->folded);
+ set_child_visible (self, self->last_visible_child, !self->folded);
self->last_visible_child = NULL;
hdy_shadow_helper_clear_cache (self->shadow_helper);
@@ -556,7 +582,7 @@ set_visible_child_info (HdyStackableBox *self,
if (gtk_widget_is_visible (widget))
self->last_visible_child = self->visible_child;
else
- gtk_widget_set_child_visible (self->visible_child->widget, !self->folded);
+ set_child_visible (self, self->visible_child, !self->folded);
}
/* FIXME This comes from GtkStack and should be adapted. */
@@ -567,7 +593,7 @@ set_visible_child_info (HdyStackableBox *self,
self->visible_child = new_visible_child;
if (new_visible_child) {
- gtk_widget_set_child_visible (new_visible_child->widget, TRUE);
+ set_child_visible (self, new_visible_child, TRUE);
/* FIXME This comes from GtkStack and should be adapted. */
/* if (contains_focus) { */
@@ -2061,7 +2087,7 @@ hdy_stackable_box_size_allocate (HdyStackableBox *self,
child_info = children->data;
- gtk_widget_set_child_visible (child_info->widget, child_info->visible);
+ set_child_visible (self, child_info, child_info->visible);
if (child_info->window &&
child_info->visible != gdk_window_is_visible (child_info->window)) {
@@ -2250,7 +2276,7 @@ hdy_stackable_box_child_visibility_notify_cb (GObject *obj,
set_visible_child_info (self, NULL, self->transition_type, self->child_transition.duration, TRUE);
if (child_info == self->last_visible_child) {
- gtk_widget_set_child_visible (self->last_visible_child->widget, !self->folded);
+ set_child_visible (self, self->last_visible_child, !self->folded);
self->last_visible_child = NULL;
}
}
@@ -3075,6 +3101,27 @@ hdy_stackable_box_class_init (HdyStackableBoxClass *klass)
_("The name of the child page"),
NULL,
G_PARAM_READWRITE);
+
+ /**
+ * HdyStackableBox::child-visible-changed:
+ * @self: The #HdyStackableBox instance
+ * @child: The child
+ * @visible: The new value
+ *
+ * This signal is emitted after a child has been shown or hidden.
+ *
+ * Since: 1.0
+ */
+ signals[SIGNAL_CHILD_VISIBLE_CHANGED] =
+ g_signal_new ("child-visible-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 2,
+ GTK_TYPE_WIDGET,
+ G_TYPE_BOOLEAN);
}
HdyStackableBox *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]