From 43ec7a0311eb181c71f304bc7df60eaf4edeb006 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 16 Aug 2024 15:17:44 -0400 Subject: [PATCH] Swatch accepts hex input --- colorpicker.go | 1 + swatch.go | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/colorpicker.go b/colorpicker.go index 0f5d3ed..e8dcd60 100644 --- a/colorpicker.go +++ b/colorpicker.go @@ -65,6 +65,7 @@ func (this *HSVAColorPicker) SetValue (value color.Color) { this.value = internal.HSVAModel.Convert(value).(internal.HSVA) this.hueSlider.SetValue(this.value.H) this.alphaSlider.SetValue(float64(this.value.A) / 0xFFFF) + this.pickerMap.Invalidate() } // OnValueChange specifies a function to be called when the user changes the diff --git a/swatch.go b/swatch.go index 3cde31e..4fc5093 100644 --- a/swatch.go +++ b/swatch.go @@ -8,6 +8,7 @@ import "git.tebibyte.media/tomo/tomo/input" import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/objects/layouts" +import "git.tebibyte.media/tomo/objects/internal" // Swatch displays a color, allowing the user to edit it by clicking on it. type Swatch struct { @@ -91,26 +92,38 @@ func (this *Swatch) Choose () { committed := false - colorPicker := NewHSVAColorPicker(this.Value()) - colorPicker.OnValueChange(func () { - this.userSetValue(colorPicker.Value()) - }) - - hexInput := NewTextInput("TODO") - + colorPicker := NewHSVAColorPicker(this.Value()) colorMemory := this.value + hexInput := NewTextInput("TODO") + hexInput.SetFocused(true) cancelButton := NewButton("Cancel") cancelButton.SetIcon(tomo.IconDialogCancel) + okButton := NewButton("OK") + okButton.SetIcon(tomo.IconDialogOkay) + + updateHexInput := func () { + nrgba := color.NRGBAModel.Convert(colorPicker.Value()).(color.NRGBA) + hexInput.SetValue(internal.FormatNRGBA(nrgba)) + } + updateHexInput() + commit := func () { + committed = true + window.Close() + } + colorPicker.OnValueChange(func () { + this.userSetValue(colorPicker.Value()) + updateHexInput() + }) + hexInput.OnConfirm(commit) + hexInput.OnValueChange(func () { + nrgba := internal.ParseNRGBA(hexInput.Value()) + this.userSetValue(nrgba) + colorPicker.SetValue(nrgba) + }) cancelButton.OnClick(func () { window.Close() }) - okButton := NewButton("OK") - okButton.SetFocused(true) - okButton.SetIcon(tomo.IconDialogOkay) - okButton.OnClick(func () { - committed = true - window.Close() - }) + okButton.OnClick(commit) controlRow := NewInnerContainer ( layouts.ContractHorizontal,