summaryrefslogtreecommitdiff
path: root/gtk/gtkcenterbox.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2017-06-03 13:17:19 -0400
committerMatthias Clasen <mclasen@redhat.com>2017-06-04 21:20:33 -0400
commitf8059f30405b015c7ac00fdf2156503928b6c78e (patch)
tree1ab569f0008cd8d8ff382a6ea9b52af0b8e8a865 /gtk/gtkcenterbox.c
parente936a35d66ce663d9632aa239b0f805c004ad5af (diff)
downloadgtk+-f8059f30405b015c7ac00fdf2156503928b6c78e.tar.gz
center box: handle missing start or end widgets
Any slot may be unfilled, not just the center one.
Diffstat (limited to 'gtk/gtkcenterbox.c')
-rw-r--r--gtk/gtkcenterbox.c114
1 files changed, 69 insertions, 45 deletions
diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c
index 7970baaa9f..abc37224ab 100644
--- a/gtk/gtkcenterbox.c
+++ b/gtk/gtkcenterbox.c
@@ -78,22 +78,16 @@ gtk_center_box_measure (GtkWidget *widget,
GtkCenterBox *self = GTK_CENTER_BOX (widget);
int min, nat, min_baseline, nat_baseline;
- gtk_widget_measure (self->start_widget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
+ *minimum = *natural = 0;
- if (self->center_widget)
+ if (self->start_widget)
{
- gtk_widget_measure (self->center_widget,
+ gtk_widget_measure (self->start_widget,
orientation,
for_size,
&min, &nat,
&min_baseline, &nat_baseline);
- /* XXX How are baselines even handled? */
-
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
*minimum = *minimum + min;
@@ -106,23 +100,45 @@ gtk_center_box_measure (GtkWidget *widget,
}
}
- gtk_widget_measure (self->end_widget,
- orientation,
- for_size,
- &min, &nat,
- &min_baseline, &nat_baseline);
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (self->center_widget)
{
- *minimum = *minimum + min;
- *natural = *natural + nat;
+ gtk_widget_measure (self->center_widget,
+ orientation,
+ for_size,
+ &min, &nat,
+ &min_baseline, &nat_baseline);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ *minimum = *minimum + min;
+ *natural = *natural + nat;
+ }
+ else /* GTK_ORIENTATION_VERTICAL */
+ {
+ *minimum = MAX (*minimum, min);
+ *natural = MAX (*minimum, nat);
+ }
}
- else /* GTK_ORIENTATION_VERTICAL */
+
+ if (self->end_widget)
{
- *minimum = MAX (*minimum, min);
- *natural = MAX (*minimum, nat);
- }
+ gtk_widget_measure (self->end_widget,
+ orientation,
+ for_size,
+ &min, &nat,
+ &min_baseline, &nat_baseline);
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ *minimum = *minimum + min;
+ *natural = *natural + nat;
+ }
+ else /* GTK_ORIENTATION_VERTICAL */
+ {
+ *minimum = MAX (*minimum, min);
+ *natural = MAX (*minimum, nat);
+ }
+ }
}
static void
@@ -133,38 +149,44 @@ gtk_center_box_size_allocate (GtkWidget *widget,
GtkAllocation child_allocation;
GtkAllocation clip = *allocation;
GtkAllocation child_clip;
- int start_size, end_size;
+ int start_size = 0;
+ int end_size = 0;
int min, nat;
GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
/* TODO: Allocate natural sizes if possible? */
- /* Start Box */
- gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
- allocation->height,
- &min, &nat, NULL, NULL);
- child_allocation.x = allocation->x;
child_allocation.y = allocation->y;
- child_allocation.width = min;
child_allocation.height = allocation->height;
- gtk_widget_size_allocate (self->start_widget, &child_allocation);
- gtk_widget_get_clip (self->start_widget, &child_clip);
- gdk_rectangle_union (&clip, &clip, &child_clip);
- start_size = child_allocation.width;
+ if (self->start_widget)
+ {
+ gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
+ allocation->height,
+ &min, &nat, NULL, NULL);
+ child_allocation.x = allocation->x;
+ child_allocation.width = min;
+
+ gtk_widget_size_allocate (self->start_widget, &child_allocation);
+ gtk_widget_get_clip (self->start_widget, &child_clip);
+ gdk_rectangle_union (&clip, &clip, &child_clip);
+ start_size = child_allocation.width;
+ }
- /* End Box */
- gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
- allocation->height,
- &min, &nat, NULL, NULL);
- child_allocation.x = allocation->x + allocation->width - min;
- child_allocation.width = min;
+ if (self->end_widget)
+ {
+ gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
+ allocation->height,
+ &min, &nat, NULL, NULL);
+ child_allocation.x = allocation->x + allocation->width - min;
+ child_allocation.width = min;
- gtk_widget_size_allocate (self->end_widget, &child_allocation);
- gtk_widget_get_clip (self->end_widget, &child_clip);
- gdk_rectangle_union (&clip, &clip, &child_clip);
- end_size = child_allocation.width;
+ gtk_widget_size_allocate (self->end_widget, &child_allocation);
+ gtk_widget_get_clip (self->end_widget, &child_clip);
+ gdk_rectangle_union (&clip, &clip, &child_clip);
+ end_size = child_allocation.width;
+ }
/* Center Widget */
if (self->center_widget)
@@ -197,12 +219,14 @@ gtk_center_box_snapshot (GtkWidget *widget,
{
GtkCenterBox *self = GTK_CENTER_BOX (widget);
- gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
+ if (self->start_widget)
+ gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
if (self->center_widget)
gtk_widget_snapshot_child (widget, self->center_widget, snapshot);
- gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
+ if (self->end_widget)
+ gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
}
static void