From f1f477491492dfc243a715c2c02c59247714d9bf Mon Sep 17 00:00:00 2001 From: p1gd0g Date: Thu, 28 Mar 2019 21:50:21 +0800 Subject: [PATCH] Add a new method for Box to clear a Box. --- box.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/box.go b/box.go index 99be5cb..93a02c4 100644 --- a/box.go +++ b/box.go @@ -19,8 +19,8 @@ import "C" // There can also be space between each control ("padding"). type Box struct { ControlBase - b *C.uiBox - children []Control + b *C.uiBox + children []Control } // NewHorizontalBox creates a new horizontal Box. @@ -67,7 +67,7 @@ func (b *Box) Append(child Control, stretchy bool) { // Delete deletes the nth control of the Box. func (b *Box) Delete(n int) { - b.children = append(b.children[:n], b.children[n + 1:]...) + b.children = append(b.children[:n], b.children[n+1:]...) C.uiBoxDelete(b.b, C.int(n)) } @@ -83,3 +83,11 @@ func (b *Box) Padded() bool { func (b *Box) SetPadded(padded bool) { C.uiBoxSetPadded(b.b, frombool(padded)) } + +// Clear clears the children of the Box. +func (b *Box) Clear() { + n := len(b.children) + for index := 0; index < n; index++ { + b.Delete(0) + } +}