This commit is contained in:
5684185+vsariola@users.noreply.github.com 2025-05-04 20:02:37 +03:00
parent 750d88f728
commit f9e8ff40a6
6 changed files with 43 additions and 43 deletions

View File

@ -17,8 +17,6 @@ type (
filters []event.Filter filters []event.Filter
requestFocus bool requestFocus bool
} }
EditorStyle material.EditorStyle
) )
func NewEditor(e widget.Editor) *Editor { func NewEditor(e widget.Editor) *Editor {
@ -36,8 +34,12 @@ func NewEditor(e widget.Editor) *Editor {
return ret return ret
} }
func MaterialEditor(th *material.Theme, e *Editor, hint string) EditorStyle { func MaterialEditor(th *Theme, style *LabelStyle, editor *Editor, hint string) material.EditorStyle {
return EditorStyle(material.Editor(th, &e.Editor, hint)) ret := material.Editor(&th.Material, &editor.Editor, hint)
ret.Font = style.Font
ret.TextSize = style.TextSize
ret.Color = style.Color
return ret
} }
func (e *Editor) SetText(s string) { func (e *Editor) SetText(s string) {
@ -80,7 +82,3 @@ func (e *Editor) Cancelled(gtx C) bool {
func (e *Editor) Focus() { func (e *Editor) Focus() {
e.requestFocus = true e.requestFocus = true
} }
func (e *EditorStyle) Layout(gtx C) D {
return material.EditorStyle(*e).Layout(gtx)
}

View File

@ -254,8 +254,7 @@ func (ie *InstrumentEditor) layoutInstrumentHeader(gtx C, t *Tracker) D {
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.Material, ie.commentEditor, "Comment") style := MaterialEditor(t.Theme, &t.Theme.InstrumentEditor.InstrumentComment, 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(ie.commentEditor.Text()) ie.commentString.Set(ie.commentEditor.Text())
return ret return ret
@ -292,11 +291,7 @@ func (ie *InstrumentEditor) layoutInstrumentList(gtx C, t *Tracker) D {
for ie.nameEditor.Submitted(gtx) || ie.nameEditor.Cancelled(gtx) { for ie.nameEditor.Submitted(gtx) || ie.nameEditor.Cancelled(gtx) {
ie.instrumentDragList.Focus() ie.instrumentDragList.Focus()
} }
style := MaterialEditor(&t.Theme.Material, ie.nameEditor, "Instr") style := MaterialEditor(t.Theme, &s, ie.nameEditor, "Instr")
style.Color = s.Color
style.HintColor = instrumentNameHintColor
style.TextSize = s.TextSize
style.Font = s.Font
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)
@ -431,11 +426,8 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
ie.searchEditor.SetText(str.Value()) ie.searchEditor.SetText(str.Value())
ie.unitDragList.Focus() ie.unitDragList.Focus()
} }
style := MaterialEditor(&t.Theme.Material, ie.searchEditor, "---") style := MaterialEditor(t.Theme, &t.Theme.InstrumentEditor.UnitList.Name, ie.searchEditor, "---")
style.Color = color style.Color = color
style.HintColor = t.Theme.InstrumentEditor.UnitList.Comment.Color
style.TextSize = t.Theme.InstrumentEditor.UnitList.Name.TextSize
style.Font = t.Theme.InstrumentEditor.UnitList.Name.Font
ret := style.Layout(gtx) ret := style.Layout(gtx)
str.Set(ie.searchEditor.Text()) str.Set(ie.searchEditor.Text())
return ret return ret

View File

@ -240,6 +240,10 @@ func (te *NoteEditor) layoutTracks(gtx C, t *Tracker) D {
return D{} return D{}
} }
rowMarkerPatternTextColorOp := colorOp(gtx, rowMarkerPatternTextColor)
loopMarkerColorOp := colorOp(gtx, loopMarkerColor)
rowMarkerRowTextColorOp := colorOp(gtx, rowMarkerRowTextColor)
rowTitle := func(gtx C, j int) D { rowTitle := func(gtx C, j int) D {
rpp := max(t.RowsPerPattern().Value(), 1) rpp := max(t.RowsPerPattern().Value(), 1)
pat := j / rpp pat := j / rpp
@ -247,16 +251,14 @@ func (te *NoteEditor) layoutTracks(gtx C, t *Tracker) D {
w := pxPatMarkWidth + pxRowMarkWidth w := pxPatMarkWidth + pxRowMarkWidth
defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop() defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop()
if row == 0 { if row == 0 {
color := rowMarkerPatternTextColor op := rowMarkerPatternTextColorOp
if l := t.Loop(); pat >= l.Start && pat < l.Start+l.Length { if l := t.Loop(); pat >= l.Start && pat < l.Start+l.Length {
color = loopMarkerColor op = loopMarkerColorOp
} }
paint.ColorOp{Color: color}.Add(gtx.Ops) widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", pat)), op)
widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", pat)), op.CallOp{})
} }
defer op.Offset(image.Pt(pxPatMarkWidth, 0)).Push(gtx.Ops).Pop() defer op.Offset(image.Pt(pxPatMarkWidth, 0)).Push(gtx.Ops).Pop()
paint.ColorOp{Color: rowMarkerRowTextColor}.Add(gtx.Ops) widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", row)), rowMarkerRowTextColorOp)
widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", row)), op.CallOp{})
return D{Size: image.Pt(w, pxHeight)} return D{Size: image.Pt(w, pxHeight)}
} }
@ -265,6 +267,11 @@ func (te *NoteEditor) layoutTracks(gtx C, t *Tracker) D {
selection := te.scrollTable.Table.Range() selection := te.scrollTable.Table.Range()
hasTrackMidiIn := te.TrackMidiInBtn.Bool.Value() hasTrackMidiIn := te.TrackMidiInBtn.Bool.Value()
trackerPatMarkerOp := colorOp(gtx, trackerPatMarker)
mediumEmphasisTextColorOp := colorOp(gtx, mediumEmphasisTextColor)
trackerActiveTextColorOp := colorOp(gtx, trackerActiveTextColor)
trackerInactiveTextColorOp := colorOp(gtx, trackerInactiveTextColor)
cell := func(gtx C, x, y int) D { cell := func(gtx C, x, y int) D {
// draw the background, to indicate selection // draw the background, to indicate selection
color := transparent color := transparent
@ -303,23 +310,20 @@ func (te *NoteEditor) layoutTracks(gtx C, t *Tracker) D {
defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop() defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop()
s := t.Model.Order().Value(tracker.Point{X: x, Y: pat}) s := t.Model.Order().Value(tracker.Point{X: x, Y: pat})
if row == 0 { // draw the pattern marker if row == 0 { // draw the pattern marker
paint.ColorOp{Color: trackerPatMarker}.Add(gtx.Ops) widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, patternIndexToString(s), trackerPatMarkerOp)
widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, patternIndexToString(s), op.CallOp{})
} }
if row == 1 && t.Model.PatternUnique(x, s) { // draw a * if the pattern is unique if row == 1 && t.Model.PatternUnique(x, s) { // draw a * if the pattern is unique
paint.ColorOp{Color: mediumEmphasisTextColor}.Add(gtx.Ops) widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, "*", mediumEmphasisTextColorOp)
widget.Label{}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, "*", op.CallOp{})
} }
op := trackerInactiveTextColorOp
if te.scrollTable.Table.Cursor() == point && te.scrollTable.Focused() { if te.scrollTable.Table.Cursor() == point && te.scrollTable.Focused() {
paint.ColorOp{Color: trackerActiveTextColor}.Add(gtx.Ops) op = trackerActiveTextColorOp
} else {
paint.ColorOp{Color: trackerInactiveTextColor}.Add(gtx.Ops)
} }
val := noteStr[byte(t.Model.Notes().Value(tracker.Point{X: x, Y: y}))] val := noteStr[byte(t.Model.Notes().Value(tracker.Point{X: x, Y: y}))]
if t.Model.Notes().Effect(x) { if t.Model.Notes().Effect(x) {
val = hexStr[byte(t.Model.Notes().Value(tracker.Point{X: x, Y: y}))] val = hexStr[byte(t.Model.Notes().Value(tracker.Point{X: x, Y: y}))]
} }
widget.Label{Alignment: text.Middle}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, val, op.CallOp{}) widget.Label{Alignment: text.Middle}.Layout(gtx, t.Theme.Material.Shaper, trackerFont, trackerFontSize, val, op)
return D{Size: image.Pt(pxWidth, pxHeight)} return D{Size: image.Pt(pxWidth, pxHeight)}
} }
table := FilledScrollTable(&t.Theme.Material, te.scrollTable, cell, colTitle, rowTitle, nil, rowTitleBg) table := FilledScrollTable(&t.Theme.Material, te.scrollTable, cell, colTitle, rowTitle, nil, rowTitleBg)
@ -330,6 +334,12 @@ func (te *NoteEditor) layoutTracks(gtx C, t *Tracker) D {
return table.Layout(gtx) return table.Layout(gtx)
} }
func colorOp(gtx C, c color.NRGBA) op.CallOp {
macro := op.Record(gtx.Ops)
paint.ColorOp{Color: c}.Add(gtx.Ops)
return macro.Stop()
}
func (te *NoteEditor) paintColumnCell(gtx C, x int, t *Tracker, c color.NRGBA) { func (te *NoteEditor) paintColumnCell(gtx C, x int, t *Tracker, c color.NRGBA) {
cw := gtx.Constraints.Min.X cw := gtx.Constraints.Min.X
cx := 0 cx := 0

View File

@ -52,9 +52,11 @@ type Theme struct {
ShortCut LabelStyle ShortCut LabelStyle
} }
InstrumentEditor struct { InstrumentEditor struct {
Octave LabelStyle Octave LabelStyle
Voices LabelStyle Voices LabelStyle
InstrumentList struct { InstrumentComment LabelStyle
UnitComment LabelStyle
InstrumentList struct {
Number LabelStyle Number LabelStyle
Name LabelStyle Name LabelStyle
NameMuted LabelStyle NameMuted LabelStyle

View File

@ -102,6 +102,8 @@ menu:
instrumenteditor: instrumenteditor:
octave: { textsize: 14, color: *disabled } octave: { textsize: 14, color: *disabled }
voices: { textsize: 14, color: *disabled } voices: { textsize: 14, color: *disabled }
instrumentcomment: { textsize: 14, color: *mediumemphasis }
unitcomment: { textsize: 14, color: *mediumemphasis }
instrumentlist: instrumentlist:
number: { textsize: 10, color: *mediumemphasis, shadowcolor: *black } number: { textsize: 10, color: *mediumemphasis, shadowcolor: *black }
name: { textsize: 12, color: *white, shadowcolor: *black } name: { textsize: 12, color: *white, shadowcolor: *black }
@ -112,6 +114,6 @@ instrumenteditor:
stack: { textsize: 12, color: *mediumemphasis, shadowcolor: *black } stack: { textsize: 12, color: *mediumemphasis, shadowcolor: *black }
disabled: { textsize: 12, color: *disabled } disabled: { textsize: 12, color: *disabled }
uniteditor: uniteditor:
hint: { textsize: 14, color: *highemphasis, shadowcolor: *black } hint: { textsize: 16, color: *highemphasis, shadowcolor: *black }
chooser: { textsize: 12, color: *white, shadowcolor: *black } chooser: { textsize: 12, color: *white, shadowcolor: *black }
parametername: { textsize: 14, color: *white, shadowcolor: *black } parametername: { textsize: 16, color: *white, shadowcolor: *black }

View File

@ -164,11 +164,7 @@ func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D {
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.Material, pe.commentEditor, "---") commentStyle := MaterialEditor(t.Theme, &t.Theme.InstrumentEditor.UnitComment, pe.commentEditor, "---")
commentStyle.Font = labelDefaultFont
commentStyle.TextSize = labelDefaultFontSize
commentStyle.Color = mediumEmphasisTextColor
commentStyle.HintColor = mediumEmphasisTextColor
ret := commentStyle.Layout(gtx) ret := commentStyle.Layout(gtx)
s.Set(pe.commentEditor.Text()) s.Set(pe.commentEditor.Text())
return ret return ret