diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-25 11:58:13 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-25 11:58:13 -0400 |
| commit | 39f0c352fbeeb4119aedeee1a5974f4d411339c8 (patch) | |
| tree | 4d9362dd1313c5b3dd5cd1e417e8a332b057cf83 /stack.go | |
| parent | 55c636b1e3823ec73a9b10d78a03528a54e63bb1 (diff) | |
Added the necessary work to make new regular Labels work on the other platforms.
Diffstat (limited to 'stack.go')
| -rw-r--r-- | stack.go | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -25,7 +25,7 @@ type Stack struct { orientation orientation controls []Control stretchy []bool - width, height []int // caches to avoid reallocating these each time + width, height, yoff []int // caches to avoid reallocating these each time } func newStack(o orientation, controls ...Control) *Stack { @@ -35,6 +35,7 @@ func newStack(o orientation, controls ...Control) *Stack { stretchy: make([]bool, len(controls)), width: make([]int, len(controls)), height: make([]int, len(controls)), + yoff: make([]int, len(controls)), } } @@ -92,7 +93,8 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest nStretchy++ continue } - w, h := c.preferredSize() + w, h, yoff := c.preferredSize() + s.yoff[i] = yoff if s.orientation == horizontal { // all controls have same height s.width[i] = w s.height[i] = height @@ -120,7 +122,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest } // 3) now actually place controls for i, c := range s.controls { - c.setRect(x, y, s.width[i], s.height[i], rr) + c.setRect(x, y + s.yoff[i], s.width[i], s.height[i] - s.yoff[i], rr) if s.orientation == horizontal { x += s.width[i] } else { @@ -131,7 +133,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest } // 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). -func (s *Stack) preferredSize() (width int, height int) { +func (s *Stack) preferredSize() (width int, height int, yoff int) { max := func(a int, b int) int { if a > b { return a @@ -143,10 +145,11 @@ func (s *Stack) preferredSize() (width int, height int) { var maxswid, maxsht int if len(s.controls) == 0 { // no controls, so return emptiness - return 0, 0 + return 0, 0, 0 } for i, c := range s.controls { - w, h := c.preferredSize() + // ignore yoff for preferred size calculations + w, h, _ := c.preferredSize() if s.stretchy[i] { nStretchy++ maxswid = max(maxswid, w) @@ -169,6 +172,9 @@ func (s *Stack) preferredSize() (width int, height int) { } else { height += nStretchy * maxsht } + + // yoff is always zero for stacks + yoff = 0 return } |
