Closed thomasbrook closed 5 years ago
You should change your OnClicked
handler to something like this:
...
OnClicked: func() {
childlist := mw.sv.Children()
if childlist != nil {
mw.sv.SetSuspended(true)
defer mw.sv.SetSuspended(false)
for i := childlist.Len() - 1; i >= 0; i-- {
childlist.At(i).Dispose()
}
fmt.Println("clear ok!")
}
loadChild(mw.sv)
return
},
...
WidgetList.Clear
only removes all widgets from a container, but does not dispose of them. Calling Dispose
on a widget on the other hand does both.
For best results you should always wrap operations that would trigger multiple layout updates in parent.SetSuspended(true); defer parent.SetSuspended(false)
.
In this way, I did not think of a specific scenario. But,WidgetList.Clear is not remove all widgets from a container.It may be a bug. As you loop through the list in the method onClearingWidgets of the file container.go,you also remove the control from the list in the method SetParent.
I'm not sure if I'm right.
Clearing children should be fixed by https://github.com/lxn/walk/commit/65fec213208b35277f369146b05d233ad1de6504.
After use parent.SetSuspended, usage experience is very fine.thanks.
At first, a control of type scrollview has six child control of type compose. the child control will be removed, when i click button named create.Then,i call Children().Clear(), new child control will be add to parent control.
Two child controls are not removed. Four child controls are not dispose.