mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
ui/text: add Label.MaxLines
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -19,6 +19,7 @@ type Label struct {
|
|||||||
Face Face
|
Face Face
|
||||||
Alignment Alignment
|
Alignment Alignment
|
||||||
Text string
|
Text string
|
||||||
|
MaxLines int
|
||||||
|
|
||||||
it lineIterator
|
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 {
|
func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
textLayout := l.Face.Layout(l.Text, false, cs.Width.Max)
|
textLayout := l.Face.Layout(l.Text, false, cs.Width.Max)
|
||||||
lines := textLayout.Lines
|
lines := textLayout.Lines
|
||||||
|
if max := l.MaxLines; max > 0 && len(lines) > max {
|
||||||
|
lines = lines[:max]
|
||||||
|
}
|
||||||
dims := linesDimens(lines)
|
dims := linesDimens(lines)
|
||||||
dims.Size = cs.Constrain(dims.Size)
|
dims.Size = cs.Constrain(dims.Size)
|
||||||
padTop, padBottom := textPadding(lines)
|
padTop, padBottom := textPadding(lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user