[Sugar-devel] [PATCH] SpreadLayout: fix grid cell allocation

Daniel Drake dsd at laptop.org
Wed Oct 5 17:05:16 EDT 2011


The calculation of how many grid cells to assign a child element
has a bug in that it rounds down instead of up.

With a grid cell size of 4x4, if a child element of 9 pixels in size
is added, the current code calculates that it needs 2.25 grid cells,
but then rounds this down to 2. When the child gets drawn it will
then draw outside of the grid cell bounds it was given.

Fix this by rounding up instead of down: in the above example, 3 grid
cells would be allocated. The canvas elements used already centre
themselves within their allocation.

In current Sugar, I can't see any notable differences from this change.
However, this is a fairly obvious fix, and a necessary part of the
later solution to the issue where the owner icon zoom animation does not
quite match the location of the owner icon on the views.
---
 src/jarabe/desktop/spreadlayout.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/jarabe/desktop/spreadlayout.py b/src/jarabe/desktop/spreadlayout.py
index 9200361..b5c623e 100644
--- a/src/jarabe/desktop/spreadlayout.py
+++ b/src/jarabe/desktop/spreadlayout.py
@@ -14,6 +14,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+import math
+
 import hippo
 import gobject
 import gtk
@@ -78,8 +80,10 @@ class SpreadLayout(gobject.GObject, hippo.CanvasLayout):
     def _get_child_grid_size(self, child):
         min_width, width = child.get_width_request()
         min_height, height = child.get_height_request(width)
+        width = math.ceil(width / _CELL_SIZE)
+        height = math.ceil(height / _CELL_SIZE)
 
-        return int(width / _CELL_SIZE), int(height / _CELL_SIZE)
+        return int(width), int(height)
 
     def _grid_child_changed_cb(self, grid, child):
         child.emit_request_changed()
-- 
1.7.6.4



More information about the Sugar-devel mailing list