Awesome labels

This commit is contained in:
Sasha Koshka 2023-02-11 01:27:28 -05:00
parent f9032a9a95
commit a74f9809af
4 changed files with 39 additions and 26 deletions

View File

@ -246,7 +246,7 @@ func (element *Piano) recalculate () {
element.flatKeys = make([]pianoKey, element.countFlats())
element.sharpKeys = make([]pianoKey, element.countSharps())
inset := element.theme.Inset(theme.PatternSunken)
inset := element.theme.Inset(theme.PatternPinboard)
bounds := inset.Apply(element.Bounds())
dot := bounds.Min
@ -278,7 +278,7 @@ func (element *Piano) draw () {
Focused: element.Focused(),
Disabled: !element.Enabled(),
}
pattern := element.theme.Pattern(theme.PatternSunken, state)
pattern := element.theme.Pattern(theme.PatternPinboard, state)
// inset := element.theme.Inset(theme.PatternSunken)
artist.FillRectangle(element, pattern, element.Bounds())

View File

@ -33,10 +33,9 @@ func run () {
window, _ := tomo.NewWindow(2, 2)
window.SetTitle("Piano")
container := basicElements.NewContainer(basicLayouts.Vertical { true, true })
controlBar := basicElements.NewContainer(basicLayouts.Horizontal { true, false })
// label := basicElements.NewLabel("Play a song!", false)
waveformColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
waveformList := basicElements.NewList (
basicElements.NewListEntry("Sine", func(){ waveform = 0 }),
basicElements.NewListEntry("Triangle", func(){ waveform = 3 }),
@ -67,6 +66,7 @@ func run () {
adsr.Release = releaseSlider.Value()
})
patchColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
patch := func (w int, a, d time.Duration, s float64, r time.Duration) func () {
return func () {
waveform = w
@ -87,7 +87,7 @@ func run () {
basicElements.NewListEntry ("Bones", patch (
0, 0, 100, 0.0, 0)),
basicElements.NewListEntry ("Staccato", patch (
4, 70, 0, 1.0, 400)),
4, 70, 500, 0, 0)),
basicElements.NewListEntry ("Sustain", patch (
4, 70, 200, 0.8, 500)),
basicElements.NewListEntry ("Upright", patch (
@ -98,6 +98,8 @@ func run () {
2, 0, 40, 0.0, 0)),
basicElements.NewListEntry ("Racer", patch (
3, 70, 0, 0.7, 400)),
basicElements.NewListEntry ("Reverse", patch (
2, 3000, 60, 0, 0)),
)
patchList.Collapse(0, 32)
patchScrollBox := basicElements.NewScrollContainer(false, true)
@ -105,24 +107,38 @@ func run () {
piano := fun.NewPiano(2, 5)
piano.OnPress(playNote)
piano.OnRelease(stopNote)
piano.Focus()
// honestly, if you were doing something like this for real, i'd
// encourage you to build a custom layout because this is a bit cursed.
// i need to add more layouts...
window.Adopt(container)
// controlBar.Adopt(label, true)
controlBar.Adopt(patchScrollBox, true)
controlBar.Adopt(patchColumn, true)
patchColumn.Adopt(basicElements.NewLabel("Presets", false), false)
patchColumn.Adopt(patchScrollBox, true)
patchScrollBox.Adopt(patchList)
controlBar.Adopt(waveformList, true)
controlBar.Adopt(basicElements.NewSpacer(true), false)
controlBar.Adopt(waveformColumn, false)
waveformColumn.Adopt(basicElements.NewLabel("Waveform", false), false)
waveformColumn.Adopt(waveformList, true)
controlBar.Adopt(basicElements.NewSpacer(true), false)
adsrColumn.Adopt(basicElements.NewLabel("ADSR", false), false)
adsrGroup.Adopt(attackSlider, false)
adsrGroup.Adopt(decaySlider, false)
adsrGroup.Adopt(sustainSlider, false)
adsrGroup.Adopt(releaseSlider, false)
adsrColumn.Adopt(adsrGroup, true)
controlBar.Adopt(adsrColumn, false)
container.Adopt(controlBar, true)
container.Adopt(piano, false)
piano.Focus()
window.OnClose(tomo.Stop)
window.Show()
}

View File

@ -95,7 +95,11 @@ func (Default) Pattern (
}
}
case PatternPinboard:
return texturedSunkenPattern
if state.Focused {
return focusedTexturedSunkenPattern
} else {
return texturedSunkenPattern
}
case PatternButton:
if state.Disabled {
return disabledButtonPattern

View File

@ -19,13 +19,9 @@ var sunkenPattern = artist.NewMultiBordered (
},
},
artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })
var focusedSunkenPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke {
Weight: 1,
Pattern: accentPattern,
},
artist.Stroke { Weight: 1, Pattern: accentPattern },
artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })
var texturedSunkenPattern = artist.NewMultiBordered (
@ -37,21 +33,18 @@ var texturedSunkenPattern = artist.NewMultiBordered (
artist.NewUniform(hex(0x97a09cFF)),
},
},
// artist.Stroke { Pattern: artist.Striped {
// First: artist.Stroke {
// Weight: 2,
// Pattern: artist.NewUniform(hex(0x97a09cFF)),
// },
// Second: artist.Stroke {
// Weight: 1,
// Pattern: artist.NewUniform(hex(0x6e8079FF)),
// },
// }})
artist.Stroke { Pattern: artist.Noisy {
Low: artist.NewUniform(hex(0x97a09cFF)),
High: artist.NewUniform(hex(0x6e8079FF)),
}})
var focusedTexturedSunkenPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { Weight: 1, Pattern: accentPattern },
artist.Stroke { Pattern: artist.Noisy {
Low: artist.NewUniform(hex(0x97a09cFF)),
High: artist.NewUniform(hex(0x6e8079FF)),
}})
var raisedPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern },