Port remaining layout managers to the new child iteration API
TableLayout and FlowLayout now use the ClutterActor API for iterating over the children of an actor.
This commit is contained in:
parent
9c9ab42060
commit
7e377b5aee
@ -202,11 +202,11 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
|
||||
gfloat *nat_width_p)
|
||||
{
|
||||
ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv;
|
||||
GList *l, *children = clutter_container_get_children (container);
|
||||
gint n_rows, line_item_count, line_count;
|
||||
gfloat total_min_width, total_natural_width;
|
||||
gfloat line_min_width, line_natural_width;
|
||||
gfloat max_min_width, max_natural_width;
|
||||
ClutterActor *actor, *child;
|
||||
gfloat item_y;
|
||||
|
||||
n_rows = get_rows (CLUTTER_FLOW_LAYOUT (manager), for_height);
|
||||
@ -222,6 +222,8 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
|
||||
|
||||
item_y = 0;
|
||||
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
|
||||
/* clear the line width arrays */
|
||||
if (priv->line_min != NULL)
|
||||
g_array_free (priv->line_min, TRUE);
|
||||
@ -236,14 +238,15 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
|
||||
sizeof (gfloat),
|
||||
16);
|
||||
|
||||
if (children)
|
||||
if (clutter_actor_get_n_children (actor) != 0)
|
||||
line_count = 1;
|
||||
|
||||
max_min_width = max_natural_width = 0;
|
||||
|
||||
for (l = children; l != NULL; l = l->next)
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
gfloat child_min, child_natural;
|
||||
gfloat new_y, item_height;
|
||||
|
||||
@ -301,8 +304,6 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
|
||||
priv->col_width = max_natural_width;
|
||||
|
||||
if (priv->max_col_width > 0 && priv->col_width > priv->max_col_width)
|
||||
@ -379,11 +380,11 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
|
||||
gfloat *nat_height_p)
|
||||
{
|
||||
ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv;
|
||||
GList *l, *children = clutter_container_get_children (container);
|
||||
gint n_columns, line_item_count, line_count;
|
||||
gfloat total_min_height, total_natural_height;
|
||||
gfloat line_min_height, line_natural_height;
|
||||
gfloat max_min_height, max_natural_height;
|
||||
ClutterActor *actor, *child;
|
||||
gfloat item_x;
|
||||
|
||||
n_columns = get_columns (CLUTTER_FLOW_LAYOUT (manager), for_width);
|
||||
@ -399,6 +400,8 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
|
||||
|
||||
item_x = 0;
|
||||
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
|
||||
/* clear the line height arrays */
|
||||
if (priv->line_min != NULL)
|
||||
g_array_free (priv->line_min, TRUE);
|
||||
@ -413,14 +416,15 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
|
||||
sizeof (gfloat),
|
||||
16);
|
||||
|
||||
if (children)
|
||||
if (clutter_actor_get_n_children (actor) != 0)
|
||||
line_count = 1;
|
||||
|
||||
max_min_height = max_natural_height = 0;
|
||||
|
||||
for (l = children; l != NULL; l = l->next)
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
gfloat child_min, child_natural;
|
||||
gfloat new_x, item_width;
|
||||
|
||||
@ -479,8 +483,6 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
|
||||
priv->row_height = max_natural_height;
|
||||
|
||||
if (priv->max_row_height > 0 && priv->row_height > priv->max_row_height)
|
||||
@ -555,7 +557,7 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv;
|
||||
GList *l, *children = clutter_container_get_children (container);
|
||||
ClutterActor *actor, *child;
|
||||
gfloat x_off, y_off;
|
||||
gfloat avail_width, avail_height;
|
||||
gfloat item_x, item_y;
|
||||
@ -563,7 +565,8 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
||||
gint items_per_line;
|
||||
gint line_index;
|
||||
|
||||
if (children == NULL)
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
if (clutter_actor_get_n_children (actor) == 0)
|
||||
return;
|
||||
|
||||
clutter_actor_box_get_origin (allocation, &x_off, &y_off);
|
||||
@ -593,9 +596,10 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
||||
line_item_count = 0;
|
||||
line_index = 0;
|
||||
|
||||
for (l = children; l != NULL; l = l->next)
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterActorBox child_alloc;
|
||||
gfloat item_width, item_height;
|
||||
gfloat new_x, new_y;
|
||||
@ -703,8 +707,6 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
||||
|
||||
line_item_count += 1;
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -708,29 +708,35 @@ clutter_table_layout_set_container (ClutterLayoutManager *layout,
|
||||
|
||||
static void
|
||||
update_row_col (ClutterTableLayout *layout,
|
||||
ClutterContainer *container)
|
||||
ClutterContainer *container)
|
||||
{
|
||||
ClutterTableLayoutPrivate *priv = layout->priv;
|
||||
ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (layout);
|
||||
GList *children, *l;
|
||||
ClutterActor *actor, *child;
|
||||
gint n_cols, n_rows;
|
||||
|
||||
n_cols = n_rows = 0;
|
||||
children = container ? clutter_container_get_children (container) : NULL;
|
||||
|
||||
for (l = children; l; l = g_list_next (l))
|
||||
if (container == NULL)
|
||||
goto out;
|
||||
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterTableChild *meta;
|
||||
|
||||
meta = CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager, container, child));
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
|
||||
container,
|
||||
child));
|
||||
|
||||
n_cols = MAX (n_cols, meta->col + meta->col_span);
|
||||
n_rows = MAX (n_rows, meta->row + meta->row_span);
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
|
||||
out:
|
||||
priv->n_cols = n_cols;
|
||||
priv->n_rows = n_rows;
|
||||
|
||||
@ -743,9 +749,9 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
{
|
||||
ClutterTableLayoutPrivate *priv = self->priv;
|
||||
ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (self);
|
||||
ClutterActor *actor, *child;
|
||||
gint i;
|
||||
DimensionData *columns;
|
||||
GList *l, *children;
|
||||
|
||||
update_row_col (self, container);
|
||||
g_array_set_size (priv->columns, 0);
|
||||
@ -757,12 +763,13 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
for (i = 0; i < priv->n_cols; i++)
|
||||
columns[i].visible = FALSE;
|
||||
|
||||
children = clutter_container_get_children (container);
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
|
||||
/* STAGE ONE: calculate column widths for non-spanned children */
|
||||
for (l = children; l; l = g_list_next (l))
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterTableChild *meta;
|
||||
DimensionData *col;
|
||||
gfloat c_min, c_pref;
|
||||
@ -770,8 +777,10 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||
continue;
|
||||
|
||||
meta = (ClutterTableChild *)
|
||||
clutter_layout_manager_get_child_meta (manager, container, child);
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
|
||||
container,
|
||||
child));
|
||||
|
||||
if (meta->col_span > 1)
|
||||
continue;
|
||||
@ -792,9 +801,10 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
}
|
||||
|
||||
/* STAGE TWO: take spanning children into account */
|
||||
for (l = children; l; l = g_list_next (l))
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterTableChild *meta;
|
||||
DimensionData *col;
|
||||
gfloat c_min, c_pref;
|
||||
@ -805,8 +815,10 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||
continue;
|
||||
|
||||
meta = (ClutterTableChild *)
|
||||
clutter_layout_manager_get_child_meta (manager, container, child);
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
|
||||
container,
|
||||
child));
|
||||
|
||||
if (meta->col_span < 2)
|
||||
continue;
|
||||
@ -890,7 +902,6 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
|
||||
|
||||
}
|
||||
g_list_free (children);
|
||||
|
||||
/* calculate final widths */
|
||||
if (for_width >= 0)
|
||||
@ -901,6 +912,7 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
min_width = 0;
|
||||
pref_width = 0;
|
||||
n_expand = 0;
|
||||
|
||||
for (i = 0; i < self->priv->n_cols; i++)
|
||||
{
|
||||
pref_width += columns[i].pref_size;
|
||||
@ -908,6 +920,7 @@ calculate_col_widths (ClutterTableLayout *self,
|
||||
if (columns[i].expand)
|
||||
n_expand++;
|
||||
}
|
||||
|
||||
pref_width += priv->col_spacing * (priv->n_cols - 1);
|
||||
min_width += priv->col_spacing * (priv->n_cols - 1);
|
||||
|
||||
@ -1003,7 +1016,7 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
{
|
||||
ClutterTableLayoutPrivate *priv = self->priv;
|
||||
ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (self);
|
||||
GList *l, *children;
|
||||
ClutterActor *actor, *child;
|
||||
gint i;
|
||||
DimensionData *rows, *columns;
|
||||
|
||||
@ -1019,11 +1032,13 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
for (i = 0; i < priv->n_rows; i++)
|
||||
rows[i].visible = FALSE;
|
||||
|
||||
children = clutter_container_get_children (container);
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
|
||||
/* STAGE ONE: calculate row heights for non-spanned children */
|
||||
for (l = children; l; l = g_list_next (l))
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterTableChild *meta;
|
||||
DimensionData *row;
|
||||
gfloat c_min, c_pref;
|
||||
@ -1031,8 +1046,10 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||
continue;
|
||||
|
||||
meta = (ClutterTableChild *)
|
||||
clutter_layout_manager_get_child_meta (manager, container, child);
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
|
||||
container,
|
||||
child));
|
||||
|
||||
if (meta->row_span > 1)
|
||||
continue;
|
||||
@ -1053,12 +1070,11 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
row->expand = MAX (row->expand, meta->y_expand);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* STAGE TWO: take spanning children into account */
|
||||
for (l = children; l; l = g_list_next (l))
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = l->data;
|
||||
ClutterTableChild *meta;
|
||||
gfloat c_min, c_pref;
|
||||
gfloat min_height, pref_height;
|
||||
@ -1068,8 +1084,10 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||
continue;
|
||||
|
||||
meta = (ClutterTableChild *)
|
||||
clutter_layout_manager_get_child_meta (manager, container, child);
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
|
||||
container,
|
||||
child));
|
||||
|
||||
if (meta->row_span < 2)
|
||||
continue;
|
||||
@ -1165,8 +1183,6 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
|
||||
/* calculate final heights */
|
||||
if (for_height >= 0)
|
||||
{
|
||||
@ -1176,6 +1192,7 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
min_height = 0;
|
||||
pref_height = 0;
|
||||
n_expand = 0;
|
||||
|
||||
for (i = 0; i < self->priv->n_rows; i++)
|
||||
{
|
||||
pref_height += rows[i].pref_size;
|
||||
@ -1183,6 +1200,7 @@ calculate_row_heights (ClutterTableLayout *self,
|
||||
if (rows[i].expand)
|
||||
n_expand++;
|
||||
}
|
||||
|
||||
pref_height += priv->row_spacing * (priv->n_rows - 1);
|
||||
min_height += priv->row_spacing * (priv->n_rows - 1);
|
||||
|
||||
@ -1387,7 +1405,7 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout,
|
||||
{
|
||||
ClutterTableLayout *self = CLUTTER_TABLE_LAYOUT (layout);
|
||||
ClutterTableLayoutPrivate *priv = self->priv;
|
||||
GList *list, *children;
|
||||
ClutterActor *actor, *child;
|
||||
gint row_spacing, col_spacing;
|
||||
gint i;
|
||||
DimensionData *rows, *columns;
|
||||
@ -1396,8 +1414,9 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout,
|
||||
if (priv->n_cols < 1 || priv->n_rows < 1)
|
||||
return;
|
||||
|
||||
children = clutter_container_get_children (container);
|
||||
if (children == NULL)
|
||||
actor = CLUTTER_ACTOR (container);
|
||||
|
||||
if (clutter_actor_get_n_children (actor) == 0)
|
||||
return;
|
||||
|
||||
col_spacing = (priv->col_spacing);
|
||||
@ -1410,9 +1429,10 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout,
|
||||
rows = (DimensionData *) priv->rows->data;
|
||||
columns = (DimensionData *) priv->columns->data;
|
||||
|
||||
for (list = children; list; list = g_list_next (list))
|
||||
for (child = clutter_actor_get_first_child (actor);
|
||||
child != NULL;
|
||||
child = clutter_actor_get_next_sibling (child))
|
||||
{
|
||||
ClutterActor *child = list->data;
|
||||
gint row, col, row_span, col_span;
|
||||
gint col_width, row_height;
|
||||
ClutterTableChild *meta;
|
||||
@ -1424,8 +1444,10 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout,
|
||||
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||
continue;
|
||||
|
||||
meta = (ClutterTableChild *)
|
||||
clutter_layout_manager_get_child_meta (layout, priv->container, child);
|
||||
meta =
|
||||
CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (layout,
|
||||
container,
|
||||
child));
|
||||
|
||||
/* get child properties */
|
||||
col = meta->col;
|
||||
@ -1560,8 +1582,6 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout,
|
||||
do_allocate:
|
||||
clutter_actor_allocate (child, &childbox, flags);
|
||||
}
|
||||
|
||||
g_list_free (children);
|
||||
}
|
||||
|
||||
static ClutterAlpha *
|
||||
|
Loading…
Reference in New Issue
Block a user