Changed Orientation to a bool to prevent invalid values outright.
This commit is contained in:
parent
19f9761a81
commit
a174fbebbd
11
stack.go
11
stack.go
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Orientation defines the orientation of controls in a Stack.
|
// Orientation defines the orientation of controls in a Stack.
|
||||||
type Orientation int
|
type Orientation bool
|
||||||
const (
|
const (
|
||||||
Horizontal Orientation = iota
|
Horizontal Orientation = false
|
||||||
Vertical
|
Vertical Orientation = true
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
||||||
|
@ -29,9 +29,6 @@ type Stack struct {
|
||||||
|
|
||||||
// NewStack creates a new Stack with the specified orientation.
|
// NewStack creates a new Stack with the specified orientation.
|
||||||
func NewStack(o Orientation, controls ...Control) *Stack {
|
func NewStack(o Orientation, controls ...Control) *Stack {
|
||||||
if o != Horizontal && o != Vertical {
|
|
||||||
panic(fmt.Sprintf("invalid orientation %d given to NewStack()", o))
|
|
||||||
}
|
|
||||||
return &Stack{
|
return &Stack{
|
||||||
orientation: o,
|
orientation: o,
|
||||||
controls: controls,
|
controls: controls,
|
||||||
|
@ -75,8 +72,6 @@ func (s *Stack) setRect(x int, y int, width int, height int) error {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
dy = height / len(s.controls)
|
dy = height / len(s.controls)
|
||||||
height = dy
|
height = dy
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("invalid orientation %d given to Stack.setRect()", s.orientation))
|
|
||||||
}
|
}
|
||||||
for i, c := range s.controls {
|
for i, c := range s.controls {
|
||||||
err := c.setRect(x, y, width, height)
|
err := c.setRect(x, y, width, height)
|
||||||
|
|
Loading…
Reference in New Issue