From fb6d01cd76d4c2bc93e693f4d079aab109e8f99a Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 6 Aug 2007 19:37:00 +0000 Subject: [PATCH] Port ClutterVBox to the new ClutterBox implementation Like ClutterHBox, ClutterVBox now takes into account the per-child padding and the per-box margin. --- clutter/clutter-vbox.c | 71 +++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/clutter/clutter-vbox.c b/clutter/clutter-vbox.c index 3c6cef70b..86e44bfa2 100644 --- a/clutter/clutter-vbox.c +++ b/clutter/clutter-vbox.c @@ -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); }