From 243396c3010c462b7a1440218779449057ad2476 Mon Sep 17 00:00:00 2001 From: qm210 Date: Fri, 22 Nov 2024 15:22:58 +0100 Subject: [PATCH] fix: from review --- tracker/gioui/buttons.go | 5 +---- tracker/gioui/layout.go | 16 ++++++++++++++++ tracker/gioui/note_editor.go | 5 +++-- tracker/gioui/numericupdown.go | 10 +--------- tracker/gioui/tracker.go | 12 ++++++++---- 5 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 tracker/gioui/layout.go diff --git a/tracker/gioui/buttons.go b/tracker/gioui/buttons.go index 11d337d..f4024d3 100644 --- a/tracker/gioui/buttons.go +++ b/tracker/gioui/buttons.go @@ -19,6 +19,7 @@ import ( "gioui.org/widget" "gioui.org/widget/material" "gioui.org/x/component" + "github.com/vsariola/sointu/tracker" ) @@ -298,7 +299,6 @@ type ButtonStyle struct { Inset layout.Inset Button *Clickable shaper *text.Shaper - Hidden bool } type ButtonLayoutStyle struct { @@ -363,9 +363,6 @@ func (b ButtonStyle) Layout(gtx layout.Context) layout.Dimensions { CornerRadius: b.CornerRadius, Button: b.Button, }.Layout(gtx, func(gtx layout.Context) layout.Dimensions { - if b.Hidden { - return layout.Dimensions{} - } return b.Inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions { colMacro := op.Record(gtx.Ops) paint.ColorOp{Color: b.Color}.Add(gtx.Ops) diff --git a/tracker/gioui/layout.go b/tracker/gioui/layout.go new file mode 100644 index 0000000..a736b3a --- /dev/null +++ b/tracker/gioui/layout.go @@ -0,0 +1,16 @@ +package gioui + +import "gioui.org/layout" + +// general helpers for layout that do not belong to any specific widget + +func EmptyWidget() layout.Spacer { + return layout.Spacer{} +} + +func OnlyIf(condition bool, widget layout.Widget) layout.Widget { + if condition { + return widget + } + return EmptyWidget().Layout +} diff --git a/tracker/gioui/note_editor.go b/tracker/gioui/note_editor.go index 764b544..7238ada 100644 --- a/tracker/gioui/note_editor.go +++ b/tracker/gioui/note_editor.go @@ -158,7 +158,8 @@ func (te *NoteEditor) layoutButtons(gtx C, t *Tracker) D { deleteTrackBtnStyle := ActionIcon(gtx, t.Theme, te.DeleteTrackBtn, icons.ActionDelete, te.deleteTrackHint) splitTrackBtnStyle := ActionIcon(gtx, t.Theme, te.SplitTrackBtn, icons.CommunicationCallSplit, te.splitTrackHint) newTrackBtnStyle := ActionIcon(gtx, t.Theme, te.NewTrackBtn, icons.ContentAdd, te.addTrackHint) - voiceUpDown := NumericUpDownPadded(t.Theme, te.TrackVoices, "Number of voices for this track", 1) + voiceUpDown := NumericUpDown(t.Theme, te.TrackVoices, "Number of voices for this track") + voiceUpDown.Padding = unit.Dp(1) effectBtnStyle := ToggleButton(gtx, t.Theme, te.EffectBtn, "Hex") uniqueBtnStyle := ToggleIcon(gtx, t.Theme, te.UniqueBtn, icons.ToggleStarBorder, icons.ToggleStar, te.uniqueOffTip, te.uniqueOnTip) midiInBtnStyle := ToggleButton(gtx, t.Theme, te.TrackMidiInBtn, "MIDI") @@ -175,7 +176,7 @@ func (te *NoteEditor) layoutButtons(gtx C, t *Tracker) D { layout.Rigid(voiceUpDown.Layout), layout.Rigid(splitTrackBtnStyle.Layout), layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }), - layout.Rigid(midiInBtnStyle.Layout), + layout.Rigid(OnlyIf(t.HasAnyMidiInput(), midiInBtnStyle.Layout)), layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }), layout.Rigid(deleteTrackBtnStyle.Layout), layout.Rigid(newTrackBtnStyle.Layout)) diff --git a/tracker/gioui/numericupdown.go b/tracker/gioui/numericupdown.go index b1a86cd..3f67393 100644 --- a/tracker/gioui/numericupdown.go +++ b/tracker/gioui/numericupdown.go @@ -50,7 +50,6 @@ type NumericUpDownStyle struct { Height unit.Dp Padding unit.Dp shaper text.Shaper - Hidden bool } func NewNumberInput(v tracker.Int) *NumberInput { @@ -58,10 +57,6 @@ func NewNumberInput(v tracker.Int) *NumberInput { } func NumericUpDown(th *material.Theme, number *NumberInput, tooltip string) NumericUpDownStyle { - return NumericUpDownPadded(th, number, tooltip, 0) -} - -func NumericUpDownPadded(th *material.Theme, number *NumberInput, tooltip string, padding int) NumericUpDownStyle { bgColor := th.Palette.Fg bgColor.R /= 4 bgColor.G /= 4 @@ -80,15 +75,12 @@ func NumericUpDownPadded(th *material.Theme, number *NumberInput, tooltip string Tooltip: Tooltip(th, tooltip), Width: unit.Dp(70), Height: unit.Dp(20), - Padding: unit.Dp(padding), + Padding: unit.Dp(0), shaper: *th.Shaper, } } func (s *NumericUpDownStyle) Layout(gtx C) D { - if s.Hidden { - return D{} - } if s.Padding <= 0 { return s.layoutWithTooltip(gtx) } diff --git a/tracker/gioui/tracker.go b/tracker/gioui/tracker.go index b6f540e..f391cac 100644 --- a/tracker/gioui/tracker.go +++ b/tracker/gioui/tracker.go @@ -164,10 +164,7 @@ func (t *Tracker) Main() { func NewWindow() *app.Window { w := new(app.Window) w.Option(app.Title("Sointu Tracker")) - w.Option( - app.Size(unit.Dp(800), unit.Dp(600)), - app.Fullscreen.Option(), - ) + w.Option(app.Size(unit.Dp(800), unit.Dp(600))) return w } @@ -350,3 +347,10 @@ func (t *Tracker) removeFromMidiNotePlaying(note byte) { } } } + +func (t *Tracker) HasAnyMidiInput() bool { + for _ = range t.Model.MIDI.InputDevices { + return true + } + return false +}