Merge pull request #335 from and3md/queue_widget_destroy

Queue widget destroy support
This commit is contained in:
Vadim Lopatin 2017-04-11 10:18:29 +03:00 committed by GitHub
commit 7cad291103
2 changed files with 37 additions and 1 deletions

View File

@ -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 { interface CustomEventTarget {
/// post event to handle in UI thread (this method can be used from background thread) /// post event to handle in UI thread (this method can be used from background thread)
void postEvent(CustomEvent event); void postEvent(CustomEvent event);

View File

@ -520,6 +520,23 @@ class Window : CustomEventTarget {
_eventList = null; _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) { private void animate(Widget root, long interval) {
if (root is null) if (root is null)
return; return;