diff options
author | Matthias Clasen <mclasen@redhat.com> | 2017-06-03 22:44:19 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2017-06-04 21:21:00 -0400 |
commit | 42921750ff324e36b885bfd7905b3cd7774cd205 (patch) | |
tree | a61a691bfc377a6c5ddf8812ac75bc1d078cb112 /gtk/gtkcenterbox.c | |
parent | 60cd5b9b4ca61ab29b699ddf6d1be45c659dbb6a (diff) | |
download | gtk+-42921750ff324e36b885bfd7905b3cd7774cd205.tar.gz |
center box: Support expand property
We expand the center child first, but only as far
as we can keep it centered.
Diffstat (limited to 'gtk/gtkcenterbox.c')
-rw-r--r-- | gtk/gtkcenterbox.c | 81 |
1 files changed, 63 insertions, 18 deletions
diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c index 1a19fa1b87..45599f5893 100644 --- a/gtk/gtkcenterbox.c +++ b/gtk/gtkcenterbox.c @@ -46,6 +46,8 @@ #include "gtkcenterbox.h" #include "gtkcssnodeprivate.h" #include "gtkwidgetprivate.h" +#include "gtkorientable.h" +#include "gtkorientableprivate.h" #include "gtkbuildable.h" struct _GtkCenterBox @@ -163,6 +165,9 @@ gtk_center_box_size_allocate (GtkWidget *widget, int right_min = 0; int right_nat = 0; int avail; + gboolean left_expand = FALSE; + gboolean center_expand = FALSE; + gboolean right_expand = FALSE; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { @@ -192,35 +197,29 @@ gtk_center_box_size_allocate (GtkWidget *widget, allocation->height, ¢er_min, ¢er_nat, NULL, NULL); - child_allocation.y = allocation->y; - child_allocation.height = allocation->height; - - center_size = CLAMP (allocation->width - (left_min + right_min), center_min, center_nat); + if (self->center_widget) + { + center_size = CLAMP (allocation->width - (left_min + right_min), center_min, center_nat); + center_expand = gtk_widget_get_hexpand (self->center_widget); + } if (left) { avail = MIN ((allocation->width - center_size) / 2, allocation->width - (center_size + right_min)); - child_allocation.width = CLAMP (avail, left_min, left_nat); - child_allocation.x = allocation->x; - - gtk_widget_size_allocate (left, &child_allocation); - gtk_widget_get_clip (left, &child_clip); - gdk_rectangle_union (&clip, &clip, &child_clip); - left_size = child_allocation.width; + left_size = CLAMP (avail, left_min, left_nat); + left_expand = gtk_widget_get_hexpand (left); } if (right) { avail = MIN ((allocation->width - center_size) / 2, allocation->width - (center_size + left_min)); - child_allocation.width = CLAMP (avail, right_min, right_nat); - child_allocation.x = allocation->x + allocation->width - child_allocation.width; - - gtk_widget_size_allocate (right, &child_allocation); - gtk_widget_get_clip (right, &child_clip); - gdk_rectangle_union (&clip, &clip, &child_clip); - right_size = child_allocation.width; + right_size = CLAMP (avail, right_min, right_nat); + right_expand = gtk_widget_get_hexpand (right); } + child_allocation.y = allocation->y; + child_allocation.height = allocation->height; + if (self->center_widget) { child_allocation.width = center_size; @@ -231,11 +230,57 @@ gtk_center_box_size_allocate (GtkWidget *widget, child_allocation.x = left_size; else if (allocation->width - right_size < child_allocation.x + child_allocation.width) child_allocation.x = allocation->width - child_allocation.width - right_size; + else if (center_expand) + { + child_allocation.width = allocation->width - 2 * MAX (left_size, right_size); + child_allocation.x = (allocation->width / 2) - (child_allocation.width / 2); + } child_allocation.x += allocation->x; gtk_widget_size_allocate (self->center_widget, &child_allocation); gtk_widget_get_clip (self->center_widget, &child_clip); gdk_rectangle_union (&clip, &clip, &child_clip); + + if (left_expand) + left_size = child_allocation.x - allocation->x; + + if (right_expand) + right_size = allocation->x + allocation->width - (child_allocation.x + child_allocation.width); + } + else + { + avail = allocation->width - (left_size + right_size); + if (left_expand && right_expand) + { + left_size += avail / 2; + right_size += avail / 2; + } + else if (left_expand) + { + left_size += avail; + } + else if (right_expand) + { + right_size += avail; + } + } + + if (left) + { + child_allocation.width = left_size; + child_allocation.x = allocation->x; + gtk_widget_size_allocate (left, &child_allocation); + gtk_widget_get_clip (left, &child_clip); + gdk_rectangle_union (&clip, &clip, &child_clip); + } + + if (right) + { + child_allocation.width = right_size; + child_allocation.x = allocation->x + allocation->width - child_allocation.width; + gtk_widget_size_allocate (right, &child_allocation); + gtk_widget_get_clip (right, &child_clip); + gdk_rectangle_union (&clip, &clip, &child_clip); } gtk_widget_set_clip (widget, &clip); |