feat: focus search editor after "add unit"

This commit is contained in:
qm210 2024-10-27 08:08:12 +01:00
parent 8d7d896375
commit 56f5297188
3 changed files with 23 additions and 5 deletions

View File

@ -141,7 +141,7 @@ func (m *Model) SplitInstrument() Action {
func (m *Model) AddUnit(before bool) Action {
return Allow(func() {
defer (*Model)(m).change("AddUnitAction", PatchChange, MajorChange)()
defer m.change("AddUnitAction", PatchChange, MajorChange)()
if len(m.d.Song.Patch) == 0 { // no instruments, add one
instr := sointu.Instrument{NumVoices: 1}
instr.Units = make([]sointu.Unit, 0, 1)
@ -159,12 +159,19 @@ func (m *Model) AddUnit(before bool) Action {
m.d.UnitIndex2 = m.d.UnitIndex
copy(newUnits, instr.Units[:m.d.UnitIndex])
copy(newUnits[m.d.UnitIndex+1:], instr.Units[m.d.UnitIndex:])
(*Model)(m).assignUnitIDs(newUnits[m.d.UnitIndex : m.d.UnitIndex+1])
m.assignUnitIDs(newUnits[m.d.UnitIndex : m.d.UnitIndex+1])
m.d.Song.Patch[m.d.InstrIndex].Units = newUnits
m.d.ParamIndex = 0
})
}
func (m *Model) AddUnitAndThen(callback func()) Action {
return Allow(func() {
m.AddUnit(false).Do()
callback()
})
}
func (m *Model) DeleteUnit() Action {
return Action{
allowed: func() bool {

View File

@ -13,8 +13,9 @@ type (
// application while editing (particularly: to prevent triggering notes
// while editing).
Editor struct {
Editor widget.Editor
filters []event.Filter
Editor widget.Editor
filters []event.Filter
requestFocus bool
}
EditorStyle material.EditorStyle
@ -76,6 +77,10 @@ func (e *Editor) Cancelled(gtx C) bool {
return false
}
func (e *Editor) Focus() {
e.requestFocus = true
}
func (e *EditorStyle) Layout(gtx C) D {
return material.EditorStyle(*e).Layout(gtx)
}

View File

@ -72,7 +72,6 @@ func NewInstrumentEditor(model *tracker.Model) *InstrumentEditor {
copyInstrumentBtn: new(TipClickable),
saveInstrumentBtn: new(TipClickable),
loadInstrumentBtn: new(TipClickable),
addUnitBtn: NewActionClickable(model.AddUnit(false)),
commentExpandBtn: NewBoolClickable(model.CommentExpanded().Bool()),
presetMenuBtn: new(TipClickable),
soloBtn: NewBoolClickable(model.Solo().Bool()),
@ -91,6 +90,7 @@ func NewInstrumentEditor(model *tracker.Model) *InstrumentEditor {
ret.presetMenuItems = append(ret.presetMenuItems, MenuItem{Text: name, IconBytes: icons.ImageAudiotrack, Doer: model.LoadPreset(index)})
return true
})
ret.addUnitBtn = NewActionClickable(model.AddUnitAndThen(func() { ret.searchEditor.Focus() }))
ret.enlargeHint = makeHint("Enlarge", " (%s)", "InstrEnlargedToggle")
ret.shrinkHint = makeHint("Shrink", " (%s)", "InstrEnlargedToggle")
ret.addInstrumentHint = makeHint("Add\ninstrument", "\n(%s)", "AddInstrument")
@ -383,6 +383,12 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
}
count := min(ie.unitDragList.TrackerList.Count(), 256)
if ie.searchEditor.requestFocus {
// for now, only the searchEditor has its requestFocus flag
ie.searchEditor.requestFocus = false
gtx.Execute(key.FocusCmd{Tag: &ie.searchEditor.Editor})
}
element := func(gtx C, i int) D {
gtx.Constraints.Max.Y = gtx.Dp(20)
gtx.Constraints.Min.Y = gtx.Constraints.Max.Y