mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-03 09:08:18 -04:00
refactor(tracker/gioui): give Editor Text / SetText methods
This commit is contained in:
parent
03c994e4da
commit
2b7ce39069
@ -39,6 +39,16 @@ func MaterialEditor(th *material.Theme, e *Editor, hint string) EditorStyle {
|
|||||||
return EditorStyle(material.Editor(th, &e.Editor, hint))
|
return EditorStyle(material.Editor(th, &e.Editor, hint))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Editor) SetText(s string) {
|
||||||
|
if e.Editor.Text() != s {
|
||||||
|
e.Editor.SetText(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Editor) Text() string {
|
||||||
|
return e.Editor.Text()
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Editor) Submitted(gtx C) bool {
|
func (e *Editor) Submitted(gtx C) bool {
|
||||||
for {
|
for {
|
||||||
ev, ok := e.Editor.Update(gtx)
|
ev, ok := e.Editor.Update(gtx)
|
||||||
|
@ -225,16 +225,14 @@ func (ie *InstrumentEditor) layoutInstrumentHeader(gtx C, t *Tracker) D {
|
|||||||
layout.Rigid(header),
|
layout.Rigid(header),
|
||||||
layout.Rigid(func(gtx C) D {
|
layout.Rigid(func(gtx C) D {
|
||||||
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
||||||
style := MaterialEditor(t.Theme, ie.commentEditor, "Comment")
|
ie.commentEditor.SetText(ie.commentString.Value())
|
||||||
style.Color = highEmphasisTextColor
|
|
||||||
if style.Editor.Text() != ie.commentString.Value() {
|
|
||||||
style.Editor.SetText(ie.commentString.Value())
|
|
||||||
}
|
|
||||||
for ie.commentEditor.Submitted(gtx) || ie.commentEditor.Cancelled(gtx) {
|
for ie.commentEditor.Submitted(gtx) || ie.commentEditor.Cancelled(gtx) {
|
||||||
ie.instrumentDragList.Focus()
|
ie.instrumentDragList.Focus()
|
||||||
}
|
}
|
||||||
|
style := MaterialEditor(t.Theme, ie.commentEditor, "Comment")
|
||||||
|
style.Color = highEmphasisTextColor
|
||||||
ret := layout.UniformInset(unit.Dp(6)).Layout(gtx, style.Layout)
|
ret := layout.UniformInset(unit.Dp(6)).Layout(gtx, style.Layout)
|
||||||
ie.commentString.Set(style.Editor.Text())
|
ie.commentString.Set(ie.commentEditor.Text())
|
||||||
return ret
|
return ret
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -261,22 +259,20 @@ func (ie *InstrumentEditor) layoutInstrumentList(gtx C, t *Tracker) D {
|
|||||||
k := byte(255 - level*127)
|
k := byte(255 - level*127)
|
||||||
color := color.NRGBA{R: 255, G: k, B: 255, A: 255}
|
color := color.NRGBA{R: 255, G: k, B: 255, A: 255}
|
||||||
if i == ie.instrumentDragList.TrackerList.Selected() {
|
if i == ie.instrumentDragList.TrackerList.Selected() {
|
||||||
|
ie.nameEditor.SetText(name)
|
||||||
|
for ie.nameEditor.Submitted(gtx) || ie.nameEditor.Cancelled(gtx) {
|
||||||
|
ie.instrumentDragList.Focus()
|
||||||
|
}
|
||||||
style := MaterialEditor(t.Theme, ie.nameEditor, "Instr")
|
style := MaterialEditor(t.Theme, ie.nameEditor, "Instr")
|
||||||
style.Color = color
|
style.Color = color
|
||||||
style.HintColor = instrumentNameHintColor
|
style.HintColor = instrumentNameHintColor
|
||||||
style.TextSize = unit.Sp(12)
|
style.TextSize = unit.Sp(12)
|
||||||
style.Font = labelDefaultFont
|
style.Font = labelDefaultFont
|
||||||
if n := name; n != style.Editor.Text() {
|
|
||||||
style.Editor.SetText(n)
|
|
||||||
}
|
|
||||||
for ie.nameEditor.Submitted(gtx) || ie.nameEditor.Cancelled(gtx) {
|
|
||||||
ie.instrumentDragList.Focus()
|
|
||||||
}
|
|
||||||
dims := layout.Center.Layout(gtx, func(gtx C) D {
|
dims := layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
||||||
return style.Layout(gtx)
|
return style.Layout(gtx)
|
||||||
})
|
})
|
||||||
ie.nameString.Set(style.Editor.Text())
|
ie.nameString.Set(ie.nameEditor.Text())
|
||||||
return dims
|
return dims
|
||||||
}
|
}
|
||||||
if name == "" {
|
if name == "" {
|
||||||
@ -321,7 +317,7 @@ func (ie *InstrumentEditor) layoutInstrumentList(gtx C, t *Tracker) D {
|
|||||||
case key.NameDownArrow:
|
case key.NameDownArrow:
|
||||||
ie.unitDragList.Focus()
|
ie.unitDragList.Focus()
|
||||||
case key.NameReturn, key.NameEnter:
|
case key.NameReturn, key.NameEnter:
|
||||||
gtx.Execute(key.FocusCmd{Tag: ie.nameEditor.Editor})
|
gtx.Execute(key.FocusCmd{Tag: &ie.nameEditor.Editor})
|
||||||
l := len(ie.nameEditor.Editor.Text())
|
l := len(ie.nameEditor.Editor.Text())
|
||||||
ie.nameEditor.Editor.SetCaret(l, l)
|
ie.nameEditor.Editor.SetCaret(l, l)
|
||||||
}
|
}
|
||||||
@ -380,38 +376,34 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
|
|||||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||||
layout.Rigid(func(gtx C) D {
|
layout.Rigid(func(gtx C) D {
|
||||||
if i == ie.unitDragList.TrackerList.Selected() {
|
if i == ie.unitDragList.TrackerList.Selected() {
|
||||||
style := MaterialEditor(t.Theme, ie.searchEditor, "---")
|
|
||||||
style.Color = color
|
|
||||||
style.HintColor = instrumentNameHintColor
|
|
||||||
style.TextSize = unit.Sp(12)
|
|
||||||
style.Font = f
|
|
||||||
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
||||||
str := tracker.String{StringData: (*tracker.UnitSearch)(t.Model)}
|
str := tracker.String{StringData: (*tracker.UnitSearch)(t.Model)}
|
||||||
if style.Editor.Text() != str.Value() {
|
ie.searchEditor.SetText(str.Value())
|
||||||
style.Editor.SetText(str.Value())
|
|
||||||
}
|
|
||||||
for ie.searchEditor.Submitted(gtx) {
|
for ie.searchEditor.Submitted(gtx) {
|
||||||
ie.unitDragList.Focus()
|
ie.unitDragList.Focus()
|
||||||
if text := style.Editor.Text(); text != "" {
|
if text := ie.searchEditor.Text(); text != "" {
|
||||||
for _, n := range sointu.UnitNames {
|
for _, n := range sointu.UnitNames {
|
||||||
if strings.HasPrefix(n, style.Editor.Text()) {
|
if strings.HasPrefix(n, ie.searchEditor.Text()) {
|
||||||
t.Units().SetSelectedType(n)
|
t.Units().SetSelectedType(n)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.UnitSearching().Bool().Set(false)
|
t.UnitSearching().Bool().Set(false)
|
||||||
style.Editor.SetText(str.Value())
|
ie.searchEditor.SetText(str.Value())
|
||||||
}
|
}
|
||||||
for ie.searchEditor.Cancelled(gtx) {
|
for ie.searchEditor.Cancelled(gtx) {
|
||||||
t.UnitSearching().Bool().Set(false)
|
t.UnitSearching().Bool().Set(false)
|
||||||
style.Editor.SetText(str.Value())
|
ie.searchEditor.SetText(str.Value())
|
||||||
ie.unitDragList.Focus()
|
ie.unitDragList.Focus()
|
||||||
}
|
}
|
||||||
|
style := MaterialEditor(t.Theme, ie.searchEditor, "---")
|
||||||
|
style.Color = color
|
||||||
|
style.HintColor = instrumentNameHintColor
|
||||||
|
style.TextSize = unit.Sp(12)
|
||||||
|
style.Font = f
|
||||||
ret := style.Layout(gtx)
|
ret := style.Layout(gtx)
|
||||||
if style.Editor.Text() != str.Value() {
|
str.Set(ie.searchEditor.Text())
|
||||||
str.Set(style.Editor.Text())
|
|
||||||
}
|
|
||||||
return ret
|
return ret
|
||||||
} else {
|
} else {
|
||||||
unitNameLabel := LabelStyle{Text: u.Type, ShadeColor: black, Color: color, Font: f, FontSize: unit.Sp(12), Shaper: t.Theme.Shaper}
|
unitNameLabel := LabelStyle{Text: u.Type, ShadeColor: black, Color: color, Font: f, FontSize: unit.Sp(12), Shaper: t.Theme.Shaper}
|
||||||
@ -457,11 +449,11 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
|
|||||||
case key.NameDeleteBackward:
|
case key.NameDeleteBackward:
|
||||||
t.Units().SetSelectedType("")
|
t.Units().SetSelectedType("")
|
||||||
t.UnitSearching().Bool().Set(true)
|
t.UnitSearching().Bool().Set(true)
|
||||||
gtx.Execute(key.FocusCmd{Tag: ie.searchEditor})
|
gtx.Execute(key.FocusCmd{Tag: &ie.searchEditor.Editor})
|
||||||
case key.NameEnter, key.NameReturn:
|
case key.NameEnter, key.NameReturn:
|
||||||
t.Model.AddUnit(e.Modifiers.Contain(key.ModCtrl)).Do()
|
t.Model.AddUnit(e.Modifiers.Contain(key.ModCtrl)).Do()
|
||||||
t.UnitSearching().Bool().Set(true)
|
t.UnitSearching().Bool().Set(true)
|
||||||
gtx.Execute(key.FocusCmd{Tag: ie.searchEditor})
|
gtx.Execute(key.FocusCmd{Tag: &ie.searchEditor.Editor})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,11 +141,6 @@ func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D {
|
|||||||
text = pe.caser.String(text)
|
text = pe.caser.String(text)
|
||||||
}
|
}
|
||||||
hintText := Label(text, white, t.Theme.Shaper)
|
hintText := Label(text, white, t.Theme.Shaper)
|
||||||
commentStyle := MaterialEditor(t.Theme, pe.commentEditor, "---")
|
|
||||||
commentStyle.Font = labelDefaultFont
|
|
||||||
commentStyle.TextSize = labelDefaultFontSize
|
|
||||||
commentStyle.Color = mediumEmphasisTextColor
|
|
||||||
commentStyle.HintColor = mediumEmphasisTextColor
|
|
||||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||||
layout.Rigid(deleteUnitBtnStyle.Layout),
|
layout.Rigid(deleteUnitBtnStyle.Layout),
|
||||||
layout.Rigid(copyUnitBtnStyle.Layout),
|
layout.Rigid(copyUnitBtnStyle.Layout),
|
||||||
@ -164,14 +159,17 @@ func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D {
|
|||||||
}),
|
}),
|
||||||
layout.Flexed(1, func(gtx C) D {
|
layout.Flexed(1, func(gtx C) D {
|
||||||
s := t.UnitComment().String()
|
s := t.UnitComment().String()
|
||||||
if commentStyle.Editor.Text() != s.Value() {
|
pe.commentEditor.SetText(s.Value())
|
||||||
commentStyle.Editor.SetText(s.Value())
|
|
||||||
}
|
|
||||||
for pe.commentEditor.Submitted(gtx) || pe.commentEditor.Cancelled(gtx) {
|
for pe.commentEditor.Submitted(gtx) || pe.commentEditor.Cancelled(gtx) {
|
||||||
t.InstrumentEditor.Focus()
|
t.InstrumentEditor.Focus()
|
||||||
}
|
}
|
||||||
|
commentStyle := MaterialEditor(t.Theme, pe.commentEditor, "---")
|
||||||
|
commentStyle.Font = labelDefaultFont
|
||||||
|
commentStyle.TextSize = labelDefaultFontSize
|
||||||
|
commentStyle.Color = mediumEmphasisTextColor
|
||||||
|
commentStyle.HintColor = mediumEmphasisTextColor
|
||||||
ret := commentStyle.Layout(gtx)
|
ret := commentStyle.Layout(gtx)
|
||||||
s.Set(commentStyle.Editor.Text())
|
s.Set(pe.commentEditor.Text())
|
||||||
return ret
|
return ret
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user