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/tomo/event"
|
||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
|
var _ tomo.Object = new(LabelCheckbox)
|
||||||
|
|
||||||
// LabelCheckbox is a checkbox with a label.
|
// LabelCheckbox is a checkbox with a label.
|
||||||
type LabelCheckbox struct {
|
type LabelCheckbox struct {
|
||||||
tomo.ContainerBox
|
box tomo.ContainerBox
|
||||||
checkbox *Checkbox
|
checkbox *Checkbox
|
||||||
label *Label
|
label *Label
|
||||||
}
|
}
|
||||||
@ -15,22 +17,34 @@ type LabelCheckbox struct {
|
|||||||
// NewLabelCheckbox creates a new labeled checkbox with the specified value and
|
// NewLabelCheckbox creates a new labeled checkbox with the specified value and
|
||||||
// label text.
|
// label text.
|
||||||
func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
||||||
box := &LabelCheckbox {
|
labelCheckbox := &LabelCheckbox {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
box: tomo.NewContainerBox(),
|
||||||
checkbox: NewCheckbox(value),
|
checkbox: NewCheckbox(value),
|
||||||
label: NewLabel(text),
|
label: NewLabel(text),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
labelCheckbox.box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
||||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
labelCheckbox.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||||
box.label.SetSelectable(false)
|
labelCheckbox.label.SetSelectable(false)
|
||||||
box.label.SetFocusable(false)
|
labelCheckbox.label.SetFocusable(false)
|
||||||
box.Add(box.checkbox)
|
labelCheckbox.box.Add(labelCheckbox.checkbox)
|
||||||
box.Add(box.label)
|
labelCheckbox.box.Add(labelCheckbox.label)
|
||||||
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
labelCheckbox.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||||
|
|
||||||
box.OnButtonDown(box.handleButtonDown)
|
labelCheckbox.box.OnButtonDown(labelCheckbox.handleButtonDown)
|
||||||
box.OnButtonUp(box.handleButtonUp)
|
labelCheckbox.box.OnButtonUp(labelCheckbox.handleButtonUp)
|
||||||
return box
|
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.
|
// 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 {
|
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
|
||||||
if !isClickingButton(button) { return false }
|
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.SetFocused(true)
|
||||||
this.checkbox.Toggle()
|
this.checkbox.Toggle()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user