Reverted Stack and Grid back to pre-yoff form. This is part of the change in the sizing system.
This commit is contained in:
parent
057f0eaf53
commit
08922103a7
19
grid.go
19
grid.go
|
@ -21,7 +21,7 @@ type Grid struct {
|
||||||
controls [][]Control
|
controls [][]Control
|
||||||
filling [][]bool
|
filling [][]bool
|
||||||
stretchyrow, stretchycol int
|
stretchyrow, stretchycol int
|
||||||
widths, heights, yoff [][]int // caches to avoid reallocating each time
|
widths, heights [][]int // caches to avoid reallocating each time
|
||||||
rowheights, colwidths []int
|
rowheights, colwidths []int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,14 +42,12 @@ func NewGrid(nPerRow int, controls ...Control) *Grid {
|
||||||
cf := make([][]bool, nRows)
|
cf := make([][]bool, nRows)
|
||||||
cw := make([][]int, nRows)
|
cw := make([][]int, nRows)
|
||||||
ch := make([][]int, nRows)
|
ch := make([][]int, nRows)
|
||||||
cyoff := make([][]int, nRows)
|
|
||||||
i := 0
|
i := 0
|
||||||
for row := 0; row < nRows; row++ {
|
for row := 0; row < nRows; row++ {
|
||||||
cc[row] = make([]Control, nPerRow)
|
cc[row] = make([]Control, nPerRow)
|
||||||
cf[row] = make([]bool, nPerRow)
|
cf[row] = make([]bool, nPerRow)
|
||||||
cw[row] = make([]int, nPerRow)
|
cw[row] = make([]int, nPerRow)
|
||||||
ch[row] = make([]int, nPerRow)
|
ch[row] = make([]int, nPerRow)
|
||||||
cyoff[row] = make([]int, nPerRow)
|
|
||||||
for x := 0; x < nPerRow; x++ {
|
for x := 0; x < nPerRow; x++ {
|
||||||
cc[row][x] = controls[i]
|
cc[row][x] = controls[i]
|
||||||
i++
|
i++
|
||||||
|
@ -62,7 +60,6 @@ func NewGrid(nPerRow int, controls ...Control) *Grid {
|
||||||
stretchycol: -1,
|
stretchycol: -1,
|
||||||
widths: cw,
|
widths: cw,
|
||||||
heights: ch,
|
heights: ch,
|
||||||
yoff: cyoff,
|
|
||||||
rowheights: make([]int, nRows),
|
rowheights: make([]int, nRows),
|
||||||
colwidths: make([]int, nPerRow),
|
colwidths: make([]int, nPerRow),
|
||||||
}
|
}
|
||||||
|
@ -145,12 +142,11 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
||||||
// 2) get preferred sizes; compute row/column sizes
|
// 2) get preferred sizes; compute row/column sizes
|
||||||
for row, xcol := range g.controls {
|
for row, xcol := range g.controls {
|
||||||
for col, c := range xcol {
|
for col, c := range xcol {
|
||||||
w, h, yoff := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
g.widths[row][col] = w
|
g.widths[row][col] = w
|
||||||
g.heights[row][col] = h
|
g.heights[row][col] = h
|
||||||
g.rowheights[row] = max(g.rowheights[row], h)
|
g.rowheights[row] = max(g.rowheights[row], h)
|
||||||
g.colwidths[col] = max(g.colwidths[col], w)
|
g.colwidths[col] = max(g.colwidths[col], w)
|
||||||
g.yoff[row][col] = yoff
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3) handle the stretchy control
|
// 3) handle the stretchy control
|
||||||
|
@ -178,7 +174,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
||||||
w = g.colwidths[col]
|
w = g.colwidths[col]
|
||||||
h = g.rowheights[row]
|
h = g.rowheights[row]
|
||||||
}
|
}
|
||||||
c.setRect(x, y + g.yoff[row][col], w, h - g.yoff[row][col], rr)
|
c.setRect(x, y, w, h, rr)
|
||||||
x += g.colwidths[col]
|
x += g.colwidths[col]
|
||||||
}
|
}
|
||||||
x = startx
|
x = startx
|
||||||
|
@ -188,7 +184,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filling and stretchy are ignored for preferred size calculation
|
// filling and stretchy are ignored for preferred size calculation
|
||||||
func (g *Grid) preferredSize() (width int, height int, yoff int) {
|
func (g *Grid) preferredSize() (width int, height int) {
|
||||||
max := func(a int, b int) int {
|
max := func(a int, b int) int {
|
||||||
if a > b {
|
if a > b {
|
||||||
return a
|
return a
|
||||||
|
@ -206,8 +202,7 @@ func (g *Grid) preferredSize() (width int, height int, yoff int) {
|
||||||
// 2) get preferred sizes; compute row/column sizes
|
// 2) get preferred sizes; compute row/column sizes
|
||||||
for row, xcol := range g.controls {
|
for row, xcol := range g.controls {
|
||||||
for col, c := range xcol {
|
for col, c := range xcol {
|
||||||
// ignore yoff for preferred size calculations
|
w, h := c.preferredSize()
|
||||||
w, h, _ := c.preferredSize()
|
|
||||||
g.widths[row][col] = w
|
g.widths[row][col] = w
|
||||||
g.heights[row][col] = h
|
g.heights[row][col] = h
|
||||||
g.rowheights[row] = max(g.rowheights[row], h)
|
g.rowheights[row] = max(g.rowheights[row], h)
|
||||||
|
@ -221,7 +216,5 @@ func (g *Grid) preferredSize() (width int, height int, yoff int) {
|
||||||
for _, h := range g.rowheights {
|
for _, h := range g.rowheights {
|
||||||
height += h
|
height += h
|
||||||
}
|
}
|
||||||
|
return width, height
|
||||||
// yoff is always zero for grids
|
|
||||||
return width, height, 0
|
|
||||||
}
|
}
|
||||||
|
|
18
stack.go
18
stack.go
|
@ -25,7 +25,7 @@ type Stack struct {
|
||||||
orientation orientation
|
orientation orientation
|
||||||
controls []Control
|
controls []Control
|
||||||
stretchy []bool
|
stretchy []bool
|
||||||
width, height, yoff []int // caches to avoid reallocating these each time
|
width, height []int // caches to avoid reallocating these each time
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStack(o orientation, controls ...Control) *Stack {
|
func newStack(o orientation, controls ...Control) *Stack {
|
||||||
|
@ -35,7 +35,6 @@ func newStack(o orientation, controls ...Control) *Stack {
|
||||||
stretchy: make([]bool, len(controls)),
|
stretchy: make([]bool, len(controls)),
|
||||||
width: make([]int, len(controls)),
|
width: make([]int, len(controls)),
|
||||||
height: make([]int, len(controls)),
|
height: make([]int, len(controls)),
|
||||||
yoff: make([]int, len(controls)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +92,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
nStretchy++
|
nStretchy++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w, h, yoff := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
s.yoff[i] = yoff
|
|
||||||
if s.orientation == horizontal { // all controls have same height
|
if s.orientation == horizontal { // all controls have same height
|
||||||
s.width[i] = w
|
s.width[i] = w
|
||||||
s.height[i] = height
|
s.height[i] = height
|
||||||
|
@ -122,7 +120,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
}
|
}
|
||||||
// 3) now actually place controls
|
// 3) now actually place controls
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
c.setRect(x, y + s.yoff[i], s.width[i], s.height[i] - s.yoff[i], rr)
|
c.setRect(x, y, s.width[i], s.height[i], rr)
|
||||||
if s.orientation == horizontal {
|
if s.orientation == horizontal {
|
||||||
x += s.width[i]
|
x += s.width[i]
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,7 +131,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).
|
// 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, yoff int) {
|
func (s *Stack) preferredSize() (width int, height int) {
|
||||||
max := func(a int, b int) int {
|
max := func(a int, b int) int {
|
||||||
if a > b {
|
if a > b {
|
||||||
return a
|
return a
|
||||||
|
@ -145,11 +143,10 @@ func (s *Stack) preferredSize() (width int, height int, yoff int) {
|
||||||
var maxswid, maxsht int
|
var maxswid, maxsht int
|
||||||
|
|
||||||
if len(s.controls) == 0 { // no controls, so return emptiness
|
if len(s.controls) == 0 { // no controls, so return emptiness
|
||||||
return 0, 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
// ignore yoff for preferred size calculations
|
w, h := c.preferredSize()
|
||||||
w, h, _ := c.preferredSize()
|
|
||||||
if s.stretchy[i] {
|
if s.stretchy[i] {
|
||||||
nStretchy++
|
nStretchy++
|
||||||
maxswid = max(maxswid, w)
|
maxswid = max(maxswid, w)
|
||||||
|
@ -172,9 +169,6 @@ func (s *Stack) preferredSize() (width int, height int, yoff int) {
|
||||||
} else {
|
} else {
|
||||||
height += nStretchy * maxsht
|
height += nStretchy * maxsht
|
||||||
}
|
}
|
||||||
|
|
||||||
// yoff is always zero for stacks
|
|
||||||
yoff = 0
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue