Skip to content

Commit c1d5255

Browse files
committed
Text: add OverflowsX and OverflowsY, fix Text height to refer to filled height
1 parent fa8f17a commit c1d5255

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

text.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ type Text struct {
124124
TextOrientation
125125
Width, Height float64
126126
Text string
127-
Overflows bool // true if lines stick out of the box
127+
OverflowsX bool // true if lines stick out of the box (horizontally)
128+
OverflowsY bool // true if lines don't fit in the box (vertically)
128129
}
129130

130131
type line struct {
@@ -776,8 +777,9 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, opts
776777
} else if halign == Justify && 0.0 < breaks[j].Ratio {
777778
lineWidth += breaks[j].Stretch * breaks[j].Ratio
778779
}
780+
t.Width = math.Max(t.Width, lineWidth)
779781
if w < lineWidth {
780-
t.Overflows = true
782+
t.OverflowsX = true
781783
}
782784

783785
// shift line to centre or right
@@ -948,6 +950,7 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, opts
948950
if height != 0.0 && h < y+ascent+descent {
949951
// line doesn't fit
950952
t.Text = log[:glyphs[ag].Cluster]
953+
t.OverflowsY = true
951954
break
952955
}
953956
line.y = y + ascent
@@ -967,6 +970,7 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, opts
967970
_, _, descent, bottom := t.lines[len(t.lines)-1].Heights(rt.mode)
968971
y += -bottom*lineSpacing + descent
969972
}
973+
t.Height = y
970974

971975
// vertical align
972976
if rt.mode == VerticalRL {
@@ -997,22 +1001,6 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, opts
9971001
t.lines[j].y = h - t.lines[j].y
9981002
}
9991003
}
1000-
1001-
if width == 0.0 {
1002-
for _, line := range t.lines {
1003-
if 0 < len(line.spans) {
1004-
last := line.spans[len(line.spans)-1]
1005-
t.Width = math.Max(t.Width, last.X+last.Width)
1006-
}
1007-
}
1008-
} else {
1009-
t.Width = width
1010-
}
1011-
if height == 0.0 {
1012-
t.Height = y
1013-
} else {
1014-
t.Height = height
1015-
}
10161004
return t
10171005
}
10181006

0 commit comments

Comments
 (0)