Labels may request an expanding height change
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -144,6 +144,12 @@ func (control CoreControl) SetMinimumSize (width, height int) {
|
||||
}
|
||||
}
|
||||
|
||||
// NotifyExpandingHeightChange notifies the parent element that this element's
|
||||
// expanding height has changed.
|
||||
func (control CoreControl) NotifyExpandingHeightChange () {
|
||||
control.core.hooks.RunExpandingHeightChange()
|
||||
}
|
||||
|
||||
// ConstrainSize contstrains the specified width and height to the minimum width
|
||||
// and height, and returns wether or not anything ended up being constrained.
|
||||
func (control CoreControl) ConstrainSize (
|
||||
|
||||
Reference in New Issue
Block a user