diff --git a/button.go b/button.go index f29d869..325a556 100644 --- a/button.go +++ b/button.go @@ -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) } -func (b *Button) preferredSize() (width int, height int, err error) { +func (b *Button) preferredSize() (width int, height int) { b.lock.Lock() defer b.lock.Unlock() - width, height = b.sysData.preferredSize() - return + return b.sysData.preferredSize() } diff --git a/checkbox.go b/checkbox.go index 5dfd3d1..2b2a71a 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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) } -func (c *Checkbox) preferredSize() (width int, height int, err error) { +func (c *Checkbox) preferredSize() (width int, height int) { c.lock.Lock() defer c.lock.Unlock() - width, height = c.sysData.preferredSize() - return + return c.sysData.preferredSize() } diff --git a/combobox.go b/combobox.go index d42b353..85384be 100644 --- a/combobox.go +++ b/combobox.go @@ -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) } -func (c *Combobox) preferredSize() (width int, height int, err error) { +func (c *Combobox) preferredSize() (width int, height int) { c.lock.Lock() defer c.lock.Unlock() - width, height = c.sysData.preferredSize() - return + return c.sysData.preferredSize() } diff --git a/control.go b/control.go index 3f54afe..2513399 100644 --- a/control.go +++ b/control.go @@ -9,5 +9,5 @@ import ( type Control interface { make(window *sysData) 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) } diff --git a/grid.go b/grid.go index d960e92..fde6399 100644 --- a/grid.go +++ b/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 for row, xcol := range g.controls { for col, c := range xcol { - w, h, err := c.preferredSize() - if err != nil { - return fmt.Errorf("error getting preferred size of control (%d,%d) in Grid.setRect(): %v", row, col, err) - } + w, h := c.preferredSize() g.widths[row][col] = w g.heights[row][col] = 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 -func (g *Grid) preferredSize() (width int, height int, err error) { +func (g *Grid) preferredSize() (width int, height int) { g.lock.Lock() 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 for row, xcol := range g.controls { for col, c := range xcol { - w, h, err := 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) - } + w, h := c.preferredSize() g.widths[row][col] = w g.heights[row][col] = 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 { height += h } - return width, height, nil + return width, height } diff --git a/label.go b/label.go index 88e79af..be19949 100644 --- a/label.go +++ b/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) } -func (l *Label) preferredSize() (width int, height int, err error) { +func (l *Label) preferredSize() (width int, height int) { l.lock.Lock() defer l.lock.Unlock() - width, height = l.sysData.preferredSize() - return + return l.sysData.preferredSize() } diff --git a/lineedit.go b/lineedit.go index 037c858..98617a5 100644 --- a/lineedit.go +++ b/lineedit.go @@ -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) } -func (l *LineEdit) preferredSize() (width int, height int, err error) { +func (l *LineEdit) preferredSize() (width int, height int) { l.lock.Lock() defer l.lock.Unlock() - width, height = l.sysData.preferredSize() - return + return l.sysData.preferredSize() } diff --git a/listbox.go b/listbox.go index 8bd54b1..6d5decc 100644 --- a/listbox.go +++ b/listbox.go @@ -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) } -func (l *Listbox) preferredSize() (width int, height int, err error) { +func (l *Listbox) preferredSize() (width int, height int) { l.lock.Lock() defer l.lock.Unlock() - width, height = l.sysData.preferredSize() - return + return l.sysData.preferredSize() } diff --git a/progressbar.go b/progressbar.go index 4d41b28..4d80c94 100644 --- a/progressbar.go +++ b/progressbar.go @@ -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) } -func (p *ProgressBar) preferredSize() (width int, height int, err error) { +func (p *ProgressBar) preferredSize() (width int, height int) { p.lock.Lock() defer p.lock.Unlock() - width, height = p.sysData.preferredSize() - return + return p.sysData.preferredSize() } diff --git a/stack.go b/stack.go index cfaf510..cb65bb5 100644 --- a/stack.go +++ b/stack.go @@ -91,10 +91,7 @@ func (s *Stack) setRect(x int, y int, width int, height int, winheight int) erro nStretchy++ continue } - w, h, err := c.preferredSize() - if err != nil { - return fmt.Errorf("error getting preferred size of control %d in Stack.setRect(): %v", i, err) - } + w, h := c.preferredSize() if s.orientation == horizontal { // all controls have same height s.width[i] = w 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). -func (s *Stack) preferredSize() (width int, height int, err error) { +func (s *Stack) preferredSize() (width int, height int) { s.lock.Lock() defer s.lock.Unlock() @@ -151,13 +148,10 @@ func (s *Stack) preferredSize() (width int, height int, err error) { var maxswid, maxsht int if len(s.controls) == 0 { // no controls, so return emptiness - return 0, 0, nil + return 0, 0 } for i, c := range s.controls { - w, h, err := c.preferredSize() - if err != nil { - return 0, 0, fmt.Errorf("error getting preferred size of control %d in Stack.preferredSize(): %v", i, err) - } + w, h := c.preferredSize() if s.stretchy[i] { nStretchy++ maxswid = max(maxswid, w)