mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +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:
+5
-3
@@ -384,9 +384,11 @@ func (s *shaperImpl) shapeText(faces []font.Face, ppem fixed.Int26_6, lc system.
|
||||
}
|
||||
|
||||
// shapeAndWrapText invokes the text shaper and returns wrapped lines in the shaper's native format.
|
||||
func (s *shaperImpl) shapeAndWrapText(faces []font.Face, ppem fixed.Int26_6, maxWidth int, lc system.Locale, txt []rune) []shaping.Line {
|
||||
func (s *shaperImpl) shapeAndWrapText(faces []font.Face, params Parameters, maxWidth int, lc system.Locale, txt []rune) []shaping.Line {
|
||||
// Wrap outputs into lines.
|
||||
return s.wrapper.WrapParagraph(maxWidth, txt, s.shapeText(faces, ppem, lc, txt)...)
|
||||
return s.wrapper.WrapParagraph(shaping.WrapConfig{
|
||||
TruncateAfterLines: params.MaxLines,
|
||||
}, maxWidth, txt, s.shapeText(faces, params.PxPerEm, lc, txt)...)
|
||||
}
|
||||
|
||||
// replaceControlCharacters replaces problematic unicode
|
||||
@@ -445,7 +447,7 @@ func (s *shaperImpl) LayoutRunes(params Parameters, minWidth, maxWidth int, lc s
|
||||
if hasNewline {
|
||||
txt = txt[:len(txt)-1]
|
||||
}
|
||||
ls := s.shapeAndWrapText(s.orderer.sortedFacesForStyle(params.Font), params.PxPerEm, maxWidth, lc, replaceControlCharacters(txt))
|
||||
ls := s.shapeAndWrapText(s.orderer.sortedFacesForStyle(params.Font), params, maxWidth, lc, replaceControlCharacters(txt))
|
||||
// Convert to Lines.
|
||||
textLines := make([]line, len(ls))
|
||||
for i := range ls {
|
||||
|
||||
Reference in New Issue
Block a user