diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 3dc06e635..3d6cab872 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -8166,6 +8166,118 @@ clutter_actor_get_stage (ClutterActor *actor) return actor; } +/** + * clutter_actor_allocate_available_size: + * @self: a #ClutterActor + * @x: the actor's X coordinate + * @y: the actor's Y coordinate + * @available_width: the maximum available width, or -1 to use the + * actor's natural width + * @available_height: the maximum available height, or -1 to use the + * actor's natural height + * @absolute_origin_changed: whether the position of the parent has + * changed in stage coordinates + * + * Allocates @self taking into account the #ClutterActor's + * preferred size, but limiting it to the maximum available width + * and height provided. + * + * This function will do the right thing when dealing with the + * actor's request mode. + * + * The implementation of this function is equivalent to: + * + * |[ + * if (request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH) + * { + * clutter_actor_get_preferred_width (self, available_height, + * &min_width, + * &natural_width); + * width = CLAMP (natural_width, min_width, available_width); + * + * clutter_actor_get_preferred_height (self, width, + * &min_height, + * &natural_height); + * height = CLAMP (natural_height, min_height, available_height); + * } + * else + * { + * clutter_actor_get_preferred_height (self, available_width, + * &min_height, + * &natural_height); + * height = CLAMP (natural_height, min_height, available_height); + * + * clutter_actor_get_preferred_width (self, height, + * &min_width, + * &natural_width); + * width = CLAMP (natural_width, min_width, available_width); + * } + * + * box.x1 = x; box.y1 = y; + * box.x2 = box.x1 + available_width; + * box.y2 = box.y1 + available_height; + * clutter_actor_allocate (self, &box, absolute_origin_changed); + * ]| + * + * This function can be used by fluid layout managers to allocate + * an actor's preferred size without making it bigger than the area + * available for the container. + * + * Since: 1.0 + */ +void +clutter_actor_allocate_available_size (ClutterActor *self, + gfloat x, + gfloat y, + gfloat available_width, + gfloat available_height, + gboolean absolute_origin_changed) +{ + ClutterActorPrivate *priv; + gfloat width, height; + gfloat min_width, min_height; + gfloat natural_width, natural_height; + ClutterActorBox box; + + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + + priv = self->priv; + + switch (priv->request_mode) + { + case CLUTTER_REQUEST_HEIGHT_FOR_WIDTH: + clutter_actor_get_preferred_width (self, available_height, + &min_width, + &natural_width); + width = CLAMP (natural_width, min_width, available_width); + + clutter_actor_get_preferred_height (self, width, + &min_height, + &natural_height); + height = CLAMP (natural_height, min_height, available_height); + break; + + case CLUTTER_REQUEST_WIDTH_FOR_HEIGHT: + clutter_actor_get_preferred_height (self, available_width, + &min_height, + &natural_height); + height = CLAMP (natural_height, min_height, available_height); + + clutter_actor_get_preferred_width (self, height, + &min_width, + &natural_width); + width = CLAMP (natural_width, min_width, available_width); + break; + } + + + box.x1 = x; + box.y1 = y; + box.x2 = box.x1 + width; + box.y2 = box.y1 + height; + clutter_actor_allocate (self, &box, absolute_origin_changed); +} + /** * clutter_actor_allocate_preferred_size: * @self: a #ClutterActor diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h index 086b64d10..e30f85b66 100644 --- a/clutter/clutter-actor.h +++ b/clutter/clutter-actor.h @@ -323,6 +323,12 @@ void clutter_actor_allocate (ClutterActor gboolean absolute_origin_changed); void clutter_actor_allocate_preferred_size (ClutterActor *self, gboolean absolute_origin_changed); +void clutter_actor_allocate_available_size (ClutterActor *self, + gfloat x, + gfloat y, + gfloat available_width, + gfloat available_height, + gboolean absolute_origin_changed); void clutter_actor_get_allocation_coords (ClutterActor *self, gint *x_1, gint *y_1, diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 67c1eb866..142d28b82 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -301,6 +301,7 @@ clutter_actor_unmap clutter_actor_allocate clutter_actor_allocate_preferred_size +clutter_actor_allocate_available_size clutter_actor_get_allocation_coords clutter_actor_get_allocation_box clutter_actor_get_allocation_geometry