diff --git a/check_button.go b/check_button.go index 157f60f..afe292a 100644 --- a/check_button.go +++ b/check_button.go @@ -61,6 +61,14 @@ func (w *CheckButton) Compute(e render.Engine) { } else { 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) } diff --git a/checkbox.go b/checkbox.go index 31d2d60..cecbae2 100644 --- a/checkbox.go +++ b/checkbox.go @@ -1,5 +1,7 @@ package ui +import "errors" + // Checkbox combines a CheckButton with a widget like a Label. type Checkbox struct { Frame @@ -60,6 +62,14 @@ func (w *Checkbox) Child() Widget { 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. func (w *Checkbox) Handle(e Event, fn func(EventData) error) { w.button.Handle(e, fn)