[libadwaita/wip/exalm/fixes: 3/5] Implement compute_expand() for widgets that have children




commit eb0251d3e282528c19b8d7fbf5980f501101757f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Aug 9 19:55:40 2021 +0500

    Implement compute_expand() for widgets that have children
    
    Other than listbox rows. We never want to expand those.
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/69

 src/adw-bin.c                  |  4 ++++
 src/adw-carousel.c             |  2 ++
 src/adw-clamp-scrollable.c     |  3 +++
 src/adw-clamp.c                |  3 +++
 src/adw-flap.c                 |  2 ++
 src/adw-gizmo.c                |  5 +++--
 src/adw-header-bar.c           |  1 +
 src/adw-indicator-bin.c        |  2 ++
 src/adw-leaflet.c              |  2 ++
 src/adw-preferences-group.c    |  3 +++
 src/adw-preferences-page.c     |  3 +++
 src/adw-squeezer.c             | 36 ++----------------------------------
 src/adw-status-page.c          |  4 ++++
 src/adw-tab-bar.c              |  2 ++
 src/adw-tab-view.c             |  3 +++
 src/adw-view-stack.c           | 34 +---------------------------------
 src/adw-widget-utils-private.h |  8 ++++++++
 src/adw-widget-utils.c         | 37 +++++++++++++++++++++++++++++++++++++
 18 files changed, 85 insertions(+), 69 deletions(-)
---
diff --git a/src/adw-bin.c b/src/adw-bin.c
index 1d7baf3d..a6f6fdcc 100644
--- a/src/adw-bin.c
+++ b/src/adw-bin.c
@@ -9,6 +9,8 @@
 #include "config.h"
 #include "adw-bin.h"
 
+#include "adw-widget-utils-private.h"
+
 /**
  * AdwBin:
  *
@@ -99,6 +101,8 @@ adw_bin_class_init (AdwBinClass *klass)
   object_class->get_property = adw_bin_get_property;
   object_class->set_property = adw_bin_set_property;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   /**
    * AdwBin:child: (attributes org.gtk.Property.get=adw_bin_get_child org.gtk.Property.set=adw_bin_set_child)
    *
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 3343be02..2d2c708c 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -13,6 +13,7 @@
 #include "adw-navigation-direction.h"
 #include "adw-swipe-tracker.h"
 #include "adw-swipeable.h"
+#include "adw-widget-utils-private.h"
 
 #include <math.h>
 
@@ -872,6 +873,7 @@ adw_carousel_class_init (AdwCarouselClass *klass)
   widget_class->measure = adw_carousel_measure;
   widget_class->size_allocate = adw_carousel_size_allocate;
   widget_class->direction_changed = adw_carousel_direction_changed;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   /**
    * AdwCarousel:n-pages: (attributes org.gtk.Property.get=adw_carousel_get_n_pages)
diff --git a/src/adw-clamp-scrollable.c b/src/adw-clamp-scrollable.c
index 85c423d3..71ceaa06 100644
--- a/src/adw-clamp-scrollable.c
+++ b/src/adw-clamp-scrollable.c
@@ -8,6 +8,7 @@
 #include "adw-clamp-scrollable.h"
 
 #include "adw-clamp-layout.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwClampScrollable:
@@ -229,6 +230,8 @@ adw_clamp_scrollable_class_init (AdwClampScrollableClass *klass)
   object_class->set_property = adw_clamp_scrollable_set_property;
   object_class->dispose = adw_clamp_scrollable_dispose;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
                                     "orientation");
diff --git a/src/adw-clamp.c b/src/adw-clamp.c
index b48a802c..5cba5c13 100644
--- a/src/adw-clamp.c
+++ b/src/adw-clamp.c
@@ -8,6 +8,7 @@
 #include "adw-clamp.h"
 
 #include "adw-clamp-layout.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwClamp:
@@ -153,6 +154,8 @@ adw_clamp_class_init (AdwClampClass *klass)
   object_class->set_property = adw_clamp_set_property;
   object_class->dispose = adw_clamp_dispose;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
                                     "orientation");
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 633dfe68..5a482087 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -16,6 +16,7 @@
 #include "adw-shadow-helper-private.h"
 #include "adw-swipeable.h"
 #include "adw-swipe-tracker-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwFlap:
@@ -1261,6 +1262,7 @@ adw_flap_class_init (AdwFlapClass *klass)
   widget_class->size_allocate = adw_flap_size_allocate;
   widget_class->snapshot = adw_flap_snapshot;
   widget_class->direction_changed = adw_flap_direction_changed;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   /**
    * AdwFlap:content: (attributes org.gtk.Property.get=adw_flap_get_content 
org.gtk.Property.set=adw_flap_set_content)
diff --git a/src/adw-gizmo.c b/src/adw-gizmo.c
index c1a50f70..f50c31de 100644
--- a/src/adw-gizmo.c
+++ b/src/adw-gizmo.c
@@ -7,10 +7,10 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-
-
 #include "adw-gizmo-private.h"
 
+#include "adw-widget-utils-private.h"
+
 struct _AdwGizmo
 {
   GtkWidget parent_instance;
@@ -133,6 +133,7 @@ adw_gizmo_class_init (AdwGizmoClass *klass)
   widget_class->contains = adw_gizmo_contains;
   widget_class->grab_focus = adw_gizmo_grab_focus;
   widget_class->focus = adw_gizmo_focus;
+  widget_class->compute_expand = adw_widget_compute_expand;
 }
 
 static void
diff --git a/src/adw-header-bar.c b/src/adw-header-bar.c
index 93418584..16c8808b 100644
--- a/src/adw-header-bar.c
+++ b/src/adw-header-bar.c
@@ -414,6 +414,7 @@ adw_header_bar_class_init (AdwHeaderBarClass *class)
   widget_class->root = adw_header_bar_root;
   widget_class->unroot = adw_header_bar_unroot;
   widget_class->get_request_mode = adw_header_bar_get_request_mode;
+  widget_class->compute_expand = adw_widget_compute_expand_horizontal_only;
 
   /**
    * AdwHeaderBar:title-widget: (attributes org.gtk.Property.get=adw_header_bar_get_title_widget 
org.gtk.Property.set=adw_header_bar_set_title_widget)
diff --git a/src/adw-indicator-bin.c b/src/adw-indicator-bin.c
index 050edfce..f4993d7f 100644
--- a/src/adw-indicator-bin.c
+++ b/src/adw-indicator-bin.c
@@ -10,6 +10,7 @@
 #include "adw-indicator-bin-private.h"
 
 #include "adw-gizmo-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwIndicatorBin:
@@ -280,6 +281,7 @@ adw_indicator_bin_class_init (AdwIndicatorBinClass *klass)
   widget_class->size_allocate = adw_indicator_bin_size_allocate;
   widget_class->snapshot = adw_indicator_bin_snapshot;
   widget_class->unrealize = adw_indicator_bin_unrealize;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   /**
    * AdwIndicatorBin:child:
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index a0f1482e..07c1d792 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -16,6 +16,7 @@
 #include "adw-shadow-helper-private.h"
 #include "adw-swipeable.h"
 #include "adw-swipe-tracker-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwLeaflet:
@@ -2306,6 +2307,7 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
   widget_class->size_allocate = adw_leaflet_size_allocate;
   widget_class->snapshot = adw_leaflet_snapshot;
   widget_class->direction_changed = adw_leaflet_direction_changed;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
diff --git a/src/adw-preferences-group.c b/src/adw-preferences-group.c
index 5e2b2108..af456687 100644
--- a/src/adw-preferences-group.c
+++ b/src/adw-preferences-group.c
@@ -10,6 +10,7 @@
 
 #include "adw-macros-private.h"
 #include "adw-preferences-row.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwPreferencesGroup:
@@ -171,6 +172,8 @@ adw_preferences_group_class_init (AdwPreferencesGroupClass *klass)
   object_class->set_property = adw_preferences_group_set_property;
   object_class->dispose = adw_preferences_group_dispose;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   /**
    * AdwPreferencesGroup:description: (attributes org.gtk.Property.get=adw_preferences_group_get_description 
org.gtk.Property.set=adw_preferences_group_set_description)
    *
diff --git a/src/adw-preferences-page.c b/src/adw-preferences-page.c
index 84bab7c8..d8550deb 100644
--- a/src/adw-preferences-page.c
+++ b/src/adw-preferences-page.c
@@ -10,6 +10,7 @@
 
 #include "adw-macros-private.h"
 #include "adw-preferences-group-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwPreferencesPage:
@@ -146,6 +147,8 @@ adw_preferences_page_class_init (AdwPreferencesPageClass *klass)
   object_class->dispose = adw_preferences_page_dispose;
   object_class->finalize = adw_preferences_page_finalize;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   /**
    * AdwPreferencesPage:icon-name: (attributes org.gtk.Property.get=adw_preferences_page_get_icon_name 
org.gtk.Property.set=adw_preferences_page_set_icon_name)
    *
diff --git a/src/adw-squeezer.c b/src/adw-squeezer.c
index c3029baf..c0c245e6 100644
--- a/src/adw-squeezer.c
+++ b/src/adw-squeezer.c
@@ -21,6 +21,7 @@
 #include "gtkprogresstrackerprivate.h"
 #include "adw-animation-util-private.h"
 #include "adw-animation-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwSqueezer:
@@ -774,39 +775,6 @@ adw_squeezer_set_property (GObject      *object,
   }
 }
 
-static void
-adw_squeezer_compute_expand (GtkWidget *widget,
-                             gboolean  *hexpand_p,
-                             gboolean  *vexpand_p)
-{
-  AdwSqueezer *self = ADW_SQUEEZER (widget);
-  gboolean hexpand, vexpand;
-  AdwSqueezerPage *page;
-  GtkWidget *child;
-  GList *l;
-
-  hexpand = FALSE;
-  vexpand = FALSE;
-  for (l = self->children; l != NULL; l = l->next) {
-    page = l->data;
-    child = page->widget;
-
-    if (!hexpand &&
-        gtk_widget_compute_expand (child, GTK_ORIENTATION_HORIZONTAL))
-      hexpand = TRUE;
-
-    if (!vexpand &&
-        gtk_widget_compute_expand (child, GTK_ORIENTATION_VERTICAL))
-      vexpand = TRUE;
-
-    if (hexpand && vexpand)
-      break;
-  }
-
-  *hexpand_p = hexpand;
-  *vexpand_p = vexpand;
-}
-
 static void
 adw_squeezer_snapshot_crossfade (GtkWidget   *widget,
                                  GtkSnapshot *snapshot)
@@ -1098,7 +1066,7 @@ adw_squeezer_class_init (AdwSqueezerClass *klass)
   widget_class->size_allocate = adw_squeezer_size_allocate;
   widget_class->snapshot = adw_squeezer_snapshot;
   widget_class->measure = adw_squeezer_measure;
-  widget_class->compute_expand = adw_squeezer_compute_expand;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
diff --git a/src/adw-status-page.c b/src/adw-status-page.c
index 4aaa3c63..6b847cb9 100644
--- a/src/adw-status-page.c
+++ b/src/adw-status-page.c
@@ -8,6 +8,8 @@
 
 #include "adw-status-page.h"
 
+#include "adw-widget-utils-private.h"
+
 /**
  * AdwStatusPage:
  *
@@ -159,6 +161,8 @@ adw_status_page_class_init (AdwStatusPageClass *klass)
   object_class->dispose = adw_status_page_dispose;
   object_class->finalize = adw_status_page_finalize;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   /**
    * AdwStatusPage:icon-name: (attributes org.gtk.Property.get=adw_status_page_get_icon_name 
org.gtk.Property.set=adw_status_page_set_icon_name)
    *
diff --git a/src/adw-tab-bar.c b/src/adw-tab-bar.c
index 3c97338b..f1baaa71 100644
--- a/src/adw-tab-bar.c
+++ b/src/adw-tab-bar.c
@@ -12,6 +12,7 @@
 
 #include "adw-bin.h"
 #include "adw-tab-box-private.h"
+#include "adw-widget-utils-private.h"
 
 /**
  * AdwTabBar:
@@ -435,6 +436,7 @@ adw_tab_bar_class_init (AdwTabBarClass *klass)
   object_class->set_property = adw_tab_bar_set_property;
 
   widget_class->focus = adw_tab_bar_focus;
+  widget_class->compute_expand = adw_widget_compute_expand;
 
   /**
    * AdwTabBar:view: (attributes org.gtk.Property.get=adw_tab_bar_get_view 
org.gtk.Property.set=adw_tab_bar_set_view)
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index 57af6a6c..f436d9ae 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -11,6 +11,7 @@
 #include "adw-tab-view-private.h"
 
 #include "adw-gizmo-private.h"
+#include "adw-widget-utils-private.h"
 
 /* FIXME replace with groups */
 static GSList *tab_view_list;
@@ -1394,6 +1395,8 @@ adw_tab_view_class_init (AdwTabViewClass *klass)
   object_class->get_property = adw_tab_view_get_property;
   object_class->set_property = adw_tab_view_set_property;
 
+  widget_class->compute_expand = adw_widget_compute_expand;
+
   /**
    * AdwTabView:n-pages: (attributes org.gtk.Property.get=adw_tab_view_get_n_pages)
    *
diff --git a/src/adw-view-stack.c b/src/adw-view-stack.c
index cd4d2f50..ceff2165 100644
--- a/src/adw-view-stack.c
+++ b/src/adw-view-stack.c
@@ -882,38 +882,6 @@ stack_remove (AdwViewStack  *self,
     gtk_widget_queue_resize (GTK_WIDGET (self));
 }
 
-static void
-adw_view_stack_compute_expand (GtkWidget *widget,
-                               gboolean  *hexpand_p,
-                               gboolean  *vexpand_p)
-{
-  AdwViewStack *self = ADW_VIEW_STACK (widget);
-  gboolean hexpand, vexpand;
-  GList *l;
-
-  hexpand = FALSE;
-  vexpand = FALSE;
-
-  for (l = self->children; l; l = l->next) {
-    AdwViewStackPage *page = l->data;
-    GtkWidget *child = page->widget;
-
-    if (!hexpand &&
-        gtk_widget_compute_expand (child, GTK_ORIENTATION_HORIZONTAL))
-      hexpand = TRUE;
-
-    if (!vexpand &&
-        gtk_widget_compute_expand (child, GTK_ORIENTATION_VERTICAL))
-      vexpand = TRUE;
-
-    if (hexpand && vexpand)
-      break;
-  }
-
-  *hexpand_p = hexpand;
-  *vexpand_p = vexpand;
-}
-
 static GtkSizeRequestMode
 adw_view_stack_get_request_mode (GtkWidget *widget)
 {
@@ -1212,7 +1180,7 @@ adw_view_stack_class_init (AdwViewStackClass *klass)
   widget_class->size_allocate = adw_view_stack_size_allocate;
   widget_class->snapshot = adw_view_stack_snapshot;
   widget_class->measure = adw_view_stack_measure;
-  widget_class->compute_expand = adw_view_stack_compute_expand;
+  widget_class->compute_expand = adw_widget_compute_expand;
   widget_class->get_request_mode = adw_view_stack_get_request_mode;
 
   /**
diff --git a/src/adw-widget-utils-private.h b/src/adw-widget-utils-private.h
index c7a47917..d9db1103 100644
--- a/src/adw-widget-utils-private.h
+++ b/src/adw-widget-utils-private.h
@@ -31,4 +31,12 @@ gboolean adw_widget_focus_child (GtkWidget        *widget,
 gboolean adw_widget_grab_focus_self  (GtkWidget *widget);
 gboolean adw_widget_grab_focus_child (GtkWidget *widget);
 
+void adw_widget_compute_expand (GtkWidget *widget,
+                                gboolean  *hexpand_p,
+                                gboolean  *vexpand_p);
+
+void adw_widget_compute_expand_horizontal_only (GtkWidget *widget,
+                                                gboolean  *hexpand_p,
+                                                gboolean  *vexpand_p);
+
 G_END_DECLS
diff --git a/src/adw-widget-utils.c b/src/adw-widget-utils.c
index 27433b0d..c234ceb6 100644
--- a/src/adw-widget-utils.c
+++ b/src/adw-widget-utils.c
@@ -474,3 +474,40 @@ adw_widget_grab_focus_child (GtkWidget *widget)
 
   return FALSE;
 }
+
+void
+adw_widget_compute_expand (GtkWidget *widget,
+                           gboolean  *hexpand_p,
+                           gboolean  *vexpand_p)
+{
+  GtkWidget *child;
+  gboolean hexpand = FALSE;
+  gboolean vexpand = FALSE;
+
+  for (child = gtk_widget_get_first_child (widget);
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child)) {
+    hexpand = hexpand || gtk_widget_compute_expand (child, GTK_ORIENTATION_HORIZONTAL);
+    vexpand = vexpand || gtk_widget_compute_expand (child, GTK_ORIENTATION_VERTICAL);
+  }
+
+  *hexpand_p = hexpand;
+  *vexpand_p = vexpand;
+}
+
+void
+adw_widget_compute_expand_horizontal_only (GtkWidget *widget,
+                                           gboolean  *hexpand_p,
+                                           gboolean  *vexpand_p)
+{
+  GtkWidget *child;
+  gboolean hexpand = FALSE;
+
+  for (child = gtk_widget_get_first_child (widget);
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child))
+    hexpand = hexpand || gtk_widget_compute_expand (child, GTK_ORIENTATION_HORIZONTAL);
+
+  *hexpand_p = hexpand;
+  *vexpand_p = FALSE;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]