clutter/actor: Add API to get fixed position

It's currently a bit hard to get the fixed position of an actor. It can
be either done by using g_object_get() with the "fixed-x"/"fixed-y"
properties or by calling clutter_actor_get_position().

Calling clutter_actor_get_position() can return the fixed position, but
it might also return the allocated position if the allocation is valid.
The latter is not the best behavior when querying the fixed position
during an allocation, so introduce a new function
clutter_actor_get_fixed_position() which always gets the fixed position
and returns FALSE in case no fixed position is set.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1310
This commit is contained in:
Jonas Dreßler 2020-06-19 13:32:59 +02:00 committed by verdre
parent d722e59aac
commit dfa235aa5d
2 changed files with 41 additions and 0 deletions

View File

@ -10258,6 +10258,43 @@ clutter_actor_get_position (ClutterActor *self,
*y = clutter_actor_get_y (self);
}
/**
* clutter_actor_get_fixed_position:
* @self: a #ClutterActor
* @x: (out) (allow-none): return location for the X coordinate, or %NULL
* @y: (out) (allow-none): return location for the Y coordinate, or %NULL
*
* This function gets the fixed position of the actor, if set. If there
* is no fixed position set, this function returns %FALSE and doesn't set
* the x and y coordinates.
*
* Returns: %TRUE if the fixed position is set, %FALSE if it isn't
*/
gboolean
clutter_actor_get_fixed_position (ClutterActor *self,
float *x,
float *y)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
if (self->priv->position_set)
{
const ClutterLayoutInfo *info;
info = _clutter_actor_get_layout_info_or_defaults (self);
if (x)
*x = info->fixed_pos.x;
if (y)
*y = info->fixed_pos.y;
return TRUE;
}
return FALSE;
}
/**
* clutter_actor_get_transformed_position:
* @self: A #ClutterActor

View File

@ -454,6 +454,10 @@ void clutter_actor_set_position
gfloat x,
gfloat y);
CLUTTER_EXPORT
gboolean clutter_actor_get_fixed_position (ClutterActor *self,
float *x,
float *y);
CLUTTER_EXPORT
void clutter_actor_get_position (ClutterActor *self,
gfloat *x,
gfloat *y);