Skip to content

Commit

Permalink
remove config property TextWeight
Browse files Browse the repository at this point in the history
  • Loading branch information
oligo committed Feb 24, 2025
1 parent d8a7685 commit 7b6dc54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 10 additions & 6 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"regexp"

"gioui.org/app"
"gioui.org/font"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/paint"
Expand All @@ -31,6 +30,10 @@ type EditorApp struct {
state *gvcode.Editor
}

const (
syntaxPattern = "package|import|type|func|struct|for|var|switch|case|if|else"
)

func (ed *EditorApp) run() error {

var ops op.Ops
Expand Down Expand Up @@ -59,7 +62,7 @@ func (ed *EditorApp) layout(gtx C, th *material.Theme) D {

switch evt.(type) {
case gvcode.ChangeEvent:
styles := HightlightTextByPattern(ed.state.Text(), "sample|demostrating")
styles := HightlightTextByPattern(ed.state.Text(), syntaxPattern)
ed.state.UpdateTextStyles(styles)
}
}
Expand Down Expand Up @@ -87,10 +90,9 @@ func (ed *EditorApp) layout(gtx C, th *material.Theme) D {
}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
es := wg.NewEditor(th, ed.state)
es.Font.Typeface = "monospace"
es.TextSize = unit.Sp(14)
es.TextSize = unit.Sp(12)
es.LineHeightScale = 1.5
es.TextHighlightColor = color.NRGBA{R: 120, G: 120, B: 120, A: 200}
es.TextWeight = font.Normal

return es.Layout(gtx)
})
Expand All @@ -115,9 +117,11 @@ func main() {
// Have to set it to true as horizontal scrolling does not work yet.
WrapLine: true,
}
editorApp.state.SetText("This is a sample text for demostrating purpose!")

thisFile, _ := os.ReadFile("./main.go")
editorApp.state.SetText(string(thisFile))
// editorApp.state.SetHighlights([]editor.TextRange{{Start: 0, End: 5}})
styles := HightlightTextByPattern(editorApp.state.Text(), "sample|demostrating")
styles := HightlightTextByPattern(editorApp.state.Text(), syntaxPattern)
editorApp.state.UpdateTextStyles(styles)

go func() {
Expand Down
3 changes: 0 additions & 3 deletions widget/editor_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ type EditorStyle struct {
TabWidth int
// TextSize set the text size.
TextSize unit.Sp
// TextWeight set the text weight.
TextWeight font.Weight
// Color is the text color.
Color color.NRGBA
// SelectionColor is the color of the background for selected text.
Expand Down Expand Up @@ -87,7 +85,6 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
lineNumColor := lineNumColorMacro.Stop()

e.Editor.Font = e.Font
e.Editor.Font.Weight = e.TextWeight
e.Editor.TextSize = e.TextSize
e.Editor.LineHeight = e.LineHeight
e.Editor.LineHeightScale = e.LineHeightScale
Expand Down

0 comments on commit 7b6dc54

Please sign in to comment.