From 03d177cf64479c43585a86f7bc1fc85fe55ec2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 19 Jun 2020 13:37:12 +0200 Subject: [PATCH] clutter/actor: Add position argument to allocate_preferred_size() Make clutter_actor_allocate_preferred_size() convenient to use from layout managers by not "automatically" honouring the fixed position of the actor, but instead allowing to pass a position to allocate the actor at. This way we can move the handling of fixed positions to ClutterFixedLayout, the layout manager which is responsible for allocating actors using fixed positions. This also makes clutter_actor_allocate_preferred_size() more similar to clutter_actor_allocate_available_size(). https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1310 --- clutter/clutter/clutter-actor.c | 27 +++++++------------------- clutter/clutter/clutter-actor.h | 4 +++- clutter/clutter/clutter-clone.c | 8 +++++++- clutter/clutter/clutter-fixed-layout.c | 6 +++++- clutter/clutter/clutter-stage.c | 5 ++++- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index c5ce7300f..2dcb07df2 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -14034,6 +14034,8 @@ clutter_actor_allocate_available_size (ClutterActor *self, /** * clutter_actor_allocate_preferred_size: * @self: a #ClutterActor + * @x: the actor's X coordinate + * @y: the actor's Y coordinate * * Allocates the natural size of @self. * @@ -14051,37 +14053,22 @@ clutter_actor_allocate_available_size (ClutterActor *self, * Since: 0.8 */ void -clutter_actor_allocate_preferred_size (ClutterActor *self) +clutter_actor_allocate_preferred_size (ClutterActor *self, + float x, + float y) { - gfloat actor_x, actor_y; gfloat natural_width, natural_height; ClutterActorBox actor_box; - ClutterActorPrivate *priv; - const ClutterLayoutInfo *info; g_return_if_fail (CLUTTER_IS_ACTOR (self)); - priv = self->priv; - - if (priv->position_set) - { - info = _clutter_actor_get_layout_info_or_defaults (self); - actor_x = info->fixed_pos.x; - actor_y = info->fixed_pos.y; - } - else - { - actor_x = 0; - actor_y = 0; - } - clutter_actor_get_preferred_size (self, NULL, NULL, &natural_width, &natural_height); - actor_box.x1 = actor_x; - actor_box.y1 = actor_y; + actor_box.x1 = x; + actor_box.y1 = y; actor_box.x2 = actor_box.x1 + natural_width; actor_box.y2 = actor_box.y1 + natural_height; diff --git a/clutter/clutter/clutter-actor.h b/clutter/clutter/clutter-actor.h index a9829f02d..d28983172 100644 --- a/clutter/clutter/clutter-actor.h +++ b/clutter/clutter/clutter-actor.h @@ -419,7 +419,9 @@ CLUTTER_EXPORT void clutter_actor_allocate (ClutterActor *self, const ClutterActorBox *box); CLUTTER_EXPORT -void clutter_actor_allocate_preferred_size (ClutterActor *self); +void clutter_actor_allocate_preferred_size (ClutterActor *self, + float x, + float y); CLUTTER_EXPORT void clutter_actor_allocate_available_size (ClutterActor *self, gfloat x, diff --git a/clutter/clutter/clutter-clone.c b/clutter/clutter/clutter-clone.c index f130a3c98..4373ad7a1 100644 --- a/clutter/clutter/clutter-clone.c +++ b/clutter/clutter/clutter-clone.c @@ -245,7 +245,13 @@ clutter_clone_allocate (ClutterActor *self, */ if (clutter_actor_get_parent (priv->clone_source) != NULL && !clutter_actor_has_allocation (priv->clone_source)) - clutter_actor_allocate_preferred_size (priv->clone_source); + { + float x = 0.f; + float y = 0.f; + + clutter_actor_get_fixed_position (priv->clone_source, &x, &y); + clutter_actor_allocate_preferred_size (priv->clone_source, x, y); + } clutter_actor_get_allocation_box (priv->clone_source, &source_box); diff --git a/clutter/clutter/clutter-fixed-layout.c b/clutter/clutter/clutter-fixed-layout.c index 324084809..095f2d752 100644 --- a/clutter/clutter/clutter-fixed-layout.c +++ b/clutter/clutter/clutter-fixed-layout.c @@ -139,7 +139,11 @@ clutter_fixed_layout_allocate (ClutterLayoutManager *manager, child != NULL; child = clutter_actor_get_next_sibling (child)) { - clutter_actor_allocate_preferred_size (child); + float x = 0.f; + float y = 0.f; + + clutter_actor_get_fixed_position (child, &x, &y); + clutter_actor_allocate_preferred_size (child, x, y); } } diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 51f738217..454e6942e 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -1245,6 +1245,8 @@ clutter_stage_maybe_relayout (ClutterActor *actor) for (l = stolen_list; l; l = l->next) { g_autoptr (ClutterActor) queued_actor = l->data; + float x = 0.f; + float y = 0.f; if (CLUTTER_ACTOR_IN_RELAYOUT (queued_actor)) /* avoid reentrancy */ continue; @@ -1258,7 +1260,8 @@ clutter_stage_maybe_relayout (ClutterActor *actor) CLUTTER_SET_PRIVATE_FLAGS (queued_actor, CLUTTER_IN_RELAYOUT); - clutter_actor_allocate_preferred_size (queued_actor); + clutter_actor_get_fixed_position (queued_actor, &x, &y); + clutter_actor_allocate_preferred_size (queued_actor, x, y); CLUTTER_UNSET_PRIVATE_FLAGS (queued_actor, CLUTTER_IN_RELAYOUT);