[Sugar-devel] Force icon sizes in style.py to be even numbers

Daniel Drake dsd at laptop.org
Mon Oct 3 18:12:43 EDT 2011


Hi,

While working on no-hippo stuff I have solved one of our old bugs: the
issue where when you move from one view to the other, the XO man zoom
animation leaves the XO man in the wrong position and then he
uncomfortably 'jumps' into place on the final frame. It's actually
broken into 2 parts:

One of the issues is a simple rounding error 2 places in the code.

The second issue is a little wider reaching.
The issue is that on the friends and neighborhood view, icons are
placed based on a grid.
Each grid cell is 4x4 pixels. An icon tends to occupy a whole series
of grid cells.
As we don't render icons to strict multiples of 4 pixels in
height/width, an icon will often occupy a series of grid cells but
have some space left over.
For example, style.LARGE_ICON_SIZE comes out as '59' here. The icon
will be rendered at 59 pixels in height in a 60 pixel tall box made up
of 15 grid cells (15*4=60) in that dimension.

Now we reach the problem. If we give my icon more space than it needs,
we need to be able to center the rendered icon in its box. Otherwise
we get uncomfortable jumps like the ones you see when changing views.
And how can you center something perfectly if one of its dimensions is
59 pixels in a box of 60 pixels?

The solution I'm proposing is when packing icons into grid cells, we
make sure they have dimensions that are even numbers. Therefore they
will either fill their grid cells completely, or can be padded with an
equal number of pixels on each side to center them accurately.

So I could dance through the code, finding every case where an icon is
added to a grid-based view, and round all icon sizes to even numbers.
But there are a lot:
On the friends view: buddy icon, activity icon, owner icon
On the network view: all the different types of networks, activity
icon, owner icon

And if I force some of the changes to be wider-reaching, like making
BuddyIcon enforce even dimensions (regardless of being in a grid or
not), it would affect other users (like the frame) who don't care for
even numbered dimensions.

So,  with so many little places in the code to truncate these numbers
(which could easily be forgotten in future), and some side effects,
I'm tempted by another solution:
make style.py define all icon sizes as even numbers. i.e.:

STANDARD_ICON_SIZE = zoom(55) & ~1
SMALL_ICON_SIZE = zoom(55 * 0.5) & ~1
MEDIUM_ICON_SIZE = zoom(55 * 1.5) & ~1
LARGE_ICON_SIZE = zoom(55 * 2.0) & ~1
XLARGE_ICON_SIZE = zoom(55 * 2.75) & ~1

Would this be acceptable?

Thanks,
Daniel


More information about the Sugar-devel mailing list