changeset 69:4e5f2f16cb84

TileGrid: new increaseCols/decreaseCols methods Not currently bound to any action, but they work as expected. This will be useful once I have a better UI designed for this. It's sometimes helpful for rearranging the tiles at a different size.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 09 Sep 2019 17:59:06 -0400
parents 7cbaec8720d6
children f0ee922fe0de
files tilerswift
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tilerswift
+++ b/tilerswift
@@ -201,6 +201,7 @@
             self.tilesize*self.numcols + self.spacing,
             self.tilesize*self.numrows + self.spacing,
         ))
+        self.tiles.resize(self.numrows, self.numcols)
         self.update()
 
     def zoomOut(self):
@@ -219,6 +220,24 @@
 
         self.resize()
 
+    def computeNumRows(self):
+        pass
+
+    def increaseCols(self):
+        maxcols = len(self.tiles)
+        self.numcols += 1
+        if self.numcols > maxcols:
+            self.numcols = maxcols
+        self.computeNumRows()
+        self.resize()
+
+    def decreaseCols(self):
+        self.numcols -= 1
+        if self.numcols < 1:
+            self.numcols = 1
+        self.computeNumRows()
+        self.resize()
+
 
 class ROMCanvas(TileGrid):
     CSS = """
@@ -244,6 +263,9 @@
 
         self.resize()
 
+    def computeNumRows(self):
+        self.numrows = len(self.tiles)//self.numcols
+
     def mousePressEvent(self, event):
         i, j = self.coordsToTileIndices(event.x(), event.y())
         tile = self.tiles[i, j]