Added DisownAll method to Container

This commit is contained in:
Sasha Koshka 2023-01-10 18:07:51 -05:00
parent cb2136f7cb
commit b3e6beb8ad
2 changed files with 14 additions and 3 deletions

View File

@ -81,6 +81,19 @@ func (element *Container) Disown (child tomo.Element) {
}
}
// DisownAll removes all child elements from the container at once.
func (element *Container) DisownAll () {
element.children = nil
element.updateMinimumSize()
element.updateSelectable()
element.recalculate()
if element.core.HasImage() {
element.draw()
element.core.PushAll()
}
}
// Children returns a slice containing this element's children.
func (element *Container) Children () (children []tomo.Element) {
children = make([]tomo.Element, len(element.children))

View File

@ -20,9 +20,7 @@ func run () {
button := basic.NewButton("drawing pad")
okButton := basic.NewButton("OK")
button.OnClick (func () {
container.Disown(label)
container.Disown(button)
container.Disown(okButton)
container.DisownAll()
container.Adopt(basic.NewLabel("Draw here:"), false)
container.Adopt(basic.NewTest(), true)
container.Adopt(okButton, false)