LabelSwatch no longer embeds tomo.ContainerBox
This commit is contained in:
parent
6ee2c5669e
commit
f0c334c278
@ -6,33 +6,47 @@ 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(LabelSwatch)
|
||||
|
||||
// LabelSwatch is a swatch with a label.
|
||||
type LabelSwatch struct {
|
||||
tomo.ContainerBox
|
||||
swatch *Swatch
|
||||
label *Label
|
||||
box tomo.ContainerBox
|
||||
swatch *Swatch
|
||||
label *Label
|
||||
}
|
||||
|
||||
// NewLabelSwatch creates a new labeled swatch with the specified color and
|
||||
// label text.
|
||||
func NewLabelSwatch (value color.Color, text string) *LabelSwatch {
|
||||
box := &LabelSwatch {
|
||||
ContainerBox: tomo.NewContainerBox(),
|
||||
swatch: NewSwatch(value),
|
||||
label: NewLabel(text),
|
||||
labelSwatch := &LabelSwatch {
|
||||
box: tomo.NewContainerBox(),
|
||||
swatch: NewSwatch(value),
|
||||
label: NewLabel(text),
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "LabelSwatch"))
|
||||
box.swatch.label = text
|
||||
box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||
box.label.GetBox().(tomo.TextBox).SetSelectable(false)
|
||||
box.label.GetBox().(tomo.TextBox).SetFocusable(false)
|
||||
box.Add(box.swatch)
|
||||
box.Add(box.label)
|
||||
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||
labelSwatch.box.SetRole(tomo.R("objects", "LabelSwatch"))
|
||||
labelSwatch.swatch.label = text
|
||||
labelSwatch.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle)
|
||||
labelSwatch.label.GetBox().(tomo.TextBox).SetSelectable(false)
|
||||
labelSwatch.label.GetBox().(tomo.TextBox).SetFocusable(false)
|
||||
labelSwatch.box.Add(labelSwatch.swatch)
|
||||
labelSwatch.box.Add(labelSwatch.label)
|
||||
labelSwatch.box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||
|
||||
box.OnButtonDown(box.handleButtonDown)
|
||||
box.OnButtonUp(box.handleButtonUp)
|
||||
return box
|
||||
labelSwatch.box.OnButtonDown(labelSwatch.handleButtonDown)
|
||||
labelSwatch.box.OnButtonUp(labelSwatch.handleButtonUp)
|
||||
return labelSwatch
|
||||
}
|
||||
|
||||
// GetBox returns the underlying box.
|
||||
func (this *LabelSwatch) GetBox () tomo.Box {
|
||||
return this.box
|
||||
}
|
||||
|
||||
// SetFocused sets whether or not this swatch has keyboard focus. If set to
|
||||
// true, this method will steal focus away from whichever object currently has
|
||||
// focus.
|
||||
func (this *LabelSwatch) SetFocused (focused bool) {
|
||||
this.swatch.SetFocused(focused)
|
||||
}
|
||||
|
||||
// Value returns the color of the swatch.
|
||||
@ -69,7 +83,7 @@ func (this *LabelSwatch) handleButtonDown (button input.Button) bool {
|
||||
|
||||
func (this *LabelSwatch) handleButtonUp (button input.Button) bool {
|
||||
if !isClickingButton(button) { return true }
|
||||
if this.Window().MousePosition().In(this.Bounds()) {
|
||||
if this.box.Window().MousePosition().In(this.box.Bounds()) {
|
||||
this.swatch.SetFocused(true)
|
||||
this.swatch.Choose()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user