Implement fair extra space allocation
This commit is contained in:
committed by
Tristan Van Berkom
parent
208ba9bb50
commit
651bed57a4
657
gtk/gtkbox.c
657
gtk/gtkbox.c
@ -407,224 +407,230 @@ gtk_box_size_allocate (GtkWidget *widget,
|
|||||||
gint nvis_children;
|
gint nvis_children;
|
||||||
gint nexpand_children;
|
gint nexpand_children;
|
||||||
|
|
||||||
|
guint border_width;
|
||||||
|
GtkTextDirection direction;
|
||||||
|
GtkAllocation child_allocation;
|
||||||
|
GtkRequestedSize *sizes;
|
||||||
|
|
||||||
|
GtkPackType packing;
|
||||||
|
|
||||||
|
gint size;
|
||||||
|
gint extra;
|
||||||
|
gint n_extra_widgets = 0; /* Number of widgets that receive 1 extra px */
|
||||||
|
gint x = 0, y = 0, i;
|
||||||
|
gint child_size;
|
||||||
|
|
||||||
|
|
||||||
widget->allocation = *allocation;
|
widget->allocation = *allocation;
|
||||||
|
|
||||||
count_expand_children (box, &nvis_children, &nexpand_children);
|
count_expand_children (box, &nvis_children, &nexpand_children);
|
||||||
|
|
||||||
if (nvis_children > 0)
|
/* If there is no visible child, simply return. */
|
||||||
|
if (nvis_children <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
|
||||||
|
direction = gtk_widget_get_direction (widget);
|
||||||
|
sizes = g_newa (GtkRequestedSize, nvis_children);
|
||||||
|
|
||||||
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
else
|
||||||
|
size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
|
||||||
|
/* Retrieve desired size for visible children. */
|
||||||
|
for (i = 0, children = private->children; children; children = children->next)
|
||||||
{
|
{
|
||||||
guint border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
|
child = children->data;
|
||||||
GtkTextDirection direction = gtk_widget_get_direction (widget);
|
|
||||||
GtkAllocation child_allocation;
|
|
||||||
GtkRequestedSize *sizes = g_newa (GtkRequestedSize, nvis_children);
|
|
||||||
|
|
||||||
GtkPackType packing;
|
if (!gtk_widget_get_visible (child->widget))
|
||||||
|
continue;
|
||||||
gint size;
|
|
||||||
gint extra;
|
|
||||||
gint x = 0, y = 0, i;
|
|
||||||
gint child_size;
|
|
||||||
|
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
|
gtk_size_request_get_width_for_height (GTK_SIZE_REQUEST (child->widget),
|
||||||
|
allocation->height,
|
||||||
|
&sizes[i].minimum_size,
|
||||||
|
&sizes[i].natural_size);
|
||||||
else
|
else
|
||||||
size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
|
gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child->widget),
|
||||||
|
allocation->width,
|
||||||
|
&sizes[i].minimum_size,
|
||||||
|
&sizes[i].natural_size);
|
||||||
|
|
||||||
/* Retrieve desired size for visible children */
|
|
||||||
i = 0;
|
/* Assert the api is working properly */
|
||||||
children = private->children;
|
if (sizes[i].minimum_size < 0)
|
||||||
while (children)
|
g_error ("GtkBox child %s minimum %s: %d < 0 for %s %d",
|
||||||
|
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
||||||
|
sizes[i].minimum_size,
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
|
||||||
|
|
||||||
|
if (sizes[i].natural_size < sizes[i].minimum_size)
|
||||||
|
g_error ("GtkBox child %s natural %s: %d < minimum %d for %s %d",
|
||||||
|
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
||||||
|
sizes[i].natural_size,
|
||||||
|
sizes[i].minimum_size,
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
|
||||||
|
|
||||||
|
size -= sizes[i].minimum_size;
|
||||||
|
size -= child->padding * 2;
|
||||||
|
|
||||||
|
sizes[i].data = child;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (private->homogeneous)
|
||||||
|
{
|
||||||
|
/* If were homogenous we still need to run the above loop to get the
|
||||||
|
* minimum sizes for children that are not going to fill
|
||||||
|
*/
|
||||||
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
else
|
||||||
|
size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
|
||||||
|
extra = size / nvis_children;
|
||||||
|
n_extra_widgets = size % nvis_children;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Bring children up to size first */
|
||||||
|
size = gtk_distribute_natural_allocation (size, nvis_children, sizes);
|
||||||
|
|
||||||
|
/* Calculate space which hasn't distributed yet,
|
||||||
|
* and is available for expanding children.
|
||||||
|
*/
|
||||||
|
if (nexpand_children > 0)
|
||||||
{
|
{
|
||||||
child = children->data;
|
extra = size / nexpand_children;
|
||||||
children = children->next;
|
n_extra_widgets = size % nexpand_children;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
extra = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (gtk_widget_get_visible (child->widget))
|
/* Allocate child positions. */
|
||||||
{
|
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
{
|
||||||
gtk_size_request_get_width_for_height (GTK_SIZE_REQUEST (child->widget),
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
allocation->height,
|
{
|
||||||
&sizes[i].minimum_size,
|
child_allocation.y = allocation->y + border_width;
|
||||||
&sizes[i].natural_size);
|
child_allocation.height = MAX (1, allocation->height - border_width * 2);
|
||||||
else
|
if (packing == GTK_PACK_START)
|
||||||
gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child->widget),
|
x = allocation->x + border_width;
|
||||||
allocation->width,
|
else
|
||||||
&sizes[i].minimum_size,
|
x = allocation->x + allocation->width - border_width;
|
||||||
&sizes[i].natural_size);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Assert the api is working properly */
|
child_allocation.x = allocation->x + border_width;
|
||||||
if (sizes[i].minimum_size < 0)
|
child_allocation.width = MAX (1, allocation->width - border_width * 2);
|
||||||
g_error ("GtkBox child %s minimum %s: %d < 0 for %s %d",
|
if (packing == GTK_PACK_START)
|
||||||
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
y = allocation->y + border_width;
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
else
|
||||||
sizes[i].minimum_size,
|
y = allocation->y + allocation->height - border_width;
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
|
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
|
|
||||||
|
|
||||||
if (sizes[i].natural_size < sizes[i].minimum_size)
|
|
||||||
g_error ("GtkBox child %s natural %s: %d < minimum %d for %s %d",
|
|
||||||
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
|
||||||
sizes[i].natural_size,
|
|
||||||
sizes[i].minimum_size,
|
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "height" : "width",
|
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? allocation->height : allocation->width);
|
|
||||||
|
|
||||||
size -= sizes[i].minimum_size;
|
|
||||||
size -= child->padding * 2;
|
|
||||||
|
|
||||||
sizes[i].data = child;
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (private->homogeneous)
|
for (i = 0, children = private->children;
|
||||||
|
children;
|
||||||
|
children = children->next)
|
||||||
{
|
{
|
||||||
/* If were homogenous we still need to run the above loop to get the minimum sizes
|
child = children->data;
|
||||||
* for children that are not going to fill
|
|
||||||
|
/* If widget is not visible or it's packing is not right for current
|
||||||
|
* loop, skip it.
|
||||||
*/
|
*/
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (child->pack != packing || !gtk_widget_get_visible (child->widget))
|
||||||
size = allocation->width - border_width * 2 - (nvis_children - 1) * private->spacing;
|
continue;
|
||||||
else
|
|
||||||
size = allocation->height - border_width * 2 - (nvis_children - 1) * private->spacing;
|
|
||||||
|
|
||||||
extra = size / nvis_children;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Bring children up to size first */
|
|
||||||
size = gtk_distribute_natural_allocation (size, nvis_children, sizes);
|
|
||||||
|
|
||||||
/* Calculate space which hasn't distributed yet,
|
/* Assign the child's size. */
|
||||||
* and is available for expanding children.
|
if (private->homogeneous)
|
||||||
*/
|
|
||||||
if (nexpand_children > 0)
|
|
||||||
extra = size / nexpand_children;
|
|
||||||
else
|
|
||||||
extra = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate child positions. */
|
|
||||||
|
|
||||||
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
|
|
||||||
{
|
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
||||||
{
|
|
||||||
child_allocation.y = allocation->y + border_width;
|
|
||||||
child_allocation.height = MAX (1, allocation->height - border_width * 2);
|
|
||||||
if (packing == GTK_PACK_START)
|
|
||||||
x = allocation->x + border_width;
|
|
||||||
else
|
|
||||||
x = allocation->x + allocation->width - border_width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
child_allocation.x = allocation->x + border_width;
|
|
||||||
child_allocation.width = MAX (1, allocation->width - border_width * 2);
|
|
||||||
if (packing == GTK_PACK_START)
|
|
||||||
y = allocation->y + border_width;
|
|
||||||
else
|
|
||||||
y = allocation->y + allocation->height - border_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
children = private->children;
|
|
||||||
while (children)
|
|
||||||
{
|
{
|
||||||
child = children->data;
|
child_size = extra;
|
||||||
children = children->next;
|
|
||||||
|
|
||||||
if (gtk_widget_get_visible (child->widget))
|
if (n_extra_widgets > 0)
|
||||||
{
|
{
|
||||||
if (child->pack == packing)
|
child_size++;
|
||||||
{
|
n_extra_widgets--;
|
||||||
/* Assign the child's size. */
|
}
|
||||||
if (private->homogeneous)
|
|
||||||
{
|
|
||||||
if (nvis_children == 1)
|
|
||||||
child_size = size;
|
|
||||||
else
|
|
||||||
child_size = extra;
|
|
||||||
|
|
||||||
nvis_children -= 1;
|
|
||||||
size -= extra;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
child_size = sizes[i].minimum_size + child->padding * 2;
|
|
||||||
|
|
||||||
if (child->expand)
|
|
||||||
{
|
|
||||||
if (nexpand_children == 1)
|
|
||||||
child_size += size;
|
|
||||||
else
|
|
||||||
child_size += extra;
|
|
||||||
|
|
||||||
nexpand_children -= 1;
|
|
||||||
size -= extra;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Assign the child's position. */
|
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
||||||
{
|
|
||||||
if (child->fill)
|
|
||||||
{
|
|
||||||
child_allocation.width = MAX (1, child_size - child->padding * 2);
|
|
||||||
child_allocation.x = x + child->padding;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
child_allocation.width = sizes[i].minimum_size;
|
|
||||||
child_allocation.x = x + (child_size - child_allocation.width) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packing == GTK_PACK_START)
|
|
||||||
{
|
|
||||||
x += child_size + private->spacing;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x -= child_size + private->spacing;
|
|
||||||
|
|
||||||
child_allocation.x -= child_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == GTK_TEXT_DIR_RTL)
|
|
||||||
child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
|
|
||||||
|
|
||||||
}
|
|
||||||
else /* (private->orientation == GTK_ORIENTATION_VERTICAL) */
|
|
||||||
{
|
|
||||||
if (child->fill)
|
|
||||||
{
|
|
||||||
child_allocation.height = MAX (1, child_size - child->padding * 2);
|
|
||||||
child_allocation.y = y + child->padding;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
child_allocation.height = sizes[i].minimum_size;
|
|
||||||
child_allocation.y = y + (child_size - child_allocation.height) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packing == GTK_PACK_START)
|
|
||||||
{
|
|
||||||
y += child_size + private->spacing;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
y -= child_size + private->spacing;
|
|
||||||
|
|
||||||
child_allocation.y -= child_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gtk_widget_size_allocate (child->widget, &child_allocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child_size = sizes[i].minimum_size + child->padding * 2;
|
||||||
|
|
||||||
|
if (child->expand)
|
||||||
|
{
|
||||||
|
child_size += extra;
|
||||||
|
|
||||||
|
if (n_extra_widgets > 0)
|
||||||
|
{
|
||||||
|
child_size++;
|
||||||
|
n_extra_widgets--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assign the child's position. */
|
||||||
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
{
|
||||||
|
if (child->fill)
|
||||||
|
{
|
||||||
|
child_allocation.width = MAX (1, child_size - child->padding * 2);
|
||||||
|
child_allocation.x = x + child->padding;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child_allocation.width = sizes[i].minimum_size;
|
||||||
|
child_allocation.x = x + (child_size - child_allocation.width) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packing == GTK_PACK_START)
|
||||||
|
{
|
||||||
|
x += child_size + private->spacing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x -= child_size + private->spacing;
|
||||||
|
|
||||||
|
child_allocation.x -= child_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (direction == GTK_TEXT_DIR_RTL)
|
||||||
|
child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
|
||||||
|
|
||||||
|
}
|
||||||
|
else /* (private->orientation == GTK_ORIENTATION_VERTICAL) */
|
||||||
|
{
|
||||||
|
if (child->fill)
|
||||||
|
{
|
||||||
|
child_allocation.height = MAX (1, child_size - child->padding * 2);
|
||||||
|
child_allocation.y = y + child->padding;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child_allocation.height = sizes[i].minimum_size;
|
||||||
|
child_allocation.y = y + (child_size - child_allocation.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packing == GTK_PACK_START)
|
||||||
|
{
|
||||||
|
y += child_size + private->spacing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y -= child_size + private->spacing;
|
||||||
|
|
||||||
|
child_allocation.y -= child_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gtk_widget_size_allocate (child->widget, &child_allocation);
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -919,149 +925,156 @@ gtk_box_compute_size_for_opposing_orientation (GtkBox *box,
|
|||||||
gint *minimum_size,
|
gint *minimum_size,
|
||||||
gint *natural_size)
|
gint *natural_size)
|
||||||
{
|
{
|
||||||
GtkBoxPriv *private = box->priv;
|
GtkBoxPriv *private = box->priv;
|
||||||
GtkBoxChild *child;
|
GtkBoxChild *child;
|
||||||
GList *children;
|
GList *children;
|
||||||
gint nvis_children;
|
gint nvis_children;
|
||||||
gint nexpand_children;
|
gint nexpand_children;
|
||||||
gint computed_minimum = 0, computed_natural = 0;
|
gint computed_minimum = 0, computed_natural = 0;
|
||||||
guint border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
|
guint border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
|
||||||
|
GtkRequestedSize *sizes;
|
||||||
|
GtkPackType packing;
|
||||||
|
gint size, extra, i;
|
||||||
|
gint child_size, child_minimum, child_natural;
|
||||||
|
gint n_extra_widgets = 0;
|
||||||
|
|
||||||
count_expand_children (box, &nvis_children, &nexpand_children);
|
count_expand_children (box, &nvis_children, &nexpand_children);
|
||||||
|
|
||||||
if (nvis_children > 0)
|
if (nvis_children <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sizes = g_newa (GtkRequestedSize, nvis_children);
|
||||||
|
size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
|
||||||
|
/* Retrieve desired size for visible children */
|
||||||
|
for (i = 0, children = private->children; children; children = children->next)
|
||||||
{
|
{
|
||||||
GtkRequestedSize *sizes = g_newa (GtkRequestedSize, nvis_children);
|
child = children->data;
|
||||||
GtkPackType packing;
|
|
||||||
gint size, extra, i;
|
if (gtk_widget_get_visible (child->widget))
|
||||||
gint child_size, child_minimum, child_natural;
|
{
|
||||||
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
gtk_size_request_get_width (GTK_SIZE_REQUEST (child->widget),
|
||||||
|
&sizes[i].minimum_size,
|
||||||
|
&sizes[i].natural_size);
|
||||||
|
else
|
||||||
|
gtk_size_request_get_height (GTK_SIZE_REQUEST (child->widget),
|
||||||
|
&sizes[i].minimum_size,
|
||||||
|
&sizes[i].natural_size);
|
||||||
|
|
||||||
|
/* Assert the api is working properly */
|
||||||
|
if (sizes[i].minimum_size < 0)
|
||||||
|
g_error ("GtkBox child %s minimum %s: %d < 0",
|
||||||
|
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
||||||
|
sizes[i].minimum_size);
|
||||||
|
|
||||||
|
if (sizes[i].natural_size < sizes[i].minimum_size)
|
||||||
|
g_error ("GtkBox child %s natural %s: %d < minimum %d",
|
||||||
|
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
||||||
|
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
||||||
|
sizes[i].natural_size,
|
||||||
|
sizes[i].minimum_size);
|
||||||
|
|
||||||
|
size -= sizes[i].minimum_size;
|
||||||
|
size -= child->padding * 2;
|
||||||
|
|
||||||
|
sizes[i].data = child;
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (private->homogeneous)
|
||||||
|
{
|
||||||
|
/* If were homogenous we still need to run the above loop to get the
|
||||||
|
* minimum sizes for children that are not going to fill
|
||||||
|
*/
|
||||||
size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
|
size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
|
||||||
|
extra = size / nvis_children;
|
||||||
|
n_extra_widgets = size % nvis_children;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Bring children up to size first */
|
||||||
|
size = gtk_distribute_natural_allocation (size, nvis_children, sizes);
|
||||||
|
|
||||||
/* Retrieve desired size for visible children */
|
/* Calculate space which hasn't distributed yet,
|
||||||
for (i = 0, children = private->children; children; children = children->next)
|
* and is available for expanding children.
|
||||||
|
*/
|
||||||
|
if (nexpand_children > 0)
|
||||||
|
{
|
||||||
|
extra = size / nexpand_children;
|
||||||
|
n_extra_widgets = size % nexpand_children;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
extra = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate child positions. */
|
||||||
|
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
|
||||||
|
{
|
||||||
|
for (i = 0, children = private->children;
|
||||||
|
children;
|
||||||
|
children = children->next)
|
||||||
{
|
{
|
||||||
child = children->data;
|
child = children->data;
|
||||||
|
|
||||||
if (gtk_widget_get_visible (child->widget))
|
if (child->pack != packing || !gtk_widget_get_visible (child->widget))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (child->pack == packing)
|
||||||
{
|
{
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
/* Assign the child's size. */
|
||||||
gtk_size_request_get_width (GTK_SIZE_REQUEST (child->widget),
|
if (private->homogeneous)
|
||||||
&sizes[i].minimum_size,
|
{
|
||||||
&sizes[i].natural_size);
|
child_size = extra;
|
||||||
|
|
||||||
|
if (n_extra_widgets > 0)
|
||||||
|
{
|
||||||
|
child_size++;
|
||||||
|
n_extra_widgets--;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
gtk_size_request_get_height (GTK_SIZE_REQUEST (child->widget),
|
{
|
||||||
&sizes[i].minimum_size,
|
child_size = sizes[i].minimum_size + child->padding * 2;
|
||||||
&sizes[i].natural_size);
|
|
||||||
|
|
||||||
/* Assert the api is working properly */
|
|
||||||
if (sizes[i].minimum_size < 0)
|
|
||||||
g_error ("GtkBox child %s minimum %s: %d < 0",
|
|
||||||
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
|
||||||
sizes[i].minimum_size);
|
|
||||||
|
|
||||||
if (sizes[i].natural_size < sizes[i].minimum_size)
|
if (child->expand)
|
||||||
g_error ("GtkBox child %s natural %s: %d < minimum %d",
|
{
|
||||||
gtk_widget_get_name (GTK_WIDGET (child->widget)),
|
child_size += extra;
|
||||||
(private->orientation == GTK_ORIENTATION_HORIZONTAL) ? "width" : "height",
|
|
||||||
sizes[i].natural_size,
|
|
||||||
sizes[i].minimum_size);
|
|
||||||
|
|
||||||
size -= sizes[i].minimum_size;
|
if (n_extra_widgets > 0)
|
||||||
size -= child->padding * 2;
|
|
||||||
|
|
||||||
sizes[i].data = child;
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (private->homogeneous)
|
|
||||||
{
|
|
||||||
/* If were homogenous we still need to run the above loop to get the minimum sizes
|
|
||||||
* for children that are not going to fill
|
|
||||||
*/
|
|
||||||
size = avail_size - border_width * 2 - (nvis_children - 1) * private->spacing;
|
|
||||||
extra = size / nvis_children;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Bring children up to size first */
|
|
||||||
size = gtk_distribute_natural_allocation (size, nvis_children, sizes);
|
|
||||||
|
|
||||||
/* Calculate space which hasn't distributed yet,
|
|
||||||
* and is available for expanding children.
|
|
||||||
*/
|
|
||||||
if (nexpand_children > 0)
|
|
||||||
extra = size / nexpand_children;
|
|
||||||
else
|
|
||||||
extra = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate child positions. */
|
|
||||||
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
|
|
||||||
{
|
|
||||||
for (i = 0, children = private->children; children; children = children->next)
|
|
||||||
{
|
|
||||||
child = children->data;
|
|
||||||
|
|
||||||
if (gtk_widget_get_visible (child->widget))
|
|
||||||
{
|
|
||||||
if (child->pack == packing)
|
|
||||||
{
|
|
||||||
/* Assign the child's size. */
|
|
||||||
if (private->homogeneous)
|
|
||||||
{
|
|
||||||
if (nvis_children == 1)
|
|
||||||
child_size = size;
|
|
||||||
else
|
|
||||||
child_size = extra;
|
|
||||||
|
|
||||||
nvis_children -= 1;
|
|
||||||
size -= extra;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
child_size = sizes[i].minimum_size + child->padding * 2;
|
|
||||||
|
|
||||||
if (child->expand)
|
|
||||||
{
|
|
||||||
if (nexpand_children == 1)
|
|
||||||
child_size += size;
|
|
||||||
else
|
|
||||||
child_size += extra;
|
|
||||||
|
|
||||||
nexpand_children -= 1;
|
|
||||||
size -= extra;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child->fill)
|
|
||||||
{
|
{
|
||||||
child_size = MAX (1, child_size - child->padding * 2);
|
child_size++;
|
||||||
}
|
n_extra_widgets--;
|
||||||
else
|
|
||||||
{
|
|
||||||
child_size = sizes[i].minimum_size;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child->fill)
|
||||||
|
{
|
||||||
|
child_size = MAX (1, child_size - child->padding * 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child_size = sizes[i].minimum_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Assign the child's position. */
|
/* Assign the child's position. */
|
||||||
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child->widget),
|
gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child->widget),
|
||||||
child_size, &child_minimum, &child_natural);
|
child_size, &child_minimum, &child_natural);
|
||||||
else /* (private->orientation == GTK_ORIENTATION_VERTICAL) */
|
else /* (private->orientation == GTK_ORIENTATION_VERTICAL) */
|
||||||
gtk_size_request_get_width_for_height (GTK_SIZE_REQUEST (child->widget),
|
gtk_size_request_get_width_for_height (GTK_SIZE_REQUEST (child->widget),
|
||||||
child_size, &child_minimum, &child_natural);
|
child_size, &child_minimum, &child_natural);
|
||||||
|
|
||||||
|
|
||||||
computed_minimum = MAX (computed_minimum, child_minimum);
|
computed_minimum = MAX (computed_minimum, child_minimum);
|
||||||
computed_natural = MAX (computed_natural, child_natural);
|
computed_natural = MAX (computed_natural, child_natural);
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user