From a4ebbc26795298e0e08274c6687eb9ee8f45664c Mon Sep 17 00:00:00 2001 From: Kyle McLamb Date: Tue, 4 Oct 2016 16:20:32 -0700 Subject: [PATCH 1/3] Fix bug with layout left()/up() When moving down/right, we use the old cell size because we are moving the start point outside of the existing cell. When we go up/right, we are doing actually doing the inverse operation, moving backwards using the new cell size. We still check to see if there's an old cell because up()/down()/left()/right() should behave the same for the first cell. --- layout.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/layout.lua b/layout.lua index 58c7034..f84fdd6 100644 --- a/layout.lua +++ b/layout.lua @@ -152,7 +152,7 @@ Layout.down = Layout.row function Layout:up(w, h) w,h = calc_width_height(self, w, h) - local x,y = self._x, self._y - (self._h or 0) + local x,y = self._x, self._y - (self._h and h or 0) if not self._isFirstCell then y = y - self._pady @@ -184,7 +184,7 @@ Layout.right = Layout.col function Layout:left(w, h) w,h = calc_width_height(self, w, h) - local x,y = self._x - (self._w or 0), self._y + local x,y = self._x - (self._w and w or 0), self._y if not self._isFirstCell then x = x - self._padx From 0084ccba2e21372058e38be6b82536a7d2b35bac Mon Sep 17 00:00:00 2001 From: Kyle McLamb Date: Tue, 4 Oct 2016 16:50:28 -0700 Subject: [PATCH 2/3] Remove nextUp() and nextLeft() We need the expected size of the new cell to do it correctly, and that would introduce an inconsistency between up/left and the existing row/col functions. --- layout.lua | 8 -------- 1 file changed, 8 deletions(-) diff --git a/layout.lua b/layout.lua index f84fdd6..fd6b08c 100644 --- a/layout.lua +++ b/layout.lua @@ -37,20 +37,12 @@ end Layout.nextDown = Layout.nextRow -function Layout:nextUp() - return self._x, self._y - self._h - self._pady -end - function Layout:nextCol() return self._x + self._w + self._padx, self._y end Layout.nextRight = Layout.nextCol -function Layout:nextLeft() - return self._x - self._w - self._padx, self._y -end - function Layout:push(x,y) self._stack[#self._stack+1] = { self._x, self._y, From ef317657caf38a743346db4e3902f17be0ce6a2b Mon Sep 17 00:00:00 2001 From: Kyle McLamb Date: Tue, 4 Oct 2016 17:28:08 -0700 Subject: [PATCH 3/3] Document layout:up/down/left/right() Consolation prize. --- docs/layout.rst | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/layout.rst b/docs/layout.rst index dfadf06..3faebd9 100644 --- a/docs/layout.rst +++ b/docs/layout.rst @@ -67,6 +67,8 @@ according to the size of the popped layout. Used for nested row/column layouts. +.. _layout-row: + .. function:: row(w,h) :param mixed w,h: Cell width and height (optional). @@ -91,14 +93,20 @@ Used to provide the last four arguments to a widget, e.g.:: suit.Button("Options", suit.layout:row()) suit.Button("Quit", suit.layout:row(nil, "median")) +.. function:: down(w,h) + +An alias for :ref:`layout:row() `. + +.. _layout-col: + .. function:: col(w,h) :param mixed w,h: Cell width and height (optional). :returns: Position and size of the cell: ``x,y,w,h``. -Creates a new cell right to the current cell with width ``w`` and height ``h``. -If either ``w`` or ``h`` is omitted, the value is set the last used value. Both -``w`` and ``h`` can be a string, which takes the following meaning: +Creates a new cell to the right of the current cell with width ``w`` and height +``h``. If either ``w`` or ``h`` is omitted, the value is set the last used +value. Both ``w`` and ``h`` can be a string, which takes the following meaning: ``max`` Maximum of all values since the last reset. @@ -114,6 +122,59 @@ Used to provide the last four arguments to a widget, e.g.:: suit.Button("OK", suit.layout:col(100,30)) suit.Button("Cancel", suit.layout:col("max")) +.. function:: right(w,h) + +An alias for :ref:`layout:col() `. + +.. function:: up(w,h) + + :param mixed w,h: Cell width and height (optional). + :returns: Position and size of the cell: ``x,y,w,h``. + +Creates a new cell above the current cell with width ``w`` and height ``h``. If +either ``w`` or ``h`` is omitted, the value is set the last used value. Both +``w`` and ``h`` can be a string, which takes the following meaning: + +``max`` + Maximum of all values since the last reset. + +``min`` + Mimimum of all values since the last reset. + +``median`` + Median of all values since the last reset. + +Be careful when mixing ``up()`` and :ref:`layout:row() `, as suit +does no checking to make sure cells don't overlap. e.g.:: + + suit.Button("A", suit.layout:row(100,30)) + suit.Button("B", suit.layout:row()) + suit.Button("Also A", suit.layout:up()) + +.. function:: left(w,h) + + :param mixed w,h: Cell width and height (optional). + :returns: Position and size of the cell: ``x,y,w,h``. + +Creates a new cell to the left of the current cell with width ``w`` and height +``h``. If either ``w`` or ``h`` is omitted, the value is set the last used +value. Both ``w`` and ``h`` can be a string, which takes the following meaning: + +``max`` + Maximum of all values since the last reset. + +``min`` + Mimimum of all values since the last reset. + +``median`` + Median of all values since the last reset. + +Be careful when mixing ``left()`` and :ref:`layout:col() `, as suit +does no checking to make sure cells don't overlap. e.g.:: + + suit.Button("A", suit.layout:col(100,30)) + suit.Button("B", suit.layout:col()) + suit.Button("Also A", suit.layout:left()) Precomputed Layouts -------------------