Skip to content

Commit

Permalink
fix: from review
Browse files Browse the repository at this point in the history
  • Loading branch information
qm210 committed Nov 22, 2024
1 parent ad690c7 commit 243396c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
5 changes: 1 addition & 4 deletions tracker/gioui/buttons.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"gioui.org/widget"
"gioui.org/widget/material"
"gioui.org/x/component"

"github.com/vsariola/sointu/tracker"
)

Expand Down Expand Up @@ -298,7 +299,6 @@ type ButtonStyle struct {
Inset layout.Inset
Button *Clickable
shaper *text.Shaper
Hidden bool
}

type ButtonLayoutStyle struct {
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tracker/gioui/layout.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions tracker/gioui/note_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
Expand Down
10 changes: 1 addition & 9 deletions tracker/gioui/numericupdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ type NumericUpDownStyle struct {
Height unit.Dp
Padding unit.Dp
shaper text.Shaper
Hidden bool
}

func NewNumberInput(v tracker.Int) *NumberInput {
return &NumberInput{Int: v}
}

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
Expand All @@ -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)
}
Expand Down
12 changes: 8 additions & 4 deletions tracker/gioui/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit 243396c

Please sign in to comment.