actor: fix allocate_align_fill() to maintain the child preferred size

When trying to clamp to pixel a box that is exactly in between 2
pixels, the clutter_actor_box_clamp_to_pixel() function changes the
size of the box.

Here is an example :

ClutterActorBox box = { 10.5, 10, 20.5, 20};

g_message ("%fx%f -> %fx%f", box.x1, box.y1, box.x2, box.y2);
clutter_actor_box_clamp_to_pixel (&box);
g_message ("%fx%f -> %fx%f", box.x1, box.y1, box.x2, box.y2);

Here is what you get :

** Message: 10.500000x10.000000 -> 20.500000x20.000000
** Message: 10.000000x10.000000 -> 21.000000x20.000000

That is because of the properties of the ceilf and floorf function
used to do the clamping.

For example, ceil(0.5) is 1.0, and ceil(-0.5) is 0.0.
And, floor(0.5) is 0.0, and floor(-0.5) is -1.0.

To work around that problem this patch retains the distance between x
and y coordinates and apply that difference before calling ceilf() on
x2 and y2.

https://bugzilla.gnome.org/show_bug.cgi?id=689073
This commit is contained in:
Lionel Landwerlin 2012-11-26 10:30:47 +00:00
parent c49bfa1998
commit da498fdb9a

View File

@ -15251,7 +15251,15 @@ clutter_actor_allocate_align_fill (ClutterActor *self,
}
out:
clutter_actor_box_clamp_to_pixel (&allocation);
child_width = allocation.x2 - allocation.x1;
child_height = allocation.y2 - allocation.y1;
allocation.x1 = floorf (allocation.x1);
allocation.y1 = floorf (allocation.y1);
allocation.x2 = ceilf (allocation.x1 + child_width);
allocation.y2 = ceilf (allocation.y1 + child_height);
clutter_actor_allocate (self, &allocation, flags);
}