feat: focus search editor after "add unit"

This commit is contained in:
qm210
2024-10-27 08:08:12 +01:00
committed by Veikko Sariola
parent 8d7d896375
commit 639b2266e3
3 changed files with 23 additions and 5 deletions

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