Added Space() for padding layouts.
This commit is contained in:
parent
dbe983037a
commit
8440c7a078
|
@ -27,7 +27,8 @@ func TestMain(t *testing.T) {
|
||||||
decButton := NewButton("Dec")
|
decButton := NewButton("Dec")
|
||||||
sincdec := NewStack(Horizontal, incButton, decButton)
|
sincdec := NewStack(Horizontal, incButton, decButton)
|
||||||
password := NewPasswordEdit()
|
password := NewPasswordEdit()
|
||||||
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec, password)
|
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec, Space(), password)
|
||||||
|
s0.SetStretchy(8)
|
||||||
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
|
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
|
||||||
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
|
||||||
i := 0
|
i := 0
|
||||||
|
|
8
stack.go
8
stack.go
|
@ -16,6 +16,7 @@ const (
|
||||||
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
// A Stack stacks controls horizontally or vertically within the Stack's parent.
|
||||||
// A horizontal Stack gives all controls the same height and their preferred widths.
|
// A horizontal Stack gives all controls the same height and their preferred widths.
|
||||||
// A vertical Stack gives all controls the same width and their preferred heights.
|
// A vertical Stack gives all controls the same width and their preferred heights.
|
||||||
|
// Any extra space at the end of a Stack is left blank.
|
||||||
// Some controls may be marked as "stretchy": when the Window they are in changes size, stretchy controls resize to take up the remaining space after non-stretchy controls are laid out. If multiple controls are marked stretchy, they are alloted equal distribution of the remaining space.
|
// Some controls may be marked as "stretchy": when the Window they are in changes size, stretchy controls resize to take up the remaining space after non-stretchy controls are laid out. If multiple controls are marked stretchy, they are alloted equal distribution of the remaining space.
|
||||||
type Stack struct {
|
type Stack struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
@ -162,3 +163,10 @@ func (s *Stack) preferredSize() (width int, height int, err error) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Space() returns a null control intended for padding layouts with blank space where otherwise impossible (for instance, at the beginning or in the middle of a Stack).
|
||||||
|
// In order for Space() to work, it must be marked as stretchy in its parent layout; otherwise its size is undefined.
|
||||||
|
func Space() Control {
|
||||||
|
// As above, a stack with no controls draws nothing and reports no errors; its parent will still size it properly.
|
||||||
|
return NewStack(Horizontal)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue