Fixed a focus issue with ScrollContainer
This commit is contained in:
parent
981c11bd44
commit
0e3de11203
@ -234,7 +234,9 @@ func (element *ScrollContainer) Focused () (focused bool) {
|
|||||||
|
|
||||||
func (element *ScrollContainer) Focus () {
|
func (element *ScrollContainer) Focus () {
|
||||||
if element.onFocusRequest != nil {
|
if element.onFocusRequest != nil {
|
||||||
element.onFocusRequest()
|
if element.onFocusRequest() {
|
||||||
|
element.focused = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,8 +246,8 @@ func (element *ScrollContainer) HandleFocus (
|
|||||||
accepted bool,
|
accepted bool,
|
||||||
) {
|
) {
|
||||||
if child, ok := element.child.(elements.Focusable); ok {
|
if child, ok := element.child.(elements.Focusable); ok {
|
||||||
element.focused = true
|
element.focused = child.HandleFocus(direction)
|
||||||
return child.HandleFocus(direction)
|
return element.focused
|
||||||
} else {
|
} else {
|
||||||
element.focused = false
|
element.focused = false
|
||||||
return false
|
return false
|
||||||
@ -274,11 +276,9 @@ func (element *ScrollContainer) childDamageCallback (region canvas.Canvas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *ScrollContainer) childFocusRequestCallback () (granted bool) {
|
func (element *ScrollContainer) childFocusRequestCallback () (granted bool) {
|
||||||
child, ok := element.child.(elements.Focusable)
|
if element.onFocusRequest != nil {
|
||||||
if !ok { return false }
|
element.focused = element.onFocusRequest()
|
||||||
if element.onFocusRequest != nil && element.onFocusRequest() {
|
return element.focused
|
||||||
child.HandleFocus(input.KeynavDirectionNeutral)
|
|
||||||
return true
|
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,41 @@ func run () {
|
|||||||
releaseSlider.OnRelease (func () {
|
releaseSlider.OnRelease (func () {
|
||||||
adsr.Release = releaseSlider.Value()
|
adsr.Release = releaseSlider.Value()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
patch := func (w int, a, d time.Duration, s float64, r time.Duration) func () {
|
||||||
|
return func () {
|
||||||
|
waveform = w
|
||||||
|
adsr = ADSR {
|
||||||
|
a * time.Millisecond,
|
||||||
|
d * time.Millisecond,
|
||||||
|
s,
|
||||||
|
r * time.Millisecond,
|
||||||
|
}
|
||||||
|
waveformList.Select(w)
|
||||||
|
attackSlider .SetValue(adsr.Attack)
|
||||||
|
decaySlider .SetValue(adsr.Decay)
|
||||||
|
sustainSlider.SetValue(adsr.Sustain)
|
||||||
|
releaseSlider.SetValue(adsr.Release)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patchList := basicElements.NewList (
|
||||||
|
basicElements.NewListEntry ("Bones", patch (
|
||||||
|
0, 0, 100, 0.0, 0)),
|
||||||
|
basicElements.NewListEntry ("Staccato", patch (
|
||||||
|
4, 70, 0, 1.0, 400)),
|
||||||
|
basicElements.NewListEntry ("Sustain", patch (
|
||||||
|
4, 70, 200, 0.8, 500)),
|
||||||
|
basicElements.NewListEntry ("Upright", patch (
|
||||||
|
1, 0, 500, 0.4, 70)),
|
||||||
|
basicElements.NewListEntry ("Space Pad", patch (
|
||||||
|
4, 1500, 0, 1.0, 3000)),
|
||||||
|
basicElements.NewListEntry ("Popcorn", patch (
|
||||||
|
2, 0, 40, 0.0, 0)),
|
||||||
|
basicElements.NewListEntry ("Racer", patch (
|
||||||
|
3, 70, 0, 0.7, 400)),
|
||||||
|
)
|
||||||
|
patchList.Collapse(0, 32)
|
||||||
|
patchScrollBox := basicElements.NewScrollContainer(false, true)
|
||||||
|
|
||||||
piano := fun.NewPiano(2, 5)
|
piano := fun.NewPiano(2, 5)
|
||||||
piano.OnPress(playNote)
|
piano.OnPress(playNote)
|
||||||
@ -72,6 +107,8 @@ func run () {
|
|||||||
|
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
controlBar.Adopt(label, true)
|
controlBar.Adopt(label, true)
|
||||||
|
controlBar.Adopt(patchScrollBox, false)
|
||||||
|
patchScrollBox.Adopt(patchList)
|
||||||
controlBar.Adopt(waveformList, false)
|
controlBar.Adopt(waveformList, false)
|
||||||
controlBar.Adopt(basicElements.NewSpacer(true), false)
|
controlBar.Adopt(basicElements.NewSpacer(true), false)
|
||||||
controlBar.Adopt(attackSlider, false)
|
controlBar.Adopt(attackSlider, false)
|
||||||
@ -85,6 +122,11 @@ func run () {
|
|||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Patch struct {
|
||||||
|
ADSR
|
||||||
|
Waveform int
|
||||||
|
}
|
||||||
|
|
||||||
func stopNote (note music.Note) {
|
func stopNote (note music.Note) {
|
||||||
if _, is := playing[note]; !is { return }
|
if _, is := playing[note]; !is { return }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user