From 0960fe013d3c0c899d01e4334f6f0075f4db45b1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 24 Aug 2024 19:50:29 -0400 Subject: [PATCH] LabelCheckbox no longer embeds tomo.ContainerBox --- labelcheckbox.go | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/labelcheckbox.go b/labelcheckbox.go index e1f1bee..6c0ff31 100644 --- a/labelcheckbox.go +++ b/labelcheckbox.go @@ -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(), - checkbox: NewCheckbox(value), - label: NewLabel(text), + 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() }