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.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

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/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,