From 2ab920eb2624962bebec4ba5daf3a38b4edd5330 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 3 Jun 2024 21:13:18 -0400 Subject: [PATCH] Store role in Boxes --- button.go | 3 ++- checkbox.go | 3 ++- container.go | 9 ++++++--- heading.go | 3 ++- icon.go | 6 ++++-- label.go | 3 ++- labelcheckbox.go | 3 ++- numberinput.go | 3 ++- scrollbar.go | 7 +++++-- scrollcontainer.go | 3 ++- separator.go | 3 ++- slider.go | 7 +++++-- textinput.go | 3 ++- textview.go | 3 ++- 14 files changed, 40 insertions(+), 19 deletions(-) diff --git a/button.go b/button.go index a82e86d..20b3a2f 100644 --- a/button.go +++ b/button.go @@ -28,7 +28,8 @@ func NewButton (text string) *Button { ContainerBox: tomo.NewContainerBox(), label: NewLabel(text), } - tomo.Apply(box, tomo.R("objects", "Button", "")) + box.SetRole(tomo.R("objects", "Button", "")) + tomo.Apply(box) box.label.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle) box.SetLayout(buttonLayout) box.SetText(text) diff --git a/checkbox.go b/checkbox.go index fed59f6..040ed10 100644 --- a/checkbox.go +++ b/checkbox.go @@ -18,7 +18,8 @@ func NewCheckbox (value bool) *Checkbox { box := &Checkbox { Box: tomo.NewBox(), } - tomo.Apply(box, tomo.R("objects", "Checkbox", "")) + box.SetRole(tomo.R("objects", "Checkbox", "")) + tomo.Apply(box) box.SetValue(false) box.OnMouseUp(box.handleMouseUp) diff --git a/container.go b/container.go index 0b22c04..1724238 100644 --- a/container.go +++ b/container.go @@ -27,7 +27,8 @@ func newContainer (layout tomo.Layout, children ...tomo.Object) *Container { // window, tab pane, etc. func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container { this := newContainer(layout, children...) - tomo.Apply(this, tomo.R("objects", "Container", "outer")) + this.SetRole(tomo.R("objects", "Container", "outer")) + tomo.Apply(this) return this } @@ -35,14 +36,16 @@ func NewOuterContainer (layout tomo.Layout, children ...tomo.Object) *Container // around it. It is meant to be used as a root container for a ScrollContainer. func NewSunkenContainer (layout tomo.Layout, children ...tomo.Object) *Container { this := newContainer(layout, children...) - tomo.Apply(this, tomo.R("objects", "Container", "sunken")) + this.SetRole(tomo.R("objects", "Container", "sunken")) + tomo.Apply(this) return this } // NewInnerContainer creates a new container that has no padding around it. func NewInnerContainer (layout tomo.Layout, children ...tomo.Object) *Container { this := newContainer(layout, children...) - tomo.Apply(this, tomo.R("objects", "Container", "inner")) + this.SetRole(tomo.R("objects", "Container", "inner")) + tomo.Apply(this) return this } diff --git a/heading.go b/heading.go index 421296d..d9dfbe1 100644 --- a/heading.go +++ b/heading.go @@ -15,7 +15,8 @@ func NewHeading (level int, text string) *Heading { if level < 0 { level = 0 } if level > 2 { level = 2 } this := &Heading { TextBox: tomo.NewTextBox() } - tomo.Apply(this, tomo.R("objects", "Heading", fmt.Sprint(level))) + this.SetRole(tomo.R("objects", "Heading", fmt.Sprint(level))) + tomo.Apply(this) this.SetText(text) return this } diff --git a/icon.go b/icon.go index bbc057b..74bc45a 100644 --- a/icon.go +++ b/icon.go @@ -15,7 +15,8 @@ func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon { this := &Icon { Box: tomo.NewBox(), } - tomo.Apply(this, tomo.R("objects", "Icon", size.String())) + this.SetRole(tomo.R("objects", "Icon", size.String())) + tomo.Apply(this) this.SetTexture(id.Texture(size)) return this } @@ -25,7 +26,8 @@ func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon { this := &Icon { Box: tomo.NewBox(), } - tomo.Apply(this, tomo.R("objects", "Icon", size.String())) + this.SetRole(tomo.R("objects", "Icon", size.String())) + tomo.Apply(this) this.SetTexture(tomo.MimeIcon(mime, size)) return this } diff --git a/label.go b/label.go index 5428dc6..fd2ff52 100644 --- a/label.go +++ b/label.go @@ -10,7 +10,8 @@ type Label struct { // NewLabel creates a new text label. func NewLabel (text string) *Label { this := &Label { TextBox: tomo.NewTextBox() } - tomo.Apply(this, tomo.R("objects", "Label", "")) + this.SetRole(tomo.R("objects", "Label", "")) + tomo.Apply(this) this.SetText(text) return this } diff --git a/labelcheckbox.go b/labelcheckbox.go index dc21536..a15bc64 100644 --- a/labelcheckbox.go +++ b/labelcheckbox.go @@ -20,7 +20,8 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox { checkbox: NewCheckbox(value), label: NewLabel(text), } - tomo.Apply(box, tomo.R("objects", "LabelCheckbox", "")) + box.SetRole(tomo.R("objects", "LabelCheckbox", "")) + tomo.Apply(box) box.label.SetAlign(tomo.AlignStart, tomo.AlignMiddle) box.Add(box.checkbox) box.Add(box.label) diff --git a/numberinput.go b/numberinput.go index a2c3830..34fc709 100644 --- a/numberinput.go +++ b/numberinput.go @@ -28,7 +28,8 @@ func NewNumberInput (value float64) *NumberInput { increment: NewButton(""), decrement: NewButton(""), } - tomo.Apply(box, tomo.R("objects", "NumberInput", "")) + box.SetRole(tomo.R("objects", "NumberInput", "")) + tomo.Apply(box) box.Add(box.input) box.Add(box.decrement) box.Add(box.increment) diff --git a/scrollbar.go b/scrollbar.go index 3f2b707..cbbf95b 100644 --- a/scrollbar.go +++ b/scrollbar.go @@ -45,8 +45,11 @@ func newScrollbar (orient string) *Scrollbar { this.OnMouseUp(this.handleMouseUp) this.OnMouseMove(this.handleMouseMove) this.OnScroll(this.handleScroll) - tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient)) - tomo.Apply(this, tomo.R("objects", "Slider", orient)) + + this.handle.SetRole(tomo.R("objects", "SliderHandle", orient)) + tomo.Apply(this.handle) + this.SetRole(tomo.R("objects", "Slider", orient)) + tomo.Apply(this) return this } diff --git a/scrollcontainer.go b/scrollcontainer.go index efd96ec..e91d350 100644 --- a/scrollcontainer.go +++ b/scrollcontainer.go @@ -60,7 +60,8 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer { } this.CaptureScroll(true) this.OnScroll(this.handleScroll) - tomo.Apply(this, tomo.R("objects", "ScrollContainer", sides.String())) + this.SetRole(tomo.R("objects", "ScrollContainer", sides.String())) + tomo.Apply(this) this.SetLayout(this.layout) return this } diff --git a/separator.go b/separator.go index b9a3292..b2a5143 100644 --- a/separator.go +++ b/separator.go @@ -12,6 +12,7 @@ func NewSeparator () *Separator { this := &Separator { Box: tomo.NewBox(), } - tomo.Apply(this, tomo.R("objects", "Separator", "")) + this.SetRole(tomo.R("objects", "Separator", "")) + tomo.Apply(this) return this } diff --git a/slider.go b/slider.go index 4d6fa5d..1865f4f 100644 --- a/slider.go +++ b/slider.go @@ -51,8 +51,11 @@ func newSlider (orient string, value float64) *Slider { this.OnMouseUp(this.handleMouseUp) this.OnMouseMove(this.handleMouseMove) this.OnScroll(this.handleScroll) - tomo.Apply(this.handle, tomo.R("objects", "SliderHandle", orient)) - tomo.Apply(this, tomo.R("objects", "Slider", orient)) + + this.handle.SetRole(tomo.R("objects", "SliderHandle", orient)) + tomo.Apply(this.handle) + this.SetRole(tomo.R("objects", "Slider", orient)) + tomo.Apply(this) return this } diff --git a/textinput.go b/textinput.go index e014bb3..6f4f620 100644 --- a/textinput.go +++ b/textinput.go @@ -19,7 +19,8 @@ type TextInput struct { // NewTextInput creates a new text input containing the specified text. func NewTextInput (text string) *TextInput { this := &TextInput { TextBox: tomo.NewTextBox() } - tomo.Apply(this, tomo.R("objects", "TextInput", "")) + this.SetRole(tomo.R("objects", "TextInput", "")) + tomo.Apply(this) this.SetAlign(tomo.AlignStart, tomo.AlignMiddle) this.SetText(text) this.SetFocusable(true) diff --git a/textview.go b/textview.go index 73fe9e8..fca4b92 100644 --- a/textview.go +++ b/textview.go @@ -11,7 +11,8 @@ type TextView struct { // NewTextView creates a new text view. func NewTextView (text string) *TextView { this := &TextView { TextBox: tomo.NewTextBox() } - tomo.Apply(this, tomo.R("objects", "TextView", "")) + this.SetRole(tomo.R("objects", "TextView", "")) + tomo.Apply(this) this.SetFocusable(true) this.SetSelectable(true) this.SetText(text)