From e4992dbcb2292a07c7d901dbe21f2d40f6af7a95 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 25 Jun 2014 22:07:37 -0400 Subject: Began the work for moving everything to the new control sizing system. --- control.go | 3 +- controlsize.go | 54 ++++++++++++++++++++++++ controlsize_sys.go | 82 +++++++++++++++++++++++++++++++++++ newsizing | 122 ----------------------------------------------------- sysdata.go | 26 +----------- window.go | 17 ++++++++ 6 files changed, 156 insertions(+), 148 deletions(-) create mode 100644 controlsize.go create mode 100644 controlsize_sys.go delete mode 100644 newsizing diff --git a/control.go b/control.go index 5cf9359..4da2694 100644 --- a/control.go +++ b/control.go @@ -5,6 +5,5 @@ package ui // A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, create an Area and provide an AreaHandler that does what you need. type Control interface { make(window *sysData) error - setRect(x int, y int, width int, height int, rr *[]resizerequest) - preferredSize() (width int, height int, yoff int) + controlSizing } diff --git a/controlsize.go b/controlsize.go new file mode 100644 index 0000000..d4d9d31 --- /dev/null +++ b/controlsize.go @@ -0,0 +1,54 @@ +// 25 june 2014 + +package ui + +type allocation struct { + x int + y int + width int + height int + this Control + neighbor Control +} + +// for verification; see sysdata.go +type sysDataSizeFuncs interface { + beginResize() *sysSizeData + endResize(*sysSizeData) + translateAllocationCoords([]*allocation, int, int) + preferredSize(*sysSizeData) (int, int) + commitResize(*allocation, *sysSizeData) + getAuxResizeInfo(*sysSizeData) +} + +func (s *sysData) resizeWindow(width, height int) { + d := s.beginResize() + allocations := s.allocate(0, 0, width, height, d) + s.translateAllocationCoords(allocations, width, height) + for _, c := range s.allocations { + c.this.commitResize(c, d) + } + s.endResize(d) +} + +// non-layout controls: allocate() should just return a one-element slice; preferredSize(), commitResize(), and getAuxResizeInfo() should defer to their sysData equivalents +type controlSizing interface { + allocate(x int, y int, width int, height int, d *sysSizeData) []*allocation + preferredSize(d *sysSizeData) (width, height int) + commitResize(c *allocation, d *sysSizeData) + getAuxResizeInfo(d *sysSizeData) +} + +// vertical stack: no concept of neighbor, but not too hard to add a vertical neighbor +// horizontal stack: + var current *allocation + // ... + as := s.controls[i].allocate(...) + if current != nil { + current.neighbor = as[0].self + } + current = as[0] + // append all of as +// grid: + // same as above, except current is set to nil on each new row + // adding a vertical neighbor would require storing an extra list diff --git a/controlsize_sys.go b/controlsize_sys.go new file mode 100644 index 0000000..c520a30 --- /dev/null +++ b/controlsize_sys.go @@ -0,0 +1,82 @@ +//