ui/text: add Label.MaxLines

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-30 23:51:11 +02:00
parent 3092a72089
commit 28f53d8708
+4
View File
@@ -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)