Keyboard control for sliders
This commit is contained in:
parent
423e6869c0
commit
f3c1c95a57
@ -238,6 +238,9 @@ func (window *Window) reallocateCanvas () {
|
|||||||
newHeight := window.metrics.height
|
newHeight := window.metrics.height
|
||||||
larger := newWidth > previousWidth || newHeight > previousHeight
|
larger := newWidth > previousWidth || newHeight > previousHeight
|
||||||
smaller := newWidth < previousWidth / 2 || newHeight < previousHeight / 2
|
smaller := newWidth < previousWidth / 2 || newHeight < previousHeight / 2
|
||||||
|
|
||||||
|
allocStep := 128
|
||||||
|
|
||||||
if larger || smaller {
|
if larger || smaller {
|
||||||
if window.xCanvas != nil {
|
if window.xCanvas != nil {
|
||||||
window.xCanvas.Destroy()
|
window.xCanvas.Destroy()
|
||||||
@ -246,8 +249,8 @@ func (window *Window) reallocateCanvas () {
|
|||||||
window.backend.connection,
|
window.backend.connection,
|
||||||
image.Rect (
|
image.Rect (
|
||||||
0, 0,
|
0, 0,
|
||||||
(newWidth / 64) * 64 + 64,
|
(newWidth / allocStep + 1) * allocStep,
|
||||||
(newHeight / 64) * 64 + 64))
|
(newHeight / allocStep + 1) * allocStep))
|
||||||
window.xCanvas.CreatePixmap()
|
window.xCanvas.CreatePixmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,16 +294,23 @@ func (window *Window) childDrawCallback (region canvas.Canvas) {
|
|||||||
func (window *Window) paste (canvas canvas.Canvas) (updatedRegion image.Rectangle) {
|
func (window *Window) paste (canvas canvas.Canvas) (updatedRegion image.Rectangle) {
|
||||||
data, stride := canvas.Buffer()
|
data, stride := canvas.Buffer()
|
||||||
bounds := canvas.Bounds().Intersect(window.xCanvas.Bounds())
|
bounds := canvas.Bounds().Intersect(window.xCanvas.Bounds())
|
||||||
|
|
||||||
|
dstStride := window.xCanvas.Stride
|
||||||
|
dstData := window.xCanvas.Pix
|
||||||
|
|
||||||
// debug.PrintStack()
|
// debug.PrintStack()
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
|
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
||||||
rgba := data[x + y * stride]
|
srcYComponent := y * stride
|
||||||
index := x * 4 + y * window.xCanvas.Stride
|
dstYComponent := y * dstStride
|
||||||
window.xCanvas.Pix[index + 0] = rgba.B
|
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
|
||||||
window.xCanvas.Pix[index + 1] = rgba.G
|
rgba := data[srcYComponent + x]
|
||||||
window.xCanvas.Pix[index + 2] = rgba.R
|
index := dstYComponent + x * 4
|
||||||
window.xCanvas.Pix[index + 3] = rgba.A
|
dstData[index + 0] = rgba.B
|
||||||
}}
|
dstData[index + 1] = rgba.G
|
||||||
|
dstData[index + 2] = rgba.R
|
||||||
|
dstData[index + 3] = rgba.A
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return bounds
|
return bounds
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,24 @@ func (element *Slider) HandleMouseMove (x, y int) {
|
|||||||
func (element *Slider) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
|
func (element *Slider) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
|
||||||
|
|
||||||
func (element *Slider) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
func (element *Slider) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
||||||
// TODO: handle left and right arrows
|
switch key {
|
||||||
|
case input.KeyUp:
|
||||||
|
element.changeValue(0.1)
|
||||||
|
case input.KeyDown:
|
||||||
|
element.changeValue(-0.1)
|
||||||
|
case input.KeyRight:
|
||||||
|
if element.vertical {
|
||||||
|
element.changeValue(-0.1)
|
||||||
|
} else {
|
||||||
|
element.changeValue(0.1)
|
||||||
|
}
|
||||||
|
case input.KeyLeft:
|
||||||
|
if element.vertical {
|
||||||
|
element.changeValue(0.1)
|
||||||
|
} else {
|
||||||
|
element.changeValue(-0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Slider) HandleKeyUp (key input.Key, modifiers input.Modifiers) { }
|
func (element *Slider) HandleKeyUp (key input.Key, modifiers input.Modifiers) { }
|
||||||
@ -135,6 +152,20 @@ func (element *Slider) SetConfig (new config.Config) {
|
|||||||
element.redo()
|
element.redo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *Slider) changeValue (delta float64) {
|
||||||
|
element.value += delta
|
||||||
|
if element.value < 0 {
|
||||||
|
element.value = 0
|
||||||
|
}
|
||||||
|
if element.value > 1 {
|
||||||
|
element.value = 1
|
||||||
|
}
|
||||||
|
if element.onRelease != nil {
|
||||||
|
element.onRelease()
|
||||||
|
}
|
||||||
|
element.redo()
|
||||||
|
}
|
||||||
|
|
||||||
func (element *Slider) valueFor (x, y int) (value float64) {
|
func (element *Slider) valueFor (x, y int) (value float64) {
|
||||||
if element.vertical {
|
if element.vertical {
|
||||||
value =
|
value =
|
||||||
|
Reference in New Issue
Block a user