clutter/align-constraint: Don't take source actors position into account

ClutterAlignConstraint currently assumes the source actor is positioned
in the same coordinate system as the actor it's attached to and
automatically offsets the adjusted allocation by the origin of the
source actor.

This behavior is only valid though in case the source actor is a sibling
of the constraint actor. If the source actor is somewhere else in the
actor tree, the behavior gets annoying because the constraint actor is
offset by (seemingly) random positions.

To fix this, stop offsetting the constraint actors allocation by the
position of the source.

To still make it possible to align the constraint actors origin with the
origin of the source, no longer override the origin of the allocation
in the AlignConstraint. This allows users to align the origin using a
BindConstraint, binding the actor position to the position of the
source, which is more flexible and also more elegant.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/737
This commit is contained in:
Jonas Dreßler 2020-06-04 19:44:45 +02:00 committed by Georges Basile Stavracas Neto
parent 590b9b8c86
commit 77d359cdc3

View File

@ -135,7 +135,6 @@ clutter_align_constraint_update_allocation (ClutterConstraint *constraint,
ClutterAlignConstraint *align = CLUTTER_ALIGN_CONSTRAINT (constraint); ClutterAlignConstraint *align = CLUTTER_ALIGN_CONSTRAINT (constraint);
gfloat source_width, source_height; gfloat source_width, source_height;
gfloat actor_width, actor_height; gfloat actor_width, actor_height;
gfloat source_x, source_y;
gfloat offset_x_start, offset_y_start; gfloat offset_x_start, offset_y_start;
gfloat pivot_x, pivot_y; gfloat pivot_x, pivot_y;
@ -144,7 +143,6 @@ clutter_align_constraint_update_allocation (ClutterConstraint *constraint,
clutter_actor_box_get_size (allocation, &actor_width, &actor_height); clutter_actor_box_get_size (allocation, &actor_width, &actor_height);
clutter_actor_get_position (align->source, &source_x, &source_y);
clutter_actor_get_size (align->source, &source_width, &source_height); clutter_actor_get_size (align->source, &source_width, &source_height);
pivot_x = align->pivot.x == -1.f pivot_x = align->pivot.x == -1.f
@ -160,18 +158,18 @@ clutter_align_constraint_update_allocation (ClutterConstraint *constraint,
switch (align->align_axis) switch (align->align_axis)
{ {
case CLUTTER_ALIGN_X_AXIS: case CLUTTER_ALIGN_X_AXIS:
allocation->x1 = source_x + offset_x_start + (source_width * align->factor); allocation->x1 += offset_x_start + (source_width * align->factor);
allocation->x2 = allocation->x1 + actor_width; allocation->x2 = allocation->x1 + actor_width;
break; break;
case CLUTTER_ALIGN_Y_AXIS: case CLUTTER_ALIGN_Y_AXIS:
allocation->y1 = source_y + offset_y_start + (source_height * align->factor); allocation->y1 += offset_y_start + (source_height * align->factor);
allocation->y2 = allocation->y1 + actor_height; allocation->y2 = allocation->y1 + actor_height;
break; break;
case CLUTTER_ALIGN_BOTH: case CLUTTER_ALIGN_BOTH:
allocation->x1 = source_x + offset_x_start + (source_width * align->factor); allocation->x1 += offset_x_start + (source_width * align->factor);
allocation->y1 = source_y + offset_y_start + (source_height * align->factor); allocation->y1 += offset_y_start + (source_height * align->factor);
allocation->x2 = allocation->x1 + actor_width; allocation->x2 = allocation->x1 + actor_width;
allocation->y2 = allocation->y1 + actor_height; allocation->y2 = allocation->y1 + actor_height;
break; break;