mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
text: simplify text layout and shaping API
First, replace LayoutOptions with an explicit maximum width parameter. The single-field option struct doesn't carry its weight, and I don't think we'll see more global layout options in the future. Rather, I expect options to cover spans of text or be part of a Font. Second, replace the unit.Converter with an scaled text size. It's simpler and allow the Editor and similar widgets to easily detect whether their cached layouts are stale. Package text no longer depends on package unit, which is now dealt with at the widget-level only. Finally, remove the Size field from Font. It was a design mistake: a Font is assumed to cover all sizes, as evidenced by the FontRegistry disregarding Size when looking up fonts. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -22,6 +22,7 @@ type Label struct {
|
||||
// MaxLines limits the number of lines. Zero means no limit.
|
||||
MaxLines int
|
||||
Text string
|
||||
TextSize unit.Value
|
||||
|
||||
shaper text.Shaper
|
||||
}
|
||||
@@ -64,17 +65,15 @@ func (t *Theme) Caption(txt string) Label {
|
||||
|
||||
func (t *Theme) Label(size unit.Value, txt string) Label {
|
||||
return Label{
|
||||
Text: txt,
|
||||
Color: t.Color.Text,
|
||||
Font: text.Font{
|
||||
Size: size,
|
||||
},
|
||||
shaper: t.Shaper,
|
||||
Text: txt,
|
||||
Color: t.Color.Text,
|
||||
TextSize: size,
|
||||
shaper: t.Shaper,
|
||||
}
|
||||
}
|
||||
|
||||
func (l Label) Layout(gtx *layout.Context) {
|
||||
paint.ColorOp{Color: l.Color}.Add(gtx.Ops)
|
||||
tl := widget.Label{Alignment: l.Alignment, MaxLines: l.MaxLines}
|
||||
tl.Layout(gtx, l.shaper, l.Font, l.Text)
|
||||
tl.Layout(gtx, l.shaper, l.Font, l.TextSize, l.Text)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user