Labels may request an expanding height change

This commit is contained in:
2023-01-16 18:04:41 -05:00
parent 7754679710
commit d9281b139f
7 changed files with 71 additions and 18 deletions

View File

@@ -27,6 +27,7 @@ func NewLabel (text string, wrap bool) (element *Label) {
return
}
// Resize resizes the label and re-wraps the text if wrapping is enabled.
func (element *Label) Resize (width, height int) {
element.core.AllocateCanvas(width, height)
if element.wrap {
@@ -37,6 +38,17 @@ func (element *Label) Resize (width, height int) {
return
}
// MinimumHeightFor returns the reccomended height for this element based on the
// given width in order to allow the text to wrap properly.
func (element *Label) MinimumHeightFor (width int) (height int) {
if element.wrap {
return element.drawer.ReccomendedHeightFor(width)
} else {
_, height = element.MinimumSize()
return
}
}
// SetText sets the label's text.
func (element *Label) SetText (text string) {
if element.text == text { return }
@@ -76,6 +88,7 @@ func (element *Label) updateMinimumSize () {
if em < 1 { em = theme.Padding() }
element.core.SetMinimumSize (
em, element.drawer.LineHeight().Round())
element.core.NotifyExpandingHeightChange()
} else {
bounds := element.drawer.LayoutBounds()
element.core.SetMinimumSize(bounds.Dx(), bounds.Dy())