mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
go.*,text: implement shaper-driven line truncation
This commit pushes limiting the maximum number of lines of text into the shaper implementation. This is more efficient than doing it in widgets, and also opens the door for future use of the shaper to insert ellipsis and other truncating characters as appropriate. I realized that we lost the implementation of limiting the number of lines of text in my text stack overhaul, so this fixes a regression from that work. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -192,6 +192,8 @@ func (l *Shaper) layoutText(params Parameters, minWidth, maxWidth int, lc system
|
||||
l.txt.append(l.layoutParagraph(params, minWidth, maxWidth, lc, "", nil))
|
||||
return
|
||||
}
|
||||
truncating := params.MaxLines > 0
|
||||
maxLines := params.MaxLines
|
||||
var done bool
|
||||
var startByte int
|
||||
var endByte int
|
||||
@@ -222,6 +224,12 @@ func (l *Shaper) layoutText(params Parameters, minWidth, maxWidth int, lc system
|
||||
done = endByte == len(str)
|
||||
}
|
||||
l.txt.append(l.layoutParagraph(params, minWidth, maxWidth, lc, str[startByte:endByte], l.paragraph))
|
||||
if truncating {
|
||||
params.MaxLines = maxLines - len(l.txt.lines)
|
||||
if params.MaxLines == 0 {
|
||||
done = true
|
||||
}
|
||||
}
|
||||
if done {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user