#283: Prevent artist bio from overflowing header space

This commit is contained in:
Drew Weymouth
2023-11-22 12:28:18 -06:00
parent 2946fa50a1
commit 6445320cb5
3 changed files with 46 additions and 17 deletions
+36
View File
@@ -0,0 +1,36 @@
package widgets
import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
type MaxRowsLabel struct {
widget.Label
maxHeight float32
}
func NewMaxRowsLabel(maxRows int, text string) *MaxRowsLabel {
if maxRows < 1 {
maxRows = 1
}
m := &MaxRowsLabel{
Label: widget.Label{
Text: text,
},
}
m.ExtendBaseWidget(m)
maxHeightText := strings.Repeat("W\n", maxRows)
maxHeightText = maxHeightText[:len(maxHeightText)-1]
m.maxHeight = widget.NewLabel(maxHeightText).MinSize().Height
return m
}
func (m *MaxRowsLabel) MinSize() fyne.Size {
return fyne.NewSize(m.Label.MinSize().Width, m.maxHeight)
}