From 8b1756e95236202c3baccb4a4c56c40abb12b446 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 29 Jul 2014 23:23:45 -0400 Subject: [PATCH] Re-added Stack. Of course it only works right on GTK+ right now... the other platforms's Control.preferredSize()s aren't implemented yet! --- redo/{mergeback => }/stack.go | 30 +++++++++++++++++++----------- redo/zz_test.go | 9 +++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) rename redo/{mergeback => }/stack.go (92%) diff --git a/redo/mergeback/stack.go b/redo/stack.go similarity index 92% rename from redo/mergeback/stack.go rename to redo/stack.go index 8b2c754..9f37812 100644 --- a/redo/mergeback/stack.go +++ b/redo/stack.go @@ -58,18 +58,26 @@ func (s *Stack) SetStretchy(index int) { s.stretchy[index] = true } -func (s *Stack) make(window *sysData) error { - for i, c := range s.controls { - err := c.make(window) - if err != nil { - return fmt.Errorf("error adding control %d to Stack: %v", i, err) - } +func (s *Stack) setParent(parent *controlParent) { + for _, c := range s.controls { + c.setParent(parent) } s.created = true - return nil } -func (s *Stack) allocate(x int, y int, width int, height int, d *sysSizeData) (allocations []*allocation) { +func (s *Stack) containerShow() { + for _, c := range s.controls { + c.containerShow() + } +} + +func (s *Stack) containerHide() { + for _, c := range s.controls { + c.containerHide() + } +} + +func (s *Stack) allocate(x int, y int, width int, height int, d *sizing) (allocations []*allocation) { var stretchywid, stretchyht int var current *allocation // for neighboring @@ -142,7 +150,7 @@ func (s *Stack) allocate(x int, y int, width int, height int, d *sysSizeData) (a // The preferred size of a Stack is the sum of the preferred sizes of non-stretchy controls + (the number of stretchy controls * the largest preferred size among all stretchy controls). // We don't consider the margins here, but will need to in container if Window.SizeToFit() is ever made a thing. TODO -func (s *Stack) preferredSize(d *sysSizeData) (width int, height int) { +func (s *Stack) preferredSize(d *sizing) (width int, height int) { max := func(a int, b int) int { if a > b { return a @@ -188,11 +196,11 @@ func (s *Stack) preferredSize(d *sysSizeData) (width int, height int) { return } -func (s *Stack) commitResize(c *allocation, d *sysSizeData) { +func (s *Stack) commitResize(c *allocation, d *sizing) { // this is to satisfy Control; nothing to do here } -func (s *Stack) getAuxResizeInfo(d *sysSizeData) { +func (s *Stack) getAuxResizeInfo(d *sizing) { // this is to satisfy Control; nothing to do here } diff --git a/redo/zz_test.go b/redo/zz_test.go index d20eabf..b3d44e7 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -28,6 +28,7 @@ var ddata = []dtype{ type testwin struct { t Tab w Window + s *Stack // TODO make Stack l Label table Table b Button @@ -48,6 +49,14 @@ func (tw *testwin) make(done chan struct{}) { done <- struct{}{} return true }) + stack1 := NewHorizontalStack(NewLabel("Test"), NewTextField()) + stack1.SetStretchy(1) + stack2 := NewHorizontalStack(NewLabel("Test 2"), + NewTable(reflect.TypeOf(struct{A,B,C int}{}))) + stack2.SetStretchy(1) + tw.s = NewVerticalStack(stack1, stack2) + tw.s.SetStretchy(1) + tw.t.Append("Stack", tw.s) tw.l = NewStandaloneLabel("hello") tw.t.Append("Label", tw.l) tw.table = NewTable(reflect.TypeOf(ddata[0]))