mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +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:
+11
-8
@@ -28,6 +28,8 @@ type Label struct {
|
||||
// Truncator is the text that will be shown at the end of the final
|
||||
// line if MaxLines is exceeded. Defaults to "…" if empty.
|
||||
Truncator string
|
||||
// WrapPolicy configures how displayed text will be broken into lines.
|
||||
WrapPolicy text.WrapPolicy
|
||||
}
|
||||
|
||||
// Layout the label with the given shaper, font, size, text, and material.
|
||||
@@ -35,14 +37,15 @@ func (l Label) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size
|
||||
cs := gtx.Constraints
|
||||
textSize := fixed.I(gtx.Sp(size))
|
||||
lt.LayoutString(text.Parameters{
|
||||
Font: font,
|
||||
PxPerEm: textSize,
|
||||
MaxLines: l.MaxLines,
|
||||
Truncator: l.Truncator,
|
||||
Alignment: l.Alignment,
|
||||
MaxWidth: cs.Max.X,
|
||||
MinWidth: cs.Min.X,
|
||||
Locale: gtx.Locale,
|
||||
Font: font,
|
||||
PxPerEm: textSize,
|
||||
MaxLines: l.MaxLines,
|
||||
Truncator: l.Truncator,
|
||||
Alignment: l.Alignment,
|
||||
WrapPolicy: l.WrapPolicy,
|
||||
MaxWidth: cs.Max.X,
|
||||
MinWidth: cs.Min.X,
|
||||
Locale: gtx.Locale,
|
||||
}, txt)
|
||||
m := op.Record(gtx.Ops)
|
||||
viewport := image.Rectangle{Max: cs.Max}
|
||||
|
||||
Reference in New Issue
Block a user