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
+14
View File
@@ -44,6 +44,12 @@ type textSource interface {
// be scrolled, and for configuring and drawing text selection boxes.
type textView struct {
Alignment text.Alignment
// 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
// SingleLine forces the text to stay on a single line.
// SingleLine also sets the scrolling direction to
// horizontal.
@@ -273,6 +279,14 @@ func (e *textView) Update(gtx layout.Context, lt *text.Shaper, font font.Font, s
e.params.WrapPolicy = e.WrapPolicy
e.invalidate()
}
if lh := fixed.I(gtx.Sp(e.LineHeight)); lh != e.params.LineHeight {
e.params.LineHeight = lh
e.invalidate()
}
if e.LineHeightScale != e.params.LineHeightScale {
e.params.LineHeightScale = e.LineHeightScale
e.invalidate()
}
e.makeValid()
if eventHandling != nil {