Piano example no longer crashes

This commit is contained in:
Sasha Koshka 2023-03-31 01:30:18 -04:00
parent 7b300333cf
commit ab78bc640d

View File

@ -26,6 +26,8 @@ type Piano struct {
config config.Wrapped config config.Wrapped
theme theme.Wrapped theme theme.Wrapped
flatTheme theme.Wrapped
sharpTheme theme.Wrapped
flatKeys []pianoKey flatKeys []pianoKey
sharpKeys []pianoKey sharpKeys []pianoKey
@ -54,6 +56,8 @@ func NewPiano (low, high music.Octave) (element *Piano) {
} }
element.theme.Case = tomo.C("tomo", "piano") element.theme.Case = tomo.C("tomo", "piano")
element.flatTheme.Case = tomo.C("tomo", "piano", "flatKey")
element.sharpTheme.Case = tomo.C("tomo", "piano", "sharpKey")
element.Core, element.core = core.NewCore (element, func () { element.Core, element.core = core.NewCore (element, func () {
element.recalculate() element.recalculate()
element.draw() element.draw()
@ -202,6 +206,8 @@ func (element *Piano) HandleKeyUp (key input.Key, modifiers input.Modifiers) {
func (element *Piano) SetTheme (new tomo.Theme) { func (element *Piano) SetTheme (new tomo.Theme) {
if new == element.theme.Theme { return } if new == element.theme.Theme { return }
element.theme.Theme = new element.theme.Theme = new
element.flatTheme.Theme = new
element.sharpTheme.Theme = new
element.updateMinimumSize() element.updateMinimumSize()
element.recalculate() element.recalculate()
element.redo() element.redo()
@ -313,8 +319,7 @@ func (element *Piano) drawFlat (
state tomo.State, state tomo.State,
) { ) {
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.flatTheme.Pattern(tomo.PatternButton, state)
tomo.PatternButton, state, tomo.C("fun", "piano", "flatKey"))
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} }
@ -324,7 +329,6 @@ func (element *Piano) drawSharp (
state tomo.State, state tomo.State,
) { ) {
state.Pressed = pressed state.Pressed = pressed
pattern := element.theme.Theme.Pattern ( pattern := element.sharpTheme.Pattern(tomo.PatternButton, state)
tomo.PatternButton, state, tomo.C("fun", "piano", "sharpKey"))
pattern.Draw(element.core, bounds) pattern.Draw(element.core, bounds)
} }