From 9c3274c02ea368b1e5cb9b42c8236ce8b921e63e Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 22 Jun 2025 21:58:00 +0300 Subject: [PATCH] drafting buttons --- tracker/gioui/buttons.go | 44 +++++++++----------- tracker/gioui/instrument_editor.go | 66 +++++++++++++++--------------- tracker/gioui/menu.go | 2 +- tracker/gioui/note_editor.go | 44 ++++++++++---------- tracker/gioui/oscilloscope.go | 8 ++-- tracker/gioui/songpanel.go | 36 ++++++++-------- tracker/gioui/unit_editor.go | 22 +++++----- 7 files changed, 109 insertions(+), 113 deletions(-) diff --git a/tracker/gioui/buttons.go b/tracker/gioui/buttons.go index c364b1d..64e214d 100644 --- a/tracker/gioui/buttons.go +++ b/tracker/gioui/buttons.go @@ -27,10 +27,6 @@ type ( history []widget.Press requestClicks int - } - - ClickableTip struct { - Clickable component.TipArea } @@ -59,7 +55,7 @@ type ( Style ButtonStyle Text string Tip string - *ClickableTip + *Clickable } ActionButton struct { @@ -80,7 +76,7 @@ type ( Style IconButtonStyle Icon *widget.Icon Tip string - *ClickableTip + *Clickable } ActionIconButton struct { @@ -98,17 +94,17 @@ type ( } ) -func Btn(th *Theme, st *ButtonStyle, b *ClickableTip, txt string, tip string) Button { +func Btn(th *Theme, st *ButtonStyle, b *Clickable, txt string, tip string) Button { return Button{ - Theme: th, - Style: *st, - ClickableTip: b, - Text: txt, - Tip: tip, + Theme: th, + Style: *st, + Clickable: b, + Text: txt, + Tip: tip, } } -func ActionBtn(act tracker.Action, th *Theme, b *ClickableTip, txt string, tip string) ActionButton { +func ActionBtn(act tracker.Action, th *Theme, b *Clickable, txt string, tip string) ActionButton { return ActionButton{ act: act, DisabledStyle: th.Button.Disabled, @@ -116,7 +112,7 @@ func ActionBtn(act tracker.Action, th *Theme, b *ClickableTip, txt string, tip s } } -func ToggleBtn(b tracker.Bool, th *Theme, c *ClickableTip, text string, tip string) ToggleButton { +func ToggleBtn(b tracker.Bool, th *Theme, c *Clickable, text string, tip string) ToggleButton { return ToggleButton{ b: b, DisabledStyle: th.Button.Disabled, @@ -125,17 +121,17 @@ func ToggleBtn(b tracker.Bool, th *Theme, c *ClickableTip, text string, tip stri } } -func IconBtn(th *Theme, st *IconButtonStyle, b *ClickableTip, icon []byte, tip string) IconButton { +func IconBtn(th *Theme, st *IconButtonStyle, b *Clickable, icon []byte, tip string) IconButton { return IconButton{ - Theme: th, - Style: *st, - ClickableTip: b, - Icon: th.Icon(icon), - Tip: tip, + Theme: th, + Style: *st, + Clickable: b, + Icon: th.Icon(icon), + Tip: tip, } } -func ActionIconBtn(act tracker.Action, th *Theme, b *ClickableTip, icon []byte, tip string) ActionIconButton { +func ActionIconBtn(act tracker.Action, th *Theme, b *Clickable, icon []byte, tip string) ActionIconButton { return ActionIconButton{ act: act, DisabledStyle: th.IconButton.Disabled, @@ -143,7 +139,7 @@ func ActionIconBtn(act tracker.Action, th *Theme, b *ClickableTip, icon []byte, } } -func ToggleIconBtn(b tracker.Bool, th *Theme, c *ClickableTip, offIcon, onIcon []byte, offTip, onTip string) ToggleIconButton { +func ToggleIconBtn(b tracker.Bool, th *Theme, c *Clickable, offIcon, onIcon []byte, offTip, onTip string) ToggleIconButton { return ToggleIconButton{ b: b, DisabledStyle: th.IconButton.Disabled, @@ -155,7 +151,7 @@ func ToggleIconBtn(b tracker.Bool, th *Theme, c *ClickableTip, offIcon, onIcon [ func (b *Button) Layout(gtx C) D { if b.Tip != "" { - return b.ClickableTip.TipArea.Layout(gtx, Tooltip(b.Theme, b.Tip), b.actualLayout) + return b.Clickable.TipArea.Layout(gtx, Tooltip(b.Theme, b.Tip), b.actualLayout) } return b.actualLayout(gtx) } @@ -218,7 +214,7 @@ func (b *ToggleButton) Layout(gtx C) D { func (i *IconButton) Layout(gtx C) D { if i.Tip != "" { - return i.ClickableTip.TipArea.Layout(gtx, Tooltip(i.Theme, i.Tip), i.actualLayout) + return i.Clickable.TipArea.Layout(gtx, Tooltip(i.Theme, i.Tip), i.actualLayout) } return i.actualLayout(gtx) } diff --git a/tracker/gioui/instrument_editor.go b/tracker/gioui/instrument_editor.go index afc7943..f6a1e49 100644 --- a/tracker/gioui/instrument_editor.go +++ b/tracker/gioui/instrument_editor.go @@ -23,19 +23,19 @@ import ( type ( InstrumentEditor struct { - newInstrumentBtn *ClickableTip - enlargeBtn *ClickableTip - deleteInstrumentBtn *ClickableTip - linkInstrTrackBtn *ClickableTip - splitInstrumentBtn *ClickableTip - copyInstrumentBtn *ClickableTip - saveInstrumentBtn *ClickableTip - loadInstrumentBtn *ClickableTip - addUnitBtn *ClickableTip - presetMenuBtn *ClickableTip - commentExpandBtn *ClickableTip - soloBtn *ClickableTip - muteBtn *ClickableTip + newInstrumentBtn *Clickable + enlargeBtn *Clickable + deleteInstrumentBtn *Clickable + linkInstrTrackBtn *Clickable + splitInstrumentBtn *Clickable + copyInstrumentBtn *Clickable + saveInstrumentBtn *Clickable + loadInstrumentBtn *Clickable + addUnitBtn *Clickable + presetMenuBtn *Clickable + commentExpandBtn *Clickable + soloBtn *Clickable + muteBtn *Clickable commentEditor *Editor commentString tracker.String nameEditor *Editor @@ -68,19 +68,19 @@ type ( func NewInstrumentEditor(model *tracker.Model) *InstrumentEditor { ret := &InstrumentEditor{ - newInstrumentBtn: new(ClickableTip), - enlargeBtn: new(ClickableTip), - deleteInstrumentBtn: new(ClickableTip), - linkInstrTrackBtn: new(ClickableTip), - splitInstrumentBtn: new(ClickableTip), - copyInstrumentBtn: new(ClickableTip), - saveInstrumentBtn: new(ClickableTip), - loadInstrumentBtn: new(ClickableTip), - commentExpandBtn: new(ClickableTip), - presetMenuBtn: new(ClickableTip), - soloBtn: new(ClickableTip), - muteBtn: new(ClickableTip), - addUnitBtn: new(ClickableTip), + newInstrumentBtn: new(Clickable), + enlargeBtn: new(Clickable), + deleteInstrumentBtn: new(Clickable), + linkInstrTrackBtn: new(Clickable), + splitInstrumentBtn: new(Clickable), + copyInstrumentBtn: new(Clickable), + saveInstrumentBtn: new(Clickable), + loadInstrumentBtn: new(Clickable), + commentExpandBtn: new(Clickable), + presetMenuBtn: new(Clickable), + soloBtn: new(Clickable), + muteBtn: new(Clickable), + addUnitBtn: new(Clickable), commentEditor: NewEditor(false, false, text.Start), nameEditor: NewEditor(true, true, text.Middle), searchEditor: NewEditor(true, true, text.Start), @@ -133,8 +133,8 @@ func (ie *InstrumentEditor) Focused(gtx C) bool { func (ie *InstrumentEditor) childFocused(gtx C) bool { return ie.unitEditor.sliderList.Focused(gtx) || ie.instrumentDragList.Focused(gtx) || gtx.Source.Focused(ie.commentEditor) || gtx.Source.Focused(ie.nameEditor) || gtx.Source.Focused(ie.searchEditor) || - gtx.Source.Focused(ie.addUnitBtn.Clickable) || gtx.Source.Focused(ie.commentExpandBtn.Clickable) || gtx.Source.Focused(ie.presetMenuBtn.Clickable) || - gtx.Source.Focused(ie.deleteInstrumentBtn.Clickable) || gtx.Source.Focused(ie.copyInstrumentBtn.Clickable) + gtx.Source.Focused(ie.addUnitBtn) || gtx.Source.Focused(ie.commentExpandBtn) || gtx.Source.Focused(ie.presetMenuBtn) || + gtx.Source.Focused(ie.deleteInstrumentBtn) || gtx.Source.Focused(ie.copyInstrumentBtn) } func (ie *InstrumentEditor) Layout(gtx C, t *Tracker) D { @@ -192,14 +192,14 @@ func (ie *InstrumentEditor) layoutInstrumentHeader(gtx C, t *Tracker) D { header := func(gtx C) D { m := PopupMenu(t.Theme, &t.Theme.Menu.Text, &ie.presetMenu) - for ie.copyInstrumentBtn.Clickable.Clicked(gtx) { + for ie.copyInstrumentBtn.Clicked(gtx) { if contents, ok := t.Instruments().List().CopyElements(); ok { gtx.Execute(clipboard.WriteCmd{Type: "application/text", Data: io.NopCloser(bytes.NewReader(contents))}) t.Alerts().Add("Instrument copied to clipboard", tracker.Info) } } - for ie.saveInstrumentBtn.Clickable.Clicked(gtx) { + for ie.saveInstrumentBtn.Clicked(gtx) { writer, err := t.Explorer.CreateFile(t.InstrumentName().Value() + ".yml") if err != nil { continue @@ -207,7 +207,7 @@ func (ie *InstrumentEditor) layoutInstrumentHeader(gtx C, t *Tracker) D { t.SaveInstrument(writer) } - for ie.loadInstrumentBtn.Clickable.Clicked(gtx) { + for ie.loadInstrumentBtn.Clicked(gtx) { reader, err := t.Explorer.ChooseFile(".yml", ".json", ".4ki", ".4kp") if err != nil { continue @@ -253,7 +253,7 @@ func (ie *InstrumentEditor) layoutInstrumentHeader(gtx C, t *Tracker) D { ) } - for ie.presetMenuBtn.Clickable.Clicked(gtx) { + for ie.presetMenuBtn.Clicked(gtx) { ie.presetMenu.Visible = true } @@ -476,7 +476,7 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D { return dims }), layout.Stacked(func(gtx C) D { - for ie.addUnitBtn.Clickable.Clicked(gtx) { + for ie.addUnitBtn.Clicked(gtx) { t.AddUnit(false).Do() } margin := layout.Inset{Right: unit.Dp(20), Bottom: unit.Dp(1)} diff --git a/tracker/gioui/menu.go b/tracker/gioui/menu.go index 2a62b74..4a3f233 100644 --- a/tracker/gioui/menu.go +++ b/tracker/gioui/menu.go @@ -161,7 +161,7 @@ func PopupMenu(th *Theme, s *LabelStyle, menu *Menu) MenuStyle { } } -func (tr *Tracker) layoutMenu(gtx C, title string, ct *ClickableTip, menu *Menu, width unit.Dp, items ...MenuItem) layout.Widget { +func (tr *Tracker) layoutMenu(gtx C, title string, ct *Clickable, menu *Menu, width unit.Dp, items ...MenuItem) layout.Widget { for ct.Clicked(gtx) { menu.Visible = true } diff --git a/tracker/gioui/note_editor.go b/tracker/gioui/note_editor.go index a764efa..d1c223c 100644 --- a/tracker/gioui/note_editor.go +++ b/tracker/gioui/note_editor.go @@ -52,18 +52,18 @@ func init() { type NoteEditor struct { TrackVoices *NumericUpDown - NewTrackBtn *ClickableTip - DeleteTrackBtn *ClickableTip - SplitTrackBtn *ClickableTip + NewTrackBtn *Clickable + DeleteTrackBtn *Clickable + SplitTrackBtn *Clickable - AddSemitoneBtn *ClickableTip - SubtractSemitoneBtn *ClickableTip - AddOctaveBtn *ClickableTip - SubtractOctaveBtn *ClickableTip - NoteOffBtn *ClickableTip - EffectBtn *ClickableTip - UniqueBtn *ClickableTip - TrackMidiInBtn *ClickableTip + AddSemitoneBtn *Clickable + SubtractSemitoneBtn *Clickable + AddOctaveBtn *Clickable + SubtractOctaveBtn *Clickable + NoteOffBtn *Clickable + EffectBtn *Clickable + UniqueBtn *Clickable + TrackMidiInBtn *Clickable scrollTable *ScrollTable eventFilters []event.Filter @@ -77,17 +77,17 @@ type NoteEditor struct { func NewNoteEditor(model *tracker.Model) *NoteEditor { ret := &NoteEditor{ TrackVoices: NewNumericUpDown(), - NewTrackBtn: new(ClickableTip), - DeleteTrackBtn: new(ClickableTip), - SplitTrackBtn: new(ClickableTip), - AddSemitoneBtn: new(ClickableTip), - SubtractSemitoneBtn: new(ClickableTip), - AddOctaveBtn: new(ClickableTip), - SubtractOctaveBtn: new(ClickableTip), - NoteOffBtn: new(ClickableTip), - EffectBtn: new(ClickableTip), - UniqueBtn: new(ClickableTip), - TrackMidiInBtn: new(ClickableTip), + NewTrackBtn: new(Clickable), + DeleteTrackBtn: new(Clickable), + SplitTrackBtn: new(Clickable), + AddSemitoneBtn: new(Clickable), + SubtractSemitoneBtn: new(Clickable), + AddOctaveBtn: new(Clickable), + SubtractOctaveBtn: new(Clickable), + NoteOffBtn: new(Clickable), + EffectBtn: new(Clickable), + UniqueBtn: new(Clickable), + TrackMidiInBtn: new(Clickable), scrollTable: NewScrollTable( model.Notes().Table(), model.Tracks().List(), diff --git a/tracker/gioui/oscilloscope.go b/tracker/gioui/oscilloscope.go index bc90123..568efa0 100644 --- a/tracker/gioui/oscilloscope.go +++ b/tracker/gioui/oscilloscope.go @@ -17,8 +17,8 @@ import ( type ( OscilloscopeState struct { - onceBtn *ClickableTip - wrapBtn *ClickableTip + onceBtn *Clickable + wrapBtn *Clickable lengthInBeatsNumber *NumericUpDown triggerChannelNumber *NumericUpDown xScale int @@ -38,8 +38,8 @@ type ( func NewOscilloscope(model *tracker.Model) *OscilloscopeState { return &OscilloscopeState{ - onceBtn: new(ClickableTip), - wrapBtn: new(ClickableTip), + onceBtn: new(Clickable), + wrapBtn: new(Clickable), lengthInBeatsNumber: NewNumericUpDown(), triggerChannelNumber: NewNumericUpDown(), } diff --git a/tracker/gioui/songpanel.go b/tracker/gioui/songpanel.go index 0129ae0..78a8745 100644 --- a/tracker/gioui/songpanel.go +++ b/tracker/gioui/songpanel.go @@ -22,8 +22,8 @@ type SongPanel struct { LoudnessExpander *Expander PeakExpander *Expander - WeightingTypeBtn *ClickableTip - OversamplingBtn *ClickableTip + WeightingTypeBtn *Clickable + OversamplingBtn *Clickable BPM *NumericUpDown RowsPerPattern *NumericUpDown @@ -48,8 +48,8 @@ func NewSongPanel(model *tracker.Model) *SongPanel { MenuBar: NewMenuBar(model), PlayBar: NewPlayBar(), - WeightingTypeBtn: new(ClickableTip), - OversamplingBtn: new(ClickableTip), + WeightingTypeBtn: new(Clickable), + OversamplingBtn: new(Clickable), SongSettingsExpander: &Expander{Expanded: true}, ScopeExpander: &Expander{}, @@ -296,7 +296,7 @@ func (e *Expander) layoutHeader(gtx C, th *Theme, title string, smallWidget layo } type MenuBar struct { - Clickables []ClickableTip + Clickables []Clickable Menus []Menu fileMenuItems []MenuItem @@ -304,14 +304,14 @@ type MenuBar struct { midiMenuItems []MenuItem panicHint string - PanicBtn *ClickableTip + PanicBtn *Clickable } func NewMenuBar(model *tracker.Model) *MenuBar { ret := &MenuBar{ - Clickables: make([]ClickableTip, 3), + Clickables: make([]Clickable, 3), Menus: make([]Menu, 3), - PanicBtn: new(ClickableTip), + PanicBtn: new(Clickable), panicHint: makeHint("Panic", " (%s)", "PanicToggle"), } ret.fileMenuItems = []MenuItem{ @@ -359,11 +359,11 @@ func (t *MenuBar) Layout(gtx C, tr *Tracker) D { } type PlayBar struct { - RewindBtn *ClickableTip - PlayingBtn *ClickableTip - RecordBtn *ClickableTip - FollowBtn *ClickableTip - LoopBtn *ClickableTip + RewindBtn *Clickable + PlayingBtn *Clickable + RecordBtn *Clickable + FollowBtn *Clickable + LoopBtn *Clickable // Hints rewindHint string playHint, stopHint string @@ -374,11 +374,11 @@ type PlayBar struct { func NewPlayBar() *PlayBar { ret := &PlayBar{ - LoopBtn: new(ClickableTip), - RecordBtn: new(ClickableTip), - FollowBtn: new(ClickableTip), - PlayingBtn: new(ClickableTip), - RewindBtn: new(ClickableTip), + LoopBtn: new(Clickable), + RecordBtn: new(Clickable), + FollowBtn: new(Clickable), + PlayingBtn: new(Clickable), + RewindBtn: new(Clickable), } ret.rewindHint = makeHint("Rewind", "\n(%s)", "PlaySongStartUnfollow") ret.playHint = makeHint("Play", " (%s)", "PlayCurrentPosUnfollow") diff --git a/tracker/gioui/unit_editor.go b/tracker/gioui/unit_editor.go index 5d977ca..71ae7f1 100644 --- a/tracker/gioui/unit_editor.go +++ b/tracker/gioui/unit_editor.go @@ -30,10 +30,10 @@ type UnitEditor struct { sliderList *DragList searchList *DragList Parameters []*ParameterWidget - DeleteUnitBtn *ClickableTip - CopyUnitBtn *ClickableTip - ClearUnitBtn *ClickableTip - DisableUnitBtn *ClickableTip + DeleteUnitBtn *Clickable + CopyUnitBtn *Clickable + ClearUnitBtn *Clickable + DisableUnitBtn *Clickable SelectTypeBtn *Clickable commentEditor *Editor caser cases.Caser @@ -45,10 +45,10 @@ type UnitEditor struct { func NewUnitEditor(m *tracker.Model) *UnitEditor { ret := &UnitEditor{ - DeleteUnitBtn: new(ClickableTip), - ClearUnitBtn: new(ClickableTip), - DisableUnitBtn: new(ClickableTip), - CopyUnitBtn: new(ClickableTip), + DeleteUnitBtn: new(Clickable), + ClearUnitBtn: new(Clickable), + DisableUnitBtn: new(Clickable), + CopyUnitBtn: new(Clickable), SelectTypeBtn: new(Clickable), commentEditor: NewEditor(true, true, text.Start), sliderList: NewDragList(m.Params().List(), layout.Vertical), @@ -127,7 +127,7 @@ func (pe *UnitEditor) layoutSliders(gtx C, t *Tracker) D { } func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D { - for pe.CopyUnitBtn.Clickable.Clicked(gtx) { + for pe.CopyUnitBtn.Clicked(gtx) { if contents, ok := t.Units().List().CopyElements(); ok { gtx.Execute(clipboard.WriteCmd{Type: "application/text", Data: io.NopCloser(bytes.NewReader(contents))}) t.Alerts().Add("Unit copied to clipboard", tracker.Info) @@ -223,9 +223,9 @@ func (pe *UnitEditor) command(e key.Event, t *Tracker) { type ParameterWidget struct { floatWidget widget.Float boolWidget widget.Bool - instrBtn ClickableTip + instrBtn Clickable instrMenu Menu - unitBtn ClickableTip + unitBtn Clickable unitMenu Menu Parameter tracker.Parameter tipArea component.TipArea