Skip to content

Commit

Permalink
Fix vertical alignment of text for single lines, fixes #247
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Sep 10, 2023
1 parent 8bc6ac4 commit b542483
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, inde
bottom *= lineSpacing

if height != 0.0 && height < y+ascent+descent {
// doesn't fit or at the end of items
// line doesn't fit
t.lines = t.lines[:len(t.lines)-1]
if 0 < j {
t.text = log[:glyphs[i].Cluster]
Expand All @@ -783,6 +783,7 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, inde
t.lines[j].y = y + ascent
y += ascent + bottom
if position == len(items)-1 {
// end of text
break
}

Expand Down Expand Up @@ -901,9 +902,9 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, inde
i += item.Size
}

if 0 < j {
if 0 < len(t.lines) {
// remove line gap of last line
_, _, descent, bottom := t.lines[j-1].Heights(rt.mode)
_, _, descent, bottom := t.lines[len(t.lines)-1].Heights(rt.mode)
y += -bottom*lineSpacing + descent
}

Expand Down

0 comments on commit b542483

Please sign in to comment.