Removed error returns from Control.preferredSize() since errors are not going to be returned anymore.
This commit is contained in:
parent
ab11900d43
commit
ce571bad52
|
@ -69,10 +69,9 @@ func (b *Button) setRect(x int, y int, width int, height int, winheight int) err
|
||||||
return b.sysData.setRect(x, y, width, height, winheight)
|
return b.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) preferredSize() (width int, height int, err error) {
|
func (b *Button) preferredSize() (width int, height int) {
|
||||||
b.lock.Lock()
|
b.lock.Lock()
|
||||||
defer b.lock.Unlock()
|
defer b.lock.Unlock()
|
||||||
|
|
||||||
width, height = b.sysData.preferredSize()
|
return b.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,9 @@ func (c *Checkbox) setRect(x int, y int, width int, height int, winheight int) e
|
||||||
return c.sysData.setRect(x, y, width, height, winheight)
|
return c.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) preferredSize() (width int, height int, err error) {
|
func (c *Checkbox) preferredSize() (width int, height int) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
width, height = c.sysData.preferredSize()
|
return c.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,10 +154,9 @@ func (c *Combobox) setRect(x int, y int, width int, height int, winheight int) e
|
||||||
return c.sysData.setRect(x, y, width, height, winheight)
|
return c.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Combobox) preferredSize() (width int, height int, err error) {
|
func (c *Combobox) preferredSize() (width int, height int) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
width, height = c.sysData.preferredSize()
|
return c.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ import (
|
||||||
type Control interface {
|
type Control interface {
|
||||||
make(window *sysData) error
|
make(window *sysData) error
|
||||||
setRect(x int, y int, width int, height int, winheight int) error
|
setRect(x int, y int, width int, height int, winheight int) error
|
||||||
preferredSize() (width int, height int, err error)
|
preferredSize() (width int, height int)
|
||||||
}
|
}
|
||||||
|
|
14
grid.go
14
grid.go
|
@ -132,10 +132,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, winheight int) error
|
||||||
// 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, err := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error getting preferred size of control (%d,%d) in Grid.setRect(): %v", row, col, err)
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
@ -180,7 +177,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, winheight int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, err error) {
|
func (g *Grid) preferredSize() (width int, height int) {
|
||||||
g.lock.Lock()
|
g.lock.Lock()
|
||||||
defer g.lock.Unlock()
|
defer g.lock.Unlock()
|
||||||
|
|
||||||
|
@ -201,10 +198,7 @@ func (g *Grid) preferredSize() (width int, height int, err error) {
|
||||||
// 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, err := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
if err != nil {
|
|
||||||
return 0, 0, fmt.Errorf("error getting preferred size of control (%d,%d) in Grid.setRect(): %v", row, col, err)
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
@ -218,5 +212,5 @@ func (g *Grid) preferredSize() (width int, height int, err error) {
|
||||||
for _, h := range g.rowheights {
|
for _, h := range g.rowheights {
|
||||||
height += h
|
height += h
|
||||||
}
|
}
|
||||||
return width, height, nil
|
return width, height
|
||||||
}
|
}
|
||||||
|
|
5
label.go
5
label.go
|
@ -63,10 +63,9 @@ func (l *Label) setRect(x int, y int, width int, height int, winheight int) erro
|
||||||
return l.sysData.setRect(x, y, width, height, winheight)
|
return l.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) preferredSize() (width int, height int, err error) {
|
func (l *Label) preferredSize() (width int, height int) {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
defer l.lock.Unlock()
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
width, height = l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,9 @@ func (l *LineEdit) setRect(x int, y int, width int, height int, winheight int) e
|
||||||
return l.sysData.setRect(x, y, width, height, winheight)
|
return l.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LineEdit) preferredSize() (width int, height int, err error) {
|
func (l *LineEdit) preferredSize() (width int, height int) {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
defer l.lock.Unlock()
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
width, height = l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,10 +139,9 @@ func (l *Listbox) setRect(x int, y int, width int, height int, winheight int) er
|
||||||
return l.sysData.setRect(x, y, width, height, winheight)
|
return l.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listbox) preferredSize() (width int, height int, err error) {
|
func (l *Listbox) preferredSize() (width int, height int) {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
defer l.lock.Unlock()
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
width, height = l.sysData.preferredSize()
|
return l.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,9 @@ func (p *ProgressBar) setRect(x int, y int, width int, height int, winheight int
|
||||||
return p.sysData.setRect(x, y, width, height, winheight)
|
return p.sysData.setRect(x, y, width, height, winheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) preferredSize() (width int, height int, err error) {
|
func (p *ProgressBar) preferredSize() (width int, height int) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
||||||
width, height = p.sysData.preferredSize()
|
return p.sysData.preferredSize()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
14
stack.go
14
stack.go
|
@ -91,10 +91,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, winheight int) erro
|
||||||
nStretchy++
|
nStretchy++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w, h, err := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error getting preferred size of control %d in Stack.setRect(): %v", i, err)
|
|
||||||
}
|
|
||||||
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
|
||||||
|
@ -136,7 +133,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, winheight int) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, err error) {
|
func (s *Stack) preferredSize() (width int, height int) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
@ -151,13 +148,10 @@ func (s *Stack) preferredSize() (width int, height int, err error) {
|
||||||
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, nil
|
return 0, 0
|
||||||
}
|
}
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
w, h, err := c.preferredSize()
|
w, h := c.preferredSize()
|
||||||
if err != nil {
|
|
||||||
return 0, 0, fmt.Errorf("error getting preferred size of control %d in Stack.preferredSize(): %v", i, err)
|
|
||||||
}
|
|
||||||
if s.stretchy[i] {
|
if s.stretchy[i] {
|
||||||
nStretchy++
|
nStretchy++
|
||||||
maxswid = max(maxswid, w)
|
maxswid = max(maxswid, w)
|
||||||
|
|
Loading…
Reference in New Issue