mirror of https://github.com/buggins/dlangui.git
Merge pull request #335 from and3md/queue_widget_destroy
Queue widget destroy support
This commit is contained in:
commit
7cad291103
|
@ -1649,6 +1649,25 @@ class RunnableEvent : CustomEvent {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Queue destroy event.
|
||||
|
||||
This event allows delayed widget destruction and is used internally by
|
||||
$(LINK2 $(DDOX_ROOT_DIR)dlangui/platforms/common/platform/Window.queueWidgetDestroy.html, Window.queueWidgetDestroy()).
|
||||
*/
|
||||
class QueueDestroyEvent : RunnableEvent {
|
||||
private Widget _widgetToDestroy;
|
||||
this (Widget widgetToDestroy)
|
||||
{
|
||||
_widgetToDestroy = widgetToDestroy;
|
||||
super(1,null, delegate void () {
|
||||
if (_widgetToDestroy.parent)
|
||||
_widgetToDestroy.parent.removeChild(_widgetToDestroy);
|
||||
destroy(_widgetToDestroy);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
interface CustomEventTarget {
|
||||
/// post event to handle in UI thread (this method can be used from background thread)
|
||||
void postEvent(CustomEvent event);
|
||||
|
|
|
@ -519,7 +519,24 @@ class Window : CustomEventTarget {
|
|||
destroy(_timerQueue);
|
||||
_eventList = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Allows queue destroy of widget.
|
||||
|
||||
Sometimes when you have very complicated UI with dynamic create/destroy lists of widgets calling simple destroy()
|
||||
on widget makes segmentation fault.
|
||||
|
||||
Usually because you destroy widget that on some stage call another that tries to destroy widget that calls it.
|
||||
When the control flow returns widget not exist and you have seg. fault.
|
||||
|
||||
This function use internally $(LINK2 $(DDOX_ROOT_DIR)dlangui/core/events/QueueDestroyEvent.html, QueueDestroyEvent).
|
||||
*/
|
||||
void queueWidgetDestroy(Widget widgetToDestroy)
|
||||
{
|
||||
QueueDestroyEvent ev = new QueueDestroyEvent(widgetToDestroy);
|
||||
postEvent(ev);
|
||||
}
|
||||
|
||||
private void animate(Widget root, long interval) {
|
||||
if (root is null)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue