diff --git a/haxe/ui/backend/DialogBase.hx b/haxe/ui/backend/DialogBase.hx index 4eb899ff3..d6413af8d 100644 --- a/haxe/ui/backend/DialogBase.hx +++ b/haxe/ui/backend/DialogBase.hx @@ -29,8 +29,6 @@ class DialogBase extends Box implements Draggable { public var dialogFooterContainer:haxe.ui.containers.Box; public var dialogFooter:haxe.ui.containers.HBox; - public var destroyOnClose:Bool = true; - public function new() { super(); @@ -88,6 +86,17 @@ class DialogBase extends Box implements Draggable { registerEvent(UIEvent.SUBMIT, onSubmit); } + private var _destroyOnClose:Bool = true; + public var destroyOnClose(get, set):Bool; + private function get_destroyOnClose():Bool { + return _destroyOnClose; + } + private function set_destroyOnClose(value:Bool) { + _destroyOnClose = value; + _allowDispose = value; + return value; + } + private function onSubmit(event:UIEvent) { if (defaultButton != null) { hideDialog(defaultButton); diff --git a/haxe/ui/core/Component.hx b/haxe/ui/core/Component.hx index a4d504214..2ebf97704 100644 --- a/haxe/ui/core/Component.hx +++ b/haxe/ui/core/Component.hx @@ -534,6 +534,16 @@ class Component extends ComponentImpl return child; } + // this specifies if the component is allowed to be disposed or not, it mainly comes in useful + // for things like haxeui-flixel that imposes states (and state switches) that have to be + // managed by haxeui's "screen" - this can mean when a state switch occurs it will try to + // dispose of all objects, which usually is fine, but in some cases its not what is wanted + // for example: Dialog.destroyOnClose = false. Although quite flixel specific, there may be use for + // it in other, new, backends at some point (though currently no other backends have "states", so + // its not needed) + @:noCompletion + private var _allowDispose:Bool = true; + /** * Removes this component from memory. * diff --git a/haxe/ui/core/Screen.hx b/haxe/ui/core/Screen.hx index d80e30fa6..4d0a79c95 100644 --- a/haxe/ui/core/Screen.hx +++ b/haxe/ui/core/Screen.hx @@ -107,6 +107,10 @@ class Screen extends ScreenImpl { * @return The added component. */ public override function removeComponent(component:Component, dispose:Bool = true, invalidate:Bool = true):Component { + if (@:privateAccess !component._allowDispose) { + dispose = false; + } + if (rootComponents.indexOf(component) == -1) { if (dispose) { component.disposeComponent();