~eliasnaur/gio

28f53d8708c5456efef3f51e886af0d564c31cef — Elias Naur 2 years ago 3092a72
ui/text: add Label.MaxLines

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 4 insertions(+), 0 deletions(-)

M ui/text/label.go
M ui/text/label.go => ui/text/label.go +4 -0
@@ 19,6 19,7 @@ type Label struct {
	Face      Face
	Alignment Alignment
	Text      string
	MaxLines  int

	it lineIterator
}


@@ 82,6 83,9 @@ func (l *lineIterator) Next() (String, f32.Point, bool) {
func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
	textLayout := l.Face.Layout(l.Text, false, cs.Width.Max)
	lines := textLayout.Lines
	if max := l.MaxLines; max > 0 && len(lines) > max {
		lines = lines[:max]
	}
	dims := linesDimens(lines)
	dims.Size = cs.Constrain(dims.Size)
	padTop, padBottom := textPadding(lines)