[libadwaita/wip/exalm/action-row-expand] action-row: Allow suffixes to expand
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/action-row-expand] action-row: Allow suffixes to expand
- Date: Fri, 12 Nov 2021 16:04:46 +0000 (UTC)
commit 17fd4fa156aa0a884bbfc6e4ee47a6755d82a781
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Nov 12 21:03:04 2021 +0500
action-row: Allow suffixes to expand
GtkBox packs children from the start to end. Unfortunately, here we want
to have the opposite so we need to set halign=end on the suffixes box.
However, this also breaks hexpand for its children. There doesn't seem to
be a clean way to accomplish it without changing GtkBox, so instead do a
little hack: wrap the box into another widget and that would check if the
child is expanded and control its halign.
src/adw-action-row.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
src/adw-action-row.ui | 11 ++++++++---
2 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/src/adw-action-row.c b/src/adw-action-row.c
index 9f4ff983..f8803ba9 100644
--- a/src/adw-action-row.c
+++ b/src/adw-action-row.c
@@ -7,6 +7,7 @@
#include "config.h"
#include "adw-action-row.h"
+#include "adw-gizmo-private.h"
#include "adw-macros-private.h"
/**
@@ -51,6 +52,7 @@ typedef struct
GtkImage *image;
GtkBox *prefixes;
GtkLabel *subtitle;
+ GtkWidget *suffixes_bin;
GtkBox *suffixes;
GtkLabel *title;
GtkBox *title_box;
@@ -331,19 +333,57 @@ adw_action_row_class_init (AdwActionRowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, image);
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, prefixes);
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, subtitle);
+ gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, suffixes_bin);
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, suffixes);
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, title);
gtk_widget_class_bind_template_child_private (widget_class, AdwActionRow, title_box);
gtk_widget_class_bind_template_callback (widget_class, string_is_not_empty);
}
+static void
+suffixes_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ GtkWidget *child = gtk_widget_get_first_child (widget);
+
+ gtk_widget_measure (child, orientation, for_size, minimum, natural,
+ minimum_baseline, natural_baseline);
+}
+
+
+static void
+suffixes_allocate (GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
+{
+ GtkWidget *child = gtk_widget_get_first_child (widget);
+
+ if (gtk_widget_compute_expand (child, GTK_ORIENTATION_HORIZONTAL)) {
+ gtk_widget_set_halign (child, GTK_ALIGN_FILL);
+ } else
+ gtk_widget_set_halign (child, GTK_ALIGN_END);
+
+ gtk_widget_allocate (child, width, height, baseline, NULL);
+}
+
static void
adw_action_row_init (AdwActionRow *self)
{
+ AdwActionRowPrivate *priv = adw_action_row_get_instance_private (self);
+
+ g_type_ensure (ADW_TYPE_GIZMO);
+
gtk_widget_init_template (GTK_WIDGET (self));
- g_signal_connect (self, "notify::parent", G_CALLBACK (parent_cb), NULL);
+ gtk_widget_set_layout_manager (priv->suffixes_bin, gtk_custom_layout_new (NULL, suffixes_measure,
suffixes_allocate));
+ g_signal_connect (self, "notify::parent", G_CALLBACK (parent_cb), NULL);
}
static void
@@ -728,7 +768,7 @@ adw_action_row_add_suffix (AdwActionRow *self,
priv = adw_action_row_get_instance_private (self);
gtk_box_append (priv->suffixes, widget);
- gtk_widget_show (GTK_WIDGET (priv->suffixes));
+ gtk_widget_show (GTK_WIDGET (priv->suffixes_bin));
}
/**
diff --git a/src/adw-action-row.ui b/src/adw-action-row.ui
index 840df424..e4581ec1 100644
--- a/src/adw-action-row.ui
+++ b/src/adw-action-row.ui
@@ -38,7 +38,6 @@
<property name="halign">start</property>
<property name="orientation">vertical</property>
<property name="valign">center</property>
- <property name="hexpand">True</property>
<style>
<class name="title"/>
</style>
@@ -86,9 +85,15 @@
</object>
</child>
<child>
- <object class="GtkBox" id="suffixes">
+ <object class="AdwGizmo" id="suffixes_bin">
<property name="visible">False</property>
- <property name="spacing">12</property>
+ <property name="hexpand">True</property>
+ <child>
+ <object class="GtkBox" id="suffixes">
+ <property name="spacing">12</property>
+ <property name="halign">end</property>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]