Swatch accepts hex input

This commit is contained in:
Sasha Koshka 2024-08-16 15:17:44 -04:00
parent 3d28c8fea1
commit 43ec7a0311
2 changed files with 28 additions and 14 deletions

View File

@ -65,6 +65,7 @@ func (this *HSVAColorPicker) SetValue (value color.Color) {
this.value = internal.HSVAModel.Convert(value).(internal.HSVA) this.value = internal.HSVAModel.Convert(value).(internal.HSVA)
this.hueSlider.SetValue(this.value.H) this.hueSlider.SetValue(this.value.H)
this.alphaSlider.SetValue(float64(this.value.A) / 0xFFFF) this.alphaSlider.SetValue(float64(this.value.A) / 0xFFFF)
this.pickerMap.Invalidate()
} }
// OnValueChange specifies a function to be called when the user changes the // OnValueChange specifies a function to be called when the user changes the

View File

@ -8,6 +8,7 @@ import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
import "git.tebibyte.media/tomo/objects/layouts" 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. // Swatch displays a color, allowing the user to edit it by clicking on it.
type Swatch struct { type Swatch struct {
@ -92,25 +93,37 @@ func (this *Swatch) Choose () {
committed := false committed := false
colorPicker := NewHSVAColorPicker(this.Value()) colorPicker := NewHSVAColorPicker(this.Value())
colorPicker.OnValueChange(func () {
this.userSetValue(colorPicker.Value())
})
hexInput := NewTextInput("TODO")
colorMemory := this.value colorMemory := this.value
hexInput := NewTextInput("TODO")
hexInput.SetFocused(true)
cancelButton := NewButton("Cancel") cancelButton := NewButton("Cancel")
cancelButton.SetIcon(tomo.IconDialogCancel) 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 () { cancelButton.OnClick(func () {
window.Close() window.Close()
}) })
okButton := NewButton("OK") okButton.OnClick(commit)
okButton.SetFocused(true)
okButton.SetIcon(tomo.IconDialogOkay)
okButton.OnClick(func () {
committed = true
window.Close()
})
controlRow := NewInnerContainer ( controlRow := NewInnerContainer (
layouts.ContractHorizontal, layouts.ContractHorizontal,