Added a Select() method to List
This commit is contained in:
parent
5e448edb21
commit
dce0321e9b
@ -330,6 +330,14 @@ func (element *List) Replace (index int, entry ListEntry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select selects a specific item in the list. If the index is out of bounds,
|
||||||
|
// no items will be selecected.
|
||||||
|
func (element *List) Select (index int) {
|
||||||
|
if element.selectEntry(index) {
|
||||||
|
element.redo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (element *List) selectUnderMouse (x, y int) (updated bool) {
|
func (element *List) selectUnderMouse (x, y int) (updated bool) {
|
||||||
inset := element.theme.Inset(theme.PatternSunken)
|
inset := element.theme.Inset(theme.PatternSunken)
|
||||||
bounds := inset.Apply(element.Bounds())
|
bounds := inset.Apply(element.Bounds())
|
||||||
|
@ -36,17 +36,27 @@ func run () {
|
|||||||
|
|
||||||
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
|
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
|
||||||
label := basicElements.NewLabel("Play a song!", false)
|
label := basicElements.NewLabel("Play a song!", false)
|
||||||
waveformButton := basicElements.NewButton("Sine")
|
|
||||||
waveformButton.OnClick (func () {
|
waveformList := basicElements.NewList (
|
||||||
waveform = (waveform + 1) % 5
|
basicElements.NewListEntry("Sine", func(){ waveform = 0 }),
|
||||||
switch waveform {
|
basicElements.NewListEntry("Triangle", func(){ waveform = 3 }),
|
||||||
case 0: waveformButton.SetText("Sine")
|
basicElements.NewListEntry("Square", func(){ waveform = 1 }),
|
||||||
case 1: waveformButton.SetText("Square")
|
basicElements.NewListEntry("Saw", func(){ waveform = 2 }),
|
||||||
case 2: waveformButton.SetText("Saw")
|
basicElements.NewListEntry("Supersaw", func(){ waveform = 4 }),
|
||||||
case 3: waveformButton.SetText("Triangle")
|
)
|
||||||
case 4: waveformButton.SetText("Supersaw")
|
waveformList.Select(0)
|
||||||
}
|
|
||||||
})
|
// waveformButton := basicElements.NewButton("Sine")
|
||||||
|
// waveformButton.OnClick (func () {
|
||||||
|
// waveform = (waveform + 1) % 5
|
||||||
|
// switch waveform {
|
||||||
|
// case 0: waveformButton.SetText("Sine")
|
||||||
|
// case 1: waveformButton.SetText("Square")
|
||||||
|
// case 2: waveformButton.SetText("Saw")
|
||||||
|
// case 3: waveformButton.SetText("Triangle")
|
||||||
|
// case 4: waveformButton.SetText("Supersaw")
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
attackSlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Attack, true)
|
attackSlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Attack, true)
|
||||||
decaySlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Decay, true)
|
decaySlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Decay, true)
|
||||||
@ -73,7 +83,7 @@ func run () {
|
|||||||
|
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
controlBar.Adopt(label, true)
|
controlBar.Adopt(label, true)
|
||||||
controlBar.Adopt(waveformButton, 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)
|
||||||
controlBar.Adopt(decaySlider, false)
|
controlBar.Adopt(decaySlider, false)
|
||||||
|
Reference in New Issue
Block a user