mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker): disable buttons when they are not clickable
This commit is contained in:
parent
41cd1d21f6
commit
e62fe85867
@ -43,6 +43,14 @@ func smallButton(icStyle material.IconButtonStyle) material.IconButtonStyle {
|
|||||||
return icStyle
|
return icStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func enableButton(icStyle material.IconButtonStyle, enabled bool) material.IconButtonStyle {
|
||||||
|
if !enabled {
|
||||||
|
icStyle.Background = disabledContainerColor
|
||||||
|
icStyle.Color = disabledTextColor
|
||||||
|
}
|
||||||
|
return icStyle
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tracker) Layout(gtx layout.Context) {
|
func (t *Tracker) Layout(gtx layout.Context) {
|
||||||
paint.FillShape(gtx.Ops, backgroundColor, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op())
|
paint.FillShape(gtx.Ops, backgroundColor, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op())
|
||||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx2 layout.Context) layout.Dimensions {
|
layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx2 layout.Context) layout.Dimensions {
|
||||||
@ -101,12 +109,7 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
paint.FillShape(gtx.Ops, trackMenuSurfaceColor, clip.Rect{
|
paint.FillShape(gtx.Ops, trackMenuSurfaceColor, clip.Rect{
|
||||||
Max: gtx.Constraints.Max,
|
Max: gtx.Constraints.Max,
|
||||||
}.Op())
|
}.Op())
|
||||||
iconBtn := material.IconButton(t.Theme, t.NewTrackBtn, addIcon)
|
return in2.Layout(gtx, enableButton(material.IconButton(t.Theme, t.NewTrackBtn, addIcon), t.song.TotalTrackVoices() < t.song.Patch.TotalVoices()).Layout)
|
||||||
if t.song.TotalTrackVoices() >= t.song.Patch.TotalVoices() {
|
|
||||||
iconBtn.Background = disabledContainerColor
|
|
||||||
iconBtn.Color = disabledTextColor
|
|
||||||
}
|
|
||||||
return in2.Layout(gtx, iconBtn.Layout)
|
|
||||||
})
|
})
|
||||||
octLabel := layout.Rigid(Label("OCT:", white))
|
octLabel := layout.Rigid(Label("OCT:", white))
|
||||||
in := layout.UniformInset(unit.Dp(1))
|
in := layout.UniformInset(unit.Dp(1))
|
||||||
@ -114,11 +117,11 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
return layout.Flex{Axis: layout.Horizontal}.Layout(
|
return layout.Flex{Axis: layout.Horizontal}.Layout(
|
||||||
gtx,
|
gtx,
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
return in.Layout(gtx, smallButton(material.IconButton(t.Theme, t.OctaveUpBtn, upIcon)).Layout)
|
return in.Layout(gtx, enableButton(smallButton(material.IconButton(t.Theme, t.OctaveUpBtn, upIcon)), t.CurrentOctave < 9).Layout)
|
||||||
}),
|
}),
|
||||||
layout.Rigid(Label(fmt.Sprintf("%v", t.CurrentOctave), white)),
|
layout.Rigid(Label(fmt.Sprintf("%v", t.CurrentOctave), white)),
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
return in.Layout(gtx, smallButton(material.IconButton(t.Theme, t.OctaveDownBtn, downIcon)).Layout)
|
return in.Layout(gtx, enableButton(smallButton(material.IconButton(t.Theme, t.OctaveDownBtn, downIcon)), t.CurrentOctave > 0).Layout)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -176,17 +179,13 @@ func (t *Tracker) layoutControls(gtx layout.Context) layout.Dimensions {
|
|||||||
)),
|
)),
|
||||||
layout.Rigid(Label(fmt.Sprintf("BPM: %3v", t.song.BPM), white)),
|
layout.Rigid(Label(fmt.Sprintf("BPM: %3v", t.song.BPM), white)),
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
return in.Layout(gtx, smallButton(material.IconButton(t.Theme, t.BPMUpBtn, upIcon)).Layout)
|
return in.Layout(gtx, enableButton(smallButton(material.IconButton(t.Theme, t.BPMUpBtn, upIcon)), t.song.BPM < 999).Layout)
|
||||||
}),
|
}),
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
return in.Layout(gtx, smallButton(material.IconButton(t.Theme, t.BPMDownBtn, downIcon)).Layout)
|
return in.Layout(gtx, enableButton(smallButton(material.IconButton(t.Theme, t.BPMDownBtn, downIcon)), t.song.BPM > 1).Layout)
|
||||||
}),
|
}),
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||||
iconBtn := material.IconButton(t.Theme, t.NewInstrumentBtn, addIcon)
|
iconBtn := enableButton(material.IconButton(t.Theme, t.NewInstrumentBtn, addIcon), t.song.Patch.TotalVoices() < 32)
|
||||||
if t.song.Patch.TotalVoices() >= 32 {
|
|
||||||
iconBtn.Background = disabledContainerColor
|
|
||||||
iconBtn.Color = disabledTextColor
|
|
||||||
}
|
|
||||||
return in.Layout(gtx, iconBtn.Layout)
|
return in.Layout(gtx, iconBtn.Layout)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user