From a253f39d68efa0da62ed076735f783deb0069ff3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 16 Jul 2014 21:30:19 -0400 Subject: Ported over the sizing framework from the old package and implemented it on the GTK+ backend. --- redo/sizing.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 redo/sizing.go (limited to 'redo/sizing.go') diff --git a/redo/sizing.go b/redo/sizing.go new file mode 100644 index 0000000..a3f8c0e --- /dev/null +++ b/redo/sizing.go @@ -0,0 +1,48 @@ +// 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 +} + +// this ensures that all *windows across all platforms contain the necessary functions +// if this fails to compile, we have a problem +var windowSizeEnsure interface { + beginResize() *sizing + endResize(*sizing) + translateAllocationCoords([]*allocation, int, int) +} = &window{} + +type controlSizing interface { + allocate(x int, y int, width int, height int, d *sizing) []*allocation + preferredSize(*sizing) (int, int) + commitResize(*allocation, *sizing) + getAuxResizeInfo(*sizing) +} + +func (w *window) doresize(width, height int) { + if w.child == nil { // no children; nothing to do + return + } + d := w.beginResize() + allocations := w.child.allocate(0, 0, width, height, d) + w.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) + } + w.endResize(d) +} -- cgit v1.2.3