Checkbox: SetText and better BoolVar watch for CheckButton
This commit is contained in:
parent
c99e79d9b0
commit
d82ef0b751
|
@ -61,6 +61,14 @@ func (w *CheckButton) Compute(e render.Engine) {
|
||||||
} else {
|
} else {
|
||||||
w.SetBorderStyle(BorderRaised)
|
w.SetBorderStyle(BorderRaised)
|
||||||
}
|
}
|
||||||
|
} else if w.BoolVar != nil {
|
||||||
|
// Checkbutton, always re-assign the border style in case the caller
|
||||||
|
// has flipped the boolean behind our back.
|
||||||
|
if *w.BoolVar {
|
||||||
|
w.SetBorderStyle(BorderSunken)
|
||||||
|
} else {
|
||||||
|
w.SetBorderStyle(BorderRaised)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.Button.Compute(e)
|
w.Button.Compute(e)
|
||||||
}
|
}
|
||||||
|
|
10
checkbox.go
10
checkbox.go
|
@ -1,5 +1,7 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
// Checkbox combines a CheckButton with a widget like a Label.
|
// Checkbox combines a CheckButton with a widget like a Label.
|
||||||
type Checkbox struct {
|
type Checkbox struct {
|
||||||
Frame
|
Frame
|
||||||
|
@ -60,6 +62,14 @@ func (w *Checkbox) Child() Widget {
|
||||||
return w.child
|
return w.child
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetText conveniently sets the button text, for Label children only.
|
||||||
|
func (w *Checkbox) SetText(text string) error {
|
||||||
|
if label, ok := w.child.(*Label); ok {
|
||||||
|
label.Text = text
|
||||||
|
}
|
||||||
|
return errors.New("child is not a Label widget")
|
||||||
|
}
|
||||||
|
|
||||||
// Pass event handlers on to descendents.
|
// Pass event handlers on to descendents.
|
||||||
func (w *Checkbox) Handle(e Event, fn func(EventData) error) {
|
func (w *Checkbox) Handle(e Event, fn func(EventData) error) {
|
||||||
w.button.Handle(e, fn)
|
w.button.Handle(e, fn)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user