Added the necessary work to make new regular Labels work on the other platforms.
This commit is contained in:
parent
55c636b1e3
commit
39f0c352fb
2
area.go
2
area.go
|
@ -346,7 +346,7 @@ func (a *Area) setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Area) preferredSize() (width int, height int) {
|
func (a *Area) preferredSize() (width int, height int, yoff int) {
|
||||||
return a.sysData.preferredSize()
|
return a.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,6 @@ func (b *Button) setRect(x int, y int, width int, height int, rr *[]resizereques
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) preferredSize() (width int, height int) {
|
func (b *Button) preferredSize() (width int, height int, yoff int) {
|
||||||
return b.sysData.preferredSize()
|
return b.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,6 @@ func (c *Checkbox) setRect(x int, y int, width int, height int, rr *[]resizerequ
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) preferredSize() (width int, height int) {
|
func (c *Checkbox) preferredSize() (width int, height int, yoff int) {
|
||||||
return c.sysData.preferredSize()
|
return c.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,6 @@ func (c *Combobox) setRect(x int, y int, width int, height int, rr *[]resizerequ
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Combobox) preferredSize() (width int, height int) {
|
func (c *Combobox) preferredSize() (width int, height int, yoff int) {
|
||||||
return c.sysData.preferredSize()
|
return c.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@ package ui
|
||||||
type Control interface {
|
type Control interface {
|
||||||
make(window *sysData) error
|
make(window *sysData) error
|
||||||
setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
setRect(x int, y int, width int, height int, rr *[]resizerequest)
|
||||||
preferredSize() (width int, height int)
|
preferredSize() (width int, height int, yoff int)
|
||||||
}
|
}
|
||||||
|
|
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 [][]int // caches to avoid reallocating each time
|
widths, heights, yoff [][]int // caches to avoid reallocating each time
|
||||||
rowheights, colwidths []int
|
rowheights, colwidths []int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +42,14 @@ 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++
|
||||||
|
@ -60,6 +62,7 @@ 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),
|
||||||
}
|
}
|
||||||
|
@ -142,11 +145,12 @@ 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 := c.preferredSize()
|
w, h, yoff := 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
|
||||||
|
@ -174,7 +178,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, w, h, rr)
|
c.setRect(x, y + g.yoff[row][col], w, h - g.yoff[row][col], rr)
|
||||||
x += g.colwidths[col]
|
x += g.colwidths[col]
|
||||||
}
|
}
|
||||||
x = startx
|
x = startx
|
||||||
|
@ -184,7 +188,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) {
|
func (g *Grid) preferredSize() (width int, height int, yoff 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
|
||||||
|
@ -202,7 +206,8 @@ func (g *Grid) preferredSize() (width int, height 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 {
|
||||||
w, h := c.preferredSize()
|
// ignore yoff for preferred size calculations
|
||||||
|
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)
|
||||||
|
@ -216,5 +221,7 @@ func (g *Grid) preferredSize() (width int, height 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
|
||||||
}
|
}
|
||||||
|
|
2
label.go
2
label.go
|
@ -84,6 +84,6 @@ func (l *Label) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) preferredSize() (width int, height int) {
|
func (l *Label) preferredSize() (width int, height int, yoff int) {
|
||||||
return l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,6 @@ func (l *LineEdit) setRect(x int, y int, width int, height int, rr *[]resizerequ
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LineEdit) preferredSize() (width int, height int) {
|
func (l *LineEdit) preferredSize() (width int, height int, yoff int) {
|
||||||
return l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,6 @@ func (l *Listbox) setRect(x int, y int, width int, height int, rr *[]resizereque
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listbox) preferredSize() (width int, height int) {
|
func (l *Listbox) preferredSize() (width int, height int, yoff int) {
|
||||||
return l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,13 @@ package ui
|
||||||
// There is a warning about height-for-width controls, but in my tests this isn't an issue.
|
// There is a warning about height-for-width controls, but in my tests this isn't an issue.
|
||||||
// For Areas, we manually save the Area size and use that, just to be safe.
|
// For Areas, we manually save the Area size and use that, just to be safe.
|
||||||
|
|
||||||
func (s *sysData) preferredSize() (width int, height int) {
|
// We don't need to worry about y-offset because label alignment is "vertically center", which GtkLabel does for us.
|
||||||
|
|
||||||
|
func (s *sysData) preferredSize() (width int, height int, yoff int) {
|
||||||
if s.ctype == c_area {
|
if s.ctype == c_area {
|
||||||
return s.areawidth, s.areaheight
|
return s.areawidth, s.areaheight, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, width, height = gtk_widget_get_preferred_size(s.widget)
|
_, _, width, height = gtk_widget_get_preferred_size(s.widget)
|
||||||
return width, height
|
return width, height, 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,6 @@ func (p *ProgressBar) setRect(x int, y int, width int, height int, rr *[]resizer
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) preferredSize() (width int, height int) {
|
func (p *ProgressBar) preferredSize() (width int, height int, yoff int) {
|
||||||
return p.sysData.preferredSize()
|
return p.sysData.preferredSize()
|
||||||
}
|
}
|
||||||
|
|
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 []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 {
|
func newStack(o orientation, controls ...Control) *Stack {
|
||||||
|
@ -35,6 +35,7 @@ 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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +93,8 @@ func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest
|
||||||
nStretchy++
|
nStretchy++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w, h := c.preferredSize()
|
w, h, yoff := 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
|
||||||
|
@ -120,7 +122,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.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 {
|
if s.orientation == horizontal {
|
||||||
x += s.width[i]
|
x += s.width[i]
|
||||||
} else {
|
} 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).
|
// 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 {
|
max := func(a int, b int) int {
|
||||||
if a > b {
|
if a > b {
|
||||||
return a
|
return a
|
||||||
|
@ -143,10 +145,11 @@ func (s *Stack) preferredSize() (width int, height 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
|
return 0, 0, 0
|
||||||
}
|
}
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
w, h := c.preferredSize()
|
// ignore yoff for preferred size calculations
|
||||||
|
w, h, _ := c.preferredSize()
|
||||||
if s.stretchy[i] {
|
if s.stretchy[i] {
|
||||||
nStretchy++
|
nStretchy++
|
||||||
maxswid = max(maxswid, w)
|
maxswid = max(maxswid, w)
|
||||||
|
@ -169,6 +172,9 @@ func (s *Stack) preferredSize() (width int, height int) {
|
||||||
} else {
|
} else {
|
||||||
height += nStretchy * maxsht
|
height += nStretchy * maxsht
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// yoff is always zero for stacks
|
||||||
|
yoff = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ var _xSysData interface {
|
||||||
selectedTexts() []string
|
selectedTexts() []string
|
||||||
setWindowSize(int, int) error
|
setWindowSize(int, int) error
|
||||||
delete(int)
|
delete(int)
|
||||||
preferredSize() (int, int)
|
preferredSize() (int, int, int)
|
||||||
setProgress(int)
|
setProgress(int)
|
||||||
len() int
|
len() int
|
||||||
setAreaSize(int, int)
|
setAreaSize(int, int)
|
||||||
|
|
Loading…
Reference in New Issue