From 0c4e09868013267f410edd2e9265f7c2ae1dea95 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 24 Aug 2024 19:28:48 -0400 Subject: [PATCH] HSVAColorPicker no longer embeds tomo.ContainerBox --- colorpicker.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/colorpicker.go b/colorpicker.go index e8dcd60..fc452ee 100644 --- a/colorpicker.go +++ b/colorpicker.go @@ -8,10 +8,12 @@ import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/internal" +var _ tomo.Object = new(HSVAColorPicker) + // HSVAColorPicker allows the user to pick a color by controlling its HSVA // parameters. type HSVAColorPicker struct { - tomo.ContainerBox + box tomo.ContainerBox value internal.HSVA pickerMap *hsvaColorPickerMap @@ -26,15 +28,15 @@ type HSVAColorPicker struct { // NewHSVAColorPicker creates a new color picker with the specified color. func NewHSVAColorPicker (value color.Color) *HSVAColorPicker { picker := &HSVAColorPicker { - ContainerBox: tomo.NewContainerBox(), + box: tomo.NewContainerBox(), } - picker.SetRole(tomo.R("objects", "ColorPicker")) - picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false })) + picker.box.SetRole(tomo.R("objects", "ColorPicker")) + picker.box.SetAttr(tomo.ALayout(layouts.Row { true, false, false })) picker.pickerMap = newHsvaColorPickerMap(picker) - picker.Add(picker.pickerMap) + picker.box.Add(picker.pickerMap) picker.hueSlider = NewVerticalSlider(0.0) - picker.Add(picker.hueSlider) + picker.box.Add(picker.hueSlider) picker.hueSlider.OnValueChange(func () { picker.value.H = picker.hueSlider.Value() picker.on.valueChange.Broadcast() @@ -42,7 +44,7 @@ func NewHSVAColorPicker (value color.Color) *HSVAColorPicker { }) picker.alphaSlider = NewVerticalSlider(0.0) - picker.Add(picker.alphaSlider) + picker.box.Add(picker.alphaSlider) picker.alphaSlider.OnValueChange(func () { picker.value.A = uint16(picker.alphaSlider.Value() * 0xFFFF) picker.on.valueChange.Broadcast() @@ -54,6 +56,18 @@ func NewHSVAColorPicker (value color.Color) *HSVAColorPicker { return picker } +// GetBox returns the underlying box. +func (this *HSVAColorPicker) GetBox () tomo.Box { + return this.box +} + +// SetFocused sets whether or not this color picker has keyboard focus. If set +// to true, this method will steal focus away from whichever object currently +// has focus. +func (this *HSVAColorPicker) SetFocused (focused bool) { + this.box.SetFocused(focused) +} + // Value returns the color of the picker. func (this *HSVAColorPicker) Value () color.Color { return this.value