From e9b2f9f478750539ff9c76147b2d024e70fe958a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 1 Aug 2014 23:29:19 -0400 Subject: Began cleaning up the sizing/container/control stuff by changing container to sizing. --- redo/sizer.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ redo/sizing.go | 48 ------------------------------------------------ 2 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 redo/sizer.go delete mode 100644 redo/sizing.go diff --git a/redo/sizer.go b/redo/sizer.go new file mode 100644 index 0000000..4862ac0 --- /dev/null +++ b/redo/sizer.go @@ -0,0 +1,50 @@ +// 25 june 2014 + +package ui + +type allocation struct { + x int + y int + width int + height int + this Control + neighbor Control +} + +type sizingbase struct { + xmargin int + ymargin int + xpadding int + ypadding int +} + +type controlSizing interface { + allocate(x int, y int, width int, height int, d *sizing) []*allocation + preferredSize(*sizing) (int, int) + commitResize(*allocation, *sizing) + getAuxResizeInfo(*sizing) +} + +// A sizer hosts a Control and resizes that Control based on changes in size to the parent Window. +// sizer is used by Window, Tab, and [TODO implement] Group to contain and control their respective controls. +// Window is the beginning of the resize chain; resizes happen on the system side. +// Tab and Group are Controls and thus implement controlSizing; they should call their internal sizers's resize() method in their own commitResize(). +type sizer struct { + child Control +} + +// set to true to apply spacing to all windows +var spaced bool = false + +func (c *sizer) resize(x, y, width, height int) { + if c.child == nil { // no children; nothing to do + return + } + d := c.beginResize() + allocations := c.child.allocate(x + d.xmargin, y + d.ymargin, width - (2 * d.xmargin), height - (2 * d.ymargin), d) + c.translateAllocationCoords(allocations, width, height) + // move in reverse so as to approximate right->left order so neighbors make sense + for i := len(allocations) - 1; i >= 0; i-- { + allocations[i].this.commitResize(allocations[i], d) + } +} diff --git a/redo/sizing.go b/redo/sizing.go deleted file mode 100644 index d9c3927..0000000 --- a/redo/sizing.go +++ /dev/null @@ -1,48 +0,0 @@ -// 25 june 2014 - -package ui - -type allocation struct { - x int - y int - width int - height int - this Control - neighbor Control -} - -type sizingbase struct { - xmargin int - ymargin int - xpadding int - ypadding int -} - -type controlSizing interface { - allocate(x int, y int, width int, height int, d *sizing) []*allocation - preferredSize(*sizing) (int, int) - commitResize(*allocation, *sizing) - getAuxResizeInfo(*sizing) -} - -// on Windows, this is only embedded by window, as all other containers cannot have their own children; beginResize() points to an instance method literal (TODO get correct term) from window -// on GTK+ and Mac OS X, one is embedded by window and all containers; beginResize() points to a global function (TODO NOT GOOD; ideally the sizing data should be passed across size-allocate requests) -type container struct { - child Control -} - -// set to true to apply spacing to all windows -var spaced bool = false - -func (c *container) resize(x, y, width, height int) { - if c.child == nil { // no children; nothing to do - return - } - d := c.beginResize() - allocations := c.child.allocate(x + d.xmargin, y + d.ymargin, width - (2 * d.xmargin), height - (2 * d.ymargin), d) - c.translateAllocationCoords(allocations, width, height) - // move in reverse so as to approximate right->left order so neighbors make sense - for i := len(allocations) - 1; i >= 0; i-- { - allocations[i].this.commitResize(allocations[i], d) - } -} -- cgit v1.2.3