widget{,/material}: surface line height manipulation

This commit surfaces fields to manipulate the line height of all label and editor
types. It's unfortunate how this spreads through the API, but I don't see a good
way to eliminate that right now.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2023-07-18 16:26:45 -04:00
committed by Elias Naur
parent acab582487
commit ddf770b9d5
6 changed files with 81 additions and 19 deletions
+11 -3
View File
@@ -59,9 +59,15 @@ type Selectable struct {
// if text was cut off. Defaults to "…" if left empty.
Truncator string
// WrapPolicy configures how displayed text will be broken into lines.
WrapPolicy text.WrapPolicy
initialized bool
source stringSource
WrapPolicy text.WrapPolicy
// LineHeight controls the distance between the baselines of lines of text.
// If zero, a sensible default will be used.
LineHeight unit.Sp
// LineHeightScale applies a scaling factor to the LineHeight. If zero, a
// sensible default will be used.
LineHeightScale float32
initialized bool
source stringSource
// scratch is a buffer reused to efficiently read text out of the
// textView.
scratch []byte
@@ -181,6 +187,8 @@ func (l *Selectable) Truncated() bool {
// paint material for the text and selection rectangles, respectively.
func (l *Selectable) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectionMaterial op.CallOp) layout.Dimensions {
l.initialize()
l.text.LineHeight = l.LineHeight
l.text.LineHeightScale = l.LineHeightScale
l.text.Alignment = l.Alignment
l.text.MaxLines = l.MaxLines
l.text.Truncator = l.Truncator