LabelCheckbox no longer embeds tomo.ContainerBox
This commit is contained in:
parent
697229d183
commit
0960fe013d
@ -5,9 +5,11 @@ import "git.tebibyte.media/tomo/tomo/input"
|
||||
import "git.tebibyte.media/tomo/tomo/event"
|
||||
import "git.tebibyte.media/tomo/objects/layouts"
|
||||
|
||||
var _ tomo.Object = new(LabelCheckbox)
|
||||
|
||||
// LabelCheckbox is a checkbox with a label.
|
||||
type LabelCheckbox struct {
|
||||
tomo.ContainerBox
|
||||
box tomo.ContainerBox
|
||||
checkbox *Checkbox
|
||||
label *Label
|
||||
}
|
||||
@ -15,22 +17,34 @@ type LabelCheckbox struct {
|
||||
// NewLabelCheckbox creates a new labeled checkbox with the specified value and
|
||||
// label text.
|
||||
func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
||||
box := &LabelCheckbox {
|
||||
ContainerBox: tomo.NewContainerBox(),
|
||||
labelCheckbox := &LabelCheckbox {
|
||||
box: tomo.NewContainerBox(),
|
||||
checkbox: NewCheckbox(value),
|
||||
label: NewLabel(text),
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
box.label.SetSelectable(false)
|
||||
box.label.SetFocusable(false)
|
||||
box.Add(box.checkbox)
|
||||
box.Add(box.label)
|
||||
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||
labelCheckbox.box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
||||
labelCheckbox.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
labelCheckbox.label.SetSelectable(false)
|
||||
labelCheckbox.label.SetFocusable(false)
|
||||
labelCheckbox.box.Add(labelCheckbox.checkbox)
|
||||
labelCheckbox.box.Add(labelCheckbox.label)
|
||||
labelCheckbox.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||
|
||||
box.OnButtonDown(box.handleButtonDown)
|
||||
box.OnButtonUp(box.handleButtonUp)
|
||||
return box
|
||||
labelCheckbox.box.OnButtonDown(labelCheckbox.handleButtonDown)
|
||||
labelCheckbox.box.OnButtonUp(labelCheckbox.handleButtonUp)
|
||||
return labelCheckbox
|
||||
}
|
||||
|
||||
// GetBox returns the underlying box.
|
||||
func (this *LabelCheckbox) GetBox () tomo.Box {
|
||||
return this.box
|
||||
}
|
||||
|
||||
// SetFocused sets whether or not this checkbox has keyboard focus. If set to
|
||||
// true, this method will steal focus away from whichever object currently has
|
||||
// focus.
|
||||
func (this *LabelCheckbox) SetFocused (focused bool) {
|
||||
this.checkbox.SetFocused(focused)
|
||||
}
|
||||
|
||||
// Value returns the value of the checkbox.
|
||||
@ -61,7 +75,7 @@ func (this *LabelCheckbox) handleButtonDown (button input.Button) bool {
|
||||
|
||||
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
|
||||
if !isClickingButton(button) { return false }
|
||||
if this.Window().MousePosition().In(this.Bounds()) {
|
||||
if this.box.Window().MousePosition().In(this.box.Bounds()) {
|
||||
this.checkbox.SetFocused(true)
|
||||
this.checkbox.Toggle()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user