Port ClutterVBox to the new ClutterBox implementation

Like ClutterHBox, ClutterVBox now takes into account the per-child
padding and the per-box margin.
This commit is contained in:
Emmanuele Bassi 2007-08-06 19:37:00 +00:00
parent 6005c0849d
commit fb6d01cd76

View File

@ -40,13 +40,22 @@ clutter_vbox_query_coords (ClutterActor *actor,
ClutterActorBox *coords)
{
ClutterBox *box = CLUTTER_BOX (actor);
ClutterMargin box_margin;
GList *l;
gint width, height;
guint spacing;
spacing = clutter_box_get_spacing (box);
width = height = 0;
if (box->allocation.x2 != -1 && box->allocation.y2 != -1)
{
coords->x2 = box->allocation.x2;
coords->y2 = box->allocation.y2;
return;
}
clutter_box_get_margin (box, &box_margin);
width = CLUTTER_UNITS_TO_INT (box_margin.left);
height = CLUTTER_UNITS_TO_INT (box_margin.top);
for (l = box->children; l; l = l->next)
{
ClutterBoxChild *child = l->data;
@ -57,20 +66,38 @@ clutter_vbox_query_coords (ClutterActor *actor,
clutter_actor_get_size (child->actor, &child_width, &child_height);
width = MAX (child_width, width);
height += child_height + (spacing * 2);
height = height
+ CLUTTER_UNITS_TO_INT (child->padding.top)
+ child_height
+ CLUTTER_UNITS_TO_INT (child->padding.bottom);
width = MAX ((child_width
+ CLUTTER_UNITS_TO_INT (child->padding.left)
+ CLUTTER_UNITS_TO_INT (child->padding.right)),
width);
}
}
coords->x2 = coords->x1 + CLUTTER_UNITS_FROM_INT (width);
coords->y2 = coords->y1 + CLUTTER_UNITS_FROM_INT (height);
width += CLUTTER_UNITS_TO_INT (box_margin.right);
height += CLUTTER_UNITS_TO_INT (box_margin.bottom);
box->allocation.x2 = coords->x2 =
coords->x1 + CLUTTER_UNITS_FROM_INT (width);
box->allocation.y2 = coords->y2 =
coords->y1 + CLUTTER_UNITS_FROM_INT (height);
}
static void
clutter_vbox_request_coords (ClutterActor *actor,
ClutterActorBox *coords)
{
/* FIXME */
ClutterBox *box = CLUTTER_BOX (actor);
/* we reset the allocation here */
box->allocation.x1 = coords->x1;
box->allocation.y1 = coords->y1;
box->allocation.x2 = -1;
box->allocation.y2 = -1;
}
static void
@ -78,15 +105,35 @@ clutter_vbox_pack_child (ClutterBox *box,
ClutterBoxChild *child)
{
ClutterGeometry box_geom, child_geom;
guint spacing;
ClutterMargin box_margin;
spacing = clutter_box_get_spacing (box);
/* reset the saved allocation */
box->allocation.x2 = box->allocation.y2 = -1;
clutter_actor_get_geometry (CLUTTER_ACTOR (box), &box_geom);
clutter_actor_get_geometry (child->actor, &child_geom);
child_geom.x = 0;
child_geom.y = box_geom.height + spacing;
clutter_box_get_margin (box, &box_margin);
if (child->pack_type == CLUTTER_PACK_START)
{
child_geom.x = CLUTTER_UNITS_TO_INT (child->padding.left);
child_geom.y = box_geom.height
+ CLUTTER_UNITS_TO_INT (child->padding.top);
}
else if (child->pack_type == CLUTTER_PACK_END)
{
child_geom.x = CLUTTER_UNITS_TO_INT (child->padding.left);
child_geom.y = box_geom.height - child_geom.height
- CLUTTER_UNITS_TO_INT (child->padding.bottom);
}
child->child_coords.x1 = CLUTTER_UNITS_FROM_INT (child_geom.x);
child->child_coords.y1 = CLUTTER_UNITS_FROM_INT (child_geom.y);
child->child_coords.x2 = CLUTTER_UNITS_FROM_INT (child_geom.x)
+ CLUTTER_UNITS_FROM_INT (child_geom.width);
child->child_coords.y2 = CLUTTER_UNITS_FROM_INT (child_geom.y)
+ CLUTTER_UNITS_FROM_INT (child_geom.height);
clutter_actor_set_geometry (child->actor, &child_geom);
}