From f25cdf066c023222330119a1fe8ef5204773faa7 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 13 Aug 2009 12:26:09 +0100 Subject: [PATCH] [actor] Allow unsetting width and height separately It is possible to unset the size of an actor specified with set_width() and set_height() by using: clutter_actor_set_size (actor, -1, -1); Which works by unsetting the :min-*-set and the :natural-*-set properties. Calling set_width(-1) and set_height(-1) separately, though, doesn't work thus implicitly breaking the assumption that set_size() is nothing more than set_width()+set_height(). This was obviously due to the face that pre-1.0 set_width() and set_height() took an unsigned integer as an argument. --- clutter/clutter-actor.c | 81 ++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 8b0d191a4..a152f8389 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -5167,6 +5167,44 @@ clutter_actor_set_request_mode (ClutterActor *self, clutter_actor_queue_relayout (self); } +/* variant of set_width() without checks and without notification + * freeze+thaw, for internal usage only + */ +static inline void +clutter_actor_set_width_internal (ClutterActor *self, + gfloat width) +{ + if (width >= 0) + { + clutter_actor_set_min_width (self, width); + clutter_actor_set_natural_width (self, width); + } + else + { + clutter_actor_set_min_width_set (self, FALSE); + clutter_actor_set_natural_width_set (self, FALSE); + } +} + +/* variant of set_height() without checks and without notification + * freeze+thaw, for internal usage only + */ +static inline void +clutter_actor_set_height_internal (ClutterActor *self, + gfloat height) +{ + if (height >= 0) + { + clutter_actor_set_min_height (self, height); + clutter_actor_set_natural_height (self, height); + } + else + { + clutter_actor_set_min_height_set (self, FALSE); + clutter_actor_set_natural_height_set (self, FALSE); + } +} + /** * clutter_actor_set_size * @self: A #ClutterActor @@ -5193,27 +5231,8 @@ clutter_actor_set_size (ClutterActor *self, g_object_freeze_notify (G_OBJECT (self)); - if (width >= 0) - { - clutter_actor_set_min_width (self, width); - clutter_actor_set_natural_width (self, width); - } - else - { - clutter_actor_set_min_width_set (self, FALSE); - clutter_actor_set_natural_width_set (self, FALSE); - } - - if (height >= 0) - { - clutter_actor_set_min_height (self, height); - clutter_actor_set_natural_height (self, height); - } - else - { - clutter_actor_set_min_height_set (self, FALSE); - clutter_actor_set_natural_height_set (self, FALSE); - } + clutter_actor_set_width_internal (self, width); + clutter_actor_set_height_internal (self, height); g_object_thaw_notify (G_OBJECT (self)); } @@ -5513,15 +5532,18 @@ clutter_actor_get_height (ClutterActor *self) /** * clutter_actor_set_width * @self: A #ClutterActor - * @width: Requested new width for the actor, in pixels + * @width: Requested new width for the actor, in pixels, or -1 * * Forces a width on an actor, causing the actor's preferred width * and height (if any) to be ignored. * + * If @width is -1 the actor will use its preferred width request + * instead of overriding it, i.e. you can "unset" the width with -1. + * * This function sets both the minimum and natural size of the actor. * * since: 0.2 - **/ + */ void clutter_actor_set_width (ClutterActor *self, gfloat width) @@ -5530,8 +5552,7 @@ clutter_actor_set_width (ClutterActor *self, g_object_freeze_notify (G_OBJECT (self)); - clutter_actor_set_min_width (self, width); - clutter_actor_set_natural_width (self, width); + clutter_actor_set_width_internal (self, width); g_object_thaw_notify (G_OBJECT (self)); } @@ -5539,15 +5560,18 @@ clutter_actor_set_width (ClutterActor *self, /** * clutter_actor_set_height * @self: A #ClutterActor - * @height: Requested new height for the actor, in pixels + * @height: Requested new height for the actor, in pixels, or -1 * * Forces a height on an actor, causing the actor's preferred width * and height (if any) to be ignored. * + * If @height is -1 the actor will use its preferred height instead of + * overriding it, i.e. you can "unset" the height with -1. + * * This function sets both the minimum and natural size of the actor. * * since: 0.2 - **/ + */ void clutter_actor_set_height (ClutterActor *self, gfloat height) @@ -5556,8 +5580,7 @@ clutter_actor_set_height (ClutterActor *self, g_object_freeze_notify (G_OBJECT (self)); - clutter_actor_set_min_height (self, height); - clutter_actor_set_natural_height (self, height); + clutter_actor_set_height_internal (self, height); g_object_thaw_notify (G_OBJECT (self)); }