mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
go.*,text,widget{,/material}: enable configurable line wrapping within words
This commit enables consumers of the text shaper to select a policy for how line breaking candidates will be chosen. The new default policy can break lines within "words" (UAX#14 segments) when words do not fit by themselves on a line. This ensures that text does not horizontally overflow its bounding box unless the available width is insufficient to display a single UAX#29 grapheme cluster. Fixes: https://todo.sr.ht/~eliasnaur/gio/467 Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -57,7 +57,9 @@ type Selectable struct {
|
||||
MaxLines int
|
||||
// Truncator is the symbol to use at the end of the final line of text
|
||||
// if text was cut off. Defaults to "…" if left empty.
|
||||
Truncator string
|
||||
Truncator string
|
||||
// WrapPolicy configures how displayed text will be broken into lines.
|
||||
WrapPolicy text.WrapPolicy
|
||||
initialized bool
|
||||
source stringSource
|
||||
// scratch is a buffer reused to efficiently read text out of the
|
||||
@@ -182,6 +184,7 @@ func (l *Selectable) Layout(gtx layout.Context, lt *text.Shaper, font font.Font,
|
||||
l.text.Alignment = l.Alignment
|
||||
l.text.MaxLines = l.MaxLines
|
||||
l.text.Truncator = l.Truncator
|
||||
l.text.WrapPolicy = l.WrapPolicy
|
||||
l.text.Update(gtx, lt, font, size, l.handleEvents)
|
||||
dims := l.text.Dimensions()
|
||||
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
|
||||
|
||||
Reference in New Issue
Block a user