mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
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:
@@ -16,8 +16,14 @@ import (
|
||||
)
|
||||
|
||||
type EditorStyle struct {
|
||||
Font font.Font
|
||||
TextSize unit.Sp
|
||||
Font font.Font
|
||||
// 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
|
||||
TextSize unit.Sp
|
||||
// Color is the text color.
|
||||
Color color.NRGBA
|
||||
// Hint contains the text displayed when the editor is empty.
|
||||
@@ -64,7 +70,12 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
}
|
||||
|
||||
macro := op.Record(gtx.Ops)
|
||||
tl := widget.Label{Alignment: e.Editor.Alignment, MaxLines: maxlines}
|
||||
tl := widget.Label{
|
||||
Alignment: e.Editor.Alignment,
|
||||
MaxLines: maxlines,
|
||||
LineHeight: e.LineHeight,
|
||||
LineHeightScale: e.LineHeightScale,
|
||||
}
|
||||
dims := tl.Layout(gtx, e.shaper, e.Font, e.TextSize, e.Hint, hintColor)
|
||||
call := macro.Stop()
|
||||
|
||||
@@ -74,6 +85,8 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
if h := dims.Size.Y; gtx.Constraints.Min.Y < h {
|
||||
gtx.Constraints.Min.Y = h
|
||||
}
|
||||
e.Editor.LineHeight = e.LineHeight
|
||||
e.Editor.LineHeightScale = e.LineHeightScale
|
||||
dims = e.Editor.Layout(gtx, e.shaper, e.Font, e.TextSize, textColor, selectionColor)
|
||||
if e.Editor.Len() == 0 {
|
||||
call.Add(gtx.Ops)
|
||||
|
||||
Reference in New Issue
Block a user