Skip to content

Commit

Permalink
_allowDispose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jun 27, 2024
1 parent 86ec829 commit b07b571
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions haxe/ui/backend/DialogBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions haxe/ui/core/Component.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions haxe/ui/core/Screen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b07b571

Please sign in to comment.