fix(tracker/gioui): text.Shaper should not be a global variable

text.Shaper is not thread safe, which caused crash when adding
multiple VSTI plugins to a DAW project. This change fixes that
crash. Further refactorings need to consider where that text.Shaper
should actually reside.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-22 19:10:24 +03:00
parent 3c85f1155c
commit a38a0f4235
15 changed files with 56 additions and 43 deletions

View File

@ -20,6 +20,7 @@ type LabelStyle struct {
Alignment layout.Direction
Font font.Font
FontSize unit.Sp
Shaper *text.Shaper
}
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
@ -31,7 +32,7 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
dims := widget.Label{
Alignment: text.Start,
MaxLines: 1,
}.Layout(gtx, textShaper, l.Font, l.FontSize, l.Text, op.CallOp{})
}.Layout(gtx, l.Shaper, l.Font, l.FontSize, l.Text, op.CallOp{})
return layout.Dimensions{
Size: dims.Size.Add(image.Pt(2, 2)),
Baseline: dims.Baseline,
@ -42,11 +43,11 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
return widget.Label{
Alignment: text.Start,
MaxLines: 1,
}.Layout(gtx, textShaper, l.Font, l.FontSize, l.Text, op.CallOp{})
}.Layout(gtx, l.Shaper, l.Font, l.FontSize, l.Text, op.CallOp{})
}),
)
}
func Label(str string, color color.NRGBA) layout.Widget {
return LabelStyle{Text: str, Color: color, ShadeColor: black, Font: labelDefaultFont, FontSize: labelDefaultFontSize, Alignment: layout.W}.Layout
func Label(str string, color color.NRGBA, shaper *text.Shaper) layout.Widget {
return LabelStyle{Text: str, Color: color, ShadeColor: black, Font: labelDefaultFont, FontSize: labelDefaultFontSize, Alignment: layout.W, Shaper: shaper}.Layout
}