mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker): add button for deleting instrument
This commit is contained in:
parent
6c97b5e736
commit
22c433b3e4
@ -44,10 +44,41 @@ func (t *Tracker) layoutInstruments() layout.Widget {
|
||||
}),
|
||||
)
|
||||
}),
|
||||
layout.Rigid(t.layoutInstrumentHeader()),
|
||||
layout.Flexed(1, t.layoutInstrumentEditor()))
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracker) layoutInstrumentHeader() layout.Widget {
|
||||
headerBg := func(gtx C) D {
|
||||
paint.FillShape(gtx.Ops, trackMenuSurfaceColor, clip.Rect{
|
||||
Max: gtx.Constraints.Min,
|
||||
}.Op())
|
||||
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||
}
|
||||
header := func(gtx C) D {
|
||||
deleteInstrumentBtnStyle := material.IconButton(t.Theme, t.DeleteInstrumentBtn, deleteIcon)
|
||||
deleteInstrumentBtnStyle.Background = transparent
|
||||
deleteInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||
if len(t.song.Patch.Instruments) > 1 {
|
||||
deleteInstrumentBtnStyle.Color = primaryColor
|
||||
} else {
|
||||
deleteInstrumentBtnStyle.Color = disabledTextColor
|
||||
}
|
||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
||||
layout.Rigid(deleteInstrumentBtnStyle.Layout))
|
||||
}
|
||||
for t.DeleteInstrumentBtn.Clicked() {
|
||||
t.DeleteInstrument()
|
||||
}
|
||||
return func(gtx C) D {
|
||||
return layout.Stack{Alignment: layout.Center}.Layout(gtx,
|
||||
layout.Expanded(headerBg),
|
||||
layout.Stacked(header))
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracker) layoutInstrumentNames() layout.Widget {
|
||||
return func(gtx C) D {
|
||||
gtx.Constraints.Max.Y = gtx.Px(unit.Dp(36))
|
||||
|
@ -22,6 +22,7 @@ var addIcon *widget.Icon
|
||||
var loadIcon *widget.Icon
|
||||
var saveIcon *widget.Icon
|
||||
var clearIcon *widget.Icon
|
||||
var deleteIcon *widget.Icon
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
@ -49,6 +50,10 @@ func init() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
deleteIcon, err = widget.NewIcon(icons.ActionDelete)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func smallButton(icStyle material.IconButtonStyle) material.IconButtonStyle {
|
||||
|
@ -31,6 +31,7 @@ type Tracker struct {
|
||||
BPM *NumberInput
|
||||
NewTrackBtn *widget.Clickable
|
||||
NewInstrumentBtn *widget.Clickable
|
||||
DeleteInstrumentBtn *widget.Clickable
|
||||
LoadSongFileBtn *widget.Clickable
|
||||
NewSongFileBtn *widget.Clickable
|
||||
AddSemitoneBtn *widget.Clickable
|
||||
@ -210,6 +211,17 @@ func (t *Tracker) AddInstrument() {
|
||||
t.sequencer.SetPatch(t.song.Patch)
|
||||
}
|
||||
|
||||
func (t *Tracker) DeleteInstrument() {
|
||||
if len(t.song.Patch.Instruments) <= 1 {
|
||||
return
|
||||
}
|
||||
t.SaveUndo()
|
||||
t.song.Patch.Instruments = append(t.song.Patch.Instruments[:t.CurrentInstrument], t.song.Patch.Instruments[t.CurrentInstrument+1:]...)
|
||||
if t.CurrentInstrument >= len(t.song.Patch.Instruments) {
|
||||
t.CurrentInstrument = len(t.song.Patch.Instruments) - 1
|
||||
}
|
||||
}
|
||||
|
||||
// SetCurrentNote sets the (note) value in current pattern under cursor to iv
|
||||
func (t *Tracker) SetCurrentNote(iv byte) {
|
||||
t.SaveUndo()
|
||||
@ -318,6 +330,7 @@ func New(audioContext sointu.AudioContext) *Tracker {
|
||||
SongLength: new(NumberInput),
|
||||
NewTrackBtn: new(widget.Clickable),
|
||||
NewInstrumentBtn: new(widget.Clickable),
|
||||
DeleteInstrumentBtn: new(widget.Clickable),
|
||||
NewSongFileBtn: new(widget.Clickable),
|
||||
LoadSongFileBtn: new(widget.Clickable),
|
||||
SaveSongFileBtn: new(widget.Clickable),
|
||||
|
Loading…
x
Reference in New Issue
Block a user