Skip to content

Commit

Permalink
add basic span-based rendering in htmlcanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Feb 5, 2025
1 parent 99d9c40 commit af873cd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion paint/renderers/htmlcanvas/htmlcanvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"cogentcore.org/core/paint/render"
"cogentcore.org/core/styles"
"cogentcore.org/core/styles/units"
"cogentcore.org/core/text/rich"
)

// Renderer is an HTML canvas renderer.
Expand Down Expand Up @@ -222,7 +223,11 @@ func (rs *Renderer) RenderText(text *render.Text) {
// TODO: improve
rs.ctx.Set("font", "25px sans-serif")
rs.ctx.Set("fillStyle", "black")
rs.ctx.Call("fillText", string(text.Text.Source[0]), text.Position.X, text.Position.Y)
for _, span := range text.Text.Source {
st := &rich.Style{}
raw := st.FromRunes(span)
rs.ctx.Call("fillText", string(raw), text.Position.X, text.Position.Y)
}
}

func jsAwait(v js.Value) (result js.Value, ok bool) {
Expand Down

0 comments on commit af873cd

Please sign in to comment.