From b3e6beb8ad36872f61aafc6e715ac554d07b95b9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 10 Jan 2023 18:07:51 -0500 Subject: [PATCH] Added DisownAll method to Container --- elements/basic/container.go | 13 +++++++++++++ examples/verticalLayout/main.go | 4 +--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/elements/basic/container.go b/elements/basic/container.go index 1e48bcf..dbd617e 100644 --- a/elements/basic/container.go +++ b/elements/basic/container.go @@ -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)) diff --git a/examples/verticalLayout/main.go b/examples/verticalLayout/main.go index 546013f..b111aac 100644 --- a/examples/verticalLayout/main.go +++ b/examples/verticalLayout/main.go @@ -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)