From a74f9809afbb9a48c3c22185772e8c453b90b272 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 11 Feb 2023 01:27:28 -0500 Subject: [PATCH] Awesome labels --- elements/fun/piano.go | 4 ++-- examples/piano/main.go | 32 ++++++++++++++++++++++++-------- theme/default.go | 6 +++++- theme/defaultpatterns.go | 23 ++++++++--------------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/elements/fun/piano.go b/elements/fun/piano.go index f099c32..0ff4561 100644 --- a/elements/fun/piano.go +++ b/elements/fun/piano.go @@ -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()) diff --git a/examples/piano/main.go b/examples/piano/main.go index dd41fdd..4412e76 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -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() } diff --git a/theme/default.go b/theme/default.go index d820d8b..107cffd 100644 --- a/theme/default.go +++ b/theme/default.go @@ -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 diff --git a/theme/defaultpatterns.go b/theme/defaultpatterns.go index c4cb724..9dca6db 100644 --- a/theme/defaultpatterns.go +++ b/theme/defaultpatterns.go @@ -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 },