summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2018-02-06 22:19:30 +0100
committerTimm Bäder <mail@baedert.org>2018-02-09 11:36:53 +0100
commit3a4c6c18b30fadb0ffb24564b99cb9b88146a900 (patch)
treec140936071100009ede012a7ca495e2a295c749b /gtk
parent5e9f5c17b5e502dd09fcb89672bcc535189c3188 (diff)
downloadgtk+-3a4c6c18b30fadb0ffb24564b99cb9b88146a900.tar.gz
box: Use widget child list when computing size request
Contrary to what the comments in this function might suggest, it does not actually do anything about child positions, child child sizes. So, packing doesn't matter and we don't need to iterate over all child widgets twice.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkbox.c119
1 files changed, 50 insertions, 69 deletions
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index fac5464e53..927093e458 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -1041,8 +1041,8 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
gint *natural_baseline)
{
GtkBoxPrivate *private = gtk_box_get_instance_private (box);
- GtkBoxChild *child;
- GList *children;
+ GtkWidget *widget = GTK_WIDGET (box);
+ GtkWidget *child;
gint nvis_children;
gint nexpand_children;
gint computed_minimum = 0, computed_natural = 0;
@@ -1050,7 +1050,6 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
gint computed_minimum_below = 0, computed_natural_below = 0;
gint computed_minimum_baseline = -1, computed_natural_baseline = -1;
GtkRequestedSize *sizes;
- GtkPackType packing;
gint extra_space, size_given_to_child, i;
gint children_minimum_size = 0;
gint child_size, child_minimum, child_natural;
@@ -1069,22 +1068,19 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
extra_space = avail_size - (nvis_children - 1) * spacing;
/* Retrieve desired size for visible children */
- for (i = 0, children = private->children; children; children = children->next)
+ for (i = 0, child = _gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = _gtk_widget_get_next_sibling (child))
{
- child = children->data;
-
- if (_gtk_widget_get_visible (child->widget))
+ if (_gtk_widget_get_visible (child))
{
- gtk_widget_measure (child->widget,
+ gtk_widget_measure (child,
private->orientation,
-1,
&sizes[i].minimum_size, &sizes[i].natural_size,
NULL, NULL);
children_minimum_size += sizes[i].minimum_size;
-
- sizes[i].data = child;
-
i += 1;
}
}
@@ -1120,32 +1116,32 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
}
have_baseline = FALSE;
- /* Allocate child positions. */
- for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
+ for (i = 0, child = _gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = _gtk_widget_get_next_sibling (child))
{
- for (i = 0, children = private->children;
- children;
- children = children->next)
- {
- child = children->data;
+ /* If widget is not visible, skip it. */
+ if (!_gtk_widget_get_visible (child))
+ continue;
- /* If widget is not visible, skip it. */
- if (!_gtk_widget_get_visible (child->widget))
- continue;
+ /* Assign the child's size. */
+ if (private->homogeneous)
+ {
+ child_size = size_given_to_child;
- /* If widget is packed differently skip it, but still increment i,
- * since widget is visible and will be handled in next loop iteration.
- */
- if (child->pack != packing)
- {
- i++;
- continue;
- }
+ if (n_extra_widgets > 0)
+ {
+ child_size++;
+ n_extra_widgets--;
+ }
+ }
+ else
+ {
+ child_size = sizes[i].minimum_size;
- /* Assign the child's size. */
- if (private->homogeneous)
+ if (gtk_widget_compute_expand (child, private->orientation))
{
- child_size = size_given_to_child;
+ child_size += size_given_to_child;
if (n_extra_widgets > 0)
{
@@ -1153,45 +1149,30 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
n_extra_widgets--;
}
}
- else
- {
- child_size = sizes[i].minimum_size;
-
- if (gtk_widget_compute_expand (child->widget, private->orientation))
- {
- child_size += size_given_to_child;
-
- if (n_extra_widgets > 0)
- {
- child_size++;
- n_extra_widgets--;
- }
- }
- }
+ }
- child_minimum_baseline = child_natural_baseline = -1;
- /* Assign the child's position. */
- gtk_widget_measure (child->widget,
- OPPOSITE_ORIENTATION (private->orientation),
- child_size,
- &child_minimum, &child_natural,
- &child_minimum_baseline, &child_natural_baseline);
+ child_minimum_baseline = child_natural_baseline = -1;
+ /* Assign the child's position. */
+ gtk_widget_measure (child,
+ OPPOSITE_ORIENTATION (private->orientation),
+ child_size,
+ &child_minimum, &child_natural,
+ &child_minimum_baseline, &child_natural_baseline);
- if (child_minimum_baseline >= 0)
- {
- have_baseline = TRUE;
- computed_minimum_below = MAX (computed_minimum_below, child_minimum - child_minimum_baseline);
- computed_natural_below = MAX (computed_natural_below, child_natural - child_natural_baseline);
- computed_minimum_above = MAX (computed_minimum_above, child_minimum_baseline);
- computed_natural_above = MAX (computed_natural_above, child_natural_baseline);
- }
- else
- {
- computed_minimum = MAX (computed_minimum, child_minimum);
- computed_natural = MAX (computed_natural, child_natural);
- }
- i += 1;
- }
+ if (child_minimum_baseline >= 0)
+ {
+ have_baseline = TRUE;
+ computed_minimum_below = MAX (computed_minimum_below, child_minimum - child_minimum_baseline);
+ computed_natural_below = MAX (computed_natural_below, child_natural - child_natural_baseline);
+ computed_minimum_above = MAX (computed_minimum_above, child_minimum_baseline);
+ computed_natural_above = MAX (computed_natural_above, child_natural_baseline);
+ }
+ else
+ {
+ computed_minimum = MAX (computed_minimum, child_minimum);
+ computed_natural = MAX (computed_natural, child_natural);
+ }
+ i += 1;
}
if (have_baseline)