Add OnEnter to Swatch and ColorPicker
This commit is contained in:
parent
b9f980e7fd
commit
d0ee6c432c
@ -49,11 +49,17 @@ func (this *LabelSwatch) RGBA () (r, g, b, a uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnValueChange specifies a function to be called when the swatch's color
|
// OnValueChange specifies a function to be called when the swatch's color
|
||||||
// changes.
|
// is changed by the user.
|
||||||
func (this *LabelSwatch) OnValueChange (callback func ()) event.Cookie {
|
func (this *LabelSwatch) OnValueChange (callback func ()) event.Cookie {
|
||||||
return this.swatch.OnValueChange(callback)
|
return this.swatch.OnValueChange(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnEnter specifies a function to be called when the user selects "OK" in the
|
||||||
|
// color picker.
|
||||||
|
func (this *LabelSwatch) OnEnter (callback func ()) event.Cookie {
|
||||||
|
return this.swatch.OnEnter(callback)
|
||||||
|
}
|
||||||
|
|
||||||
func (this *LabelSwatch) handleMouseUp (button input.Button) {
|
func (this *LabelSwatch) handleMouseUp (button input.Button) {
|
||||||
if button != input.ButtonLeft { return }
|
if button != input.ButtonLeft { return }
|
||||||
if this.MousePosition().In(this.Bounds()) {
|
if this.MousePosition().In(this.Bounds()) {
|
||||||
|
26
swatch.go
26
swatch.go
@ -17,6 +17,7 @@ type Swatch struct {
|
|||||||
label string
|
label string
|
||||||
on struct {
|
on struct {
|
||||||
valueChange event.FuncBroadcaster
|
valueChange event.FuncBroadcaster
|
||||||
|
enter event.FuncBroadcaster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,15 +50,22 @@ func (this *Swatch) Value () color.Color {
|
|||||||
|
|
||||||
// RGBA satisfies the color.Color interface
|
// RGBA satisfies the color.Color interface
|
||||||
func (this *Swatch) RGBA () (r, g, b, a uint32) {
|
func (this *Swatch) RGBA () (r, g, b, a uint32) {
|
||||||
|
if this.value == nil { return }
|
||||||
return this.value.RGBA()
|
return this.value.RGBA()
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnValueChange specifies a function to be called when the swatch's color
|
// OnValueChange specifies a function to be called when the swatch's color
|
||||||
// changes.
|
// is changed by the user.
|
||||||
func (this *Swatch) OnValueChange (callback func ()) event.Cookie {
|
func (this *Swatch) OnValueChange (callback func ()) event.Cookie {
|
||||||
return this.on.valueChange.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnEnter specifies a function to be called when the user selects "OK" in the
|
||||||
|
// color picker.
|
||||||
|
func (this *Swatch) OnEnter (callback func ()) event.Cookie {
|
||||||
|
return this.on.enter.Connect(callback)
|
||||||
|
}
|
||||||
|
|
||||||
// Choose creates a modal that allows the user to edit the color of the swatch.
|
// Choose creates a modal that allows the user to edit the color of the swatch.
|
||||||
func (this *Swatch) Choose () {
|
func (this *Swatch) Choose () {
|
||||||
if this.editing { return }
|
if this.editing { return }
|
||||||
@ -65,7 +73,7 @@ func (this *Swatch) Choose () {
|
|||||||
var err error
|
var err error
|
||||||
var window tomo.Window
|
var window tomo.Window
|
||||||
if parent := this.Window(); parent != nil {
|
if parent := this.Window(); parent != nil {
|
||||||
window, err = parent.NewModal(image.Rectangle { })
|
window, err = parent.NewChild(image.Rectangle { })
|
||||||
} else {
|
} else {
|
||||||
window, err = tomo.NewWindow(image.Rectangle { })
|
window, err = tomo.NewWindow(image.Rectangle { })
|
||||||
}
|
}
|
||||||
@ -79,22 +87,26 @@ func (this *Swatch) Choose () {
|
|||||||
window.SetTitle(this.label)
|
window.SetTitle(this.label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
committed := false
|
||||||
|
|
||||||
colorPicker := NewColorPicker(this.Value())
|
colorPicker := NewColorPicker(this.Value())
|
||||||
colorPicker.OnValueChange(func () {
|
colorPicker.OnValueChange(func () {
|
||||||
this.userSetValue(colorPicker.Value())
|
this.userSetValue(colorPicker.Value())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
hexInput := NewTextInput("TODO")
|
||||||
|
|
||||||
colorMemory := this.value
|
colorMemory := this.value
|
||||||
cancelButton := NewButton("Cancel")
|
cancelButton := NewButton("Cancel")
|
||||||
cancelButton.SetIcon(tomo.IconDialogCancel)
|
cancelButton.SetIcon(tomo.IconDialogCancel)
|
||||||
cancelButton.OnClick(func () {
|
cancelButton.OnClick(func () {
|
||||||
this.userSetValue(colorMemory)
|
|
||||||
window.Close()
|
window.Close()
|
||||||
})
|
})
|
||||||
okButton := NewButton("OK")
|
okButton := NewButton("OK")
|
||||||
okButton.SetFocused(true)
|
okButton.SetFocused(true)
|
||||||
okButton.SetIcon(tomo.IconDialogOkay)
|
okButton.SetIcon(tomo.IconDialogOkay)
|
||||||
okButton.OnClick(func () {
|
okButton.OnClick(func () {
|
||||||
|
committed = true
|
||||||
window.Close()
|
window.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -106,8 +118,16 @@ func (this *Swatch) Choose () {
|
|||||||
window.SetRoot(NewOuterContainer (
|
window.SetRoot(NewOuterContainer (
|
||||||
layouts.Column { true, false },
|
layouts.Column { true, false },
|
||||||
colorPicker,
|
colorPicker,
|
||||||
|
NewInnerContainer(layouts.Row { false, true },
|
||||||
|
NewLabel("Hex"),
|
||||||
|
hexInput),
|
||||||
controlRow))
|
controlRow))
|
||||||
window.OnClose(func () {
|
window.OnClose(func () {
|
||||||
|
if committed {
|
||||||
|
this.on.enter.Broadcast()
|
||||||
|
} else {
|
||||||
|
this.userSetValue(colorMemory)
|
||||||
|
}
|
||||||
this.editing = false
|
this.editing = false
|
||||||
})
|
})
|
||||||
this.editing = true
|
this.editing = true
|
||||||
|
Loading…
Reference in New Issue
Block a user