Skip to content

Commit

Permalink
window may not be "ready" when adding events: defer them
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jan 18, 2024
1 parent 830aefa commit 27ace0f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions haxe/ui/backend/ScreenImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,39 @@ class ScreenImpl extends ScreenBase {
return EventMapper.HAXEUI_TO_HEAPS.get(type) != null;
}

private var _deferredEvents:Array<{type:String, listener:UIEvent->Void}> = null;
private function mapDeferredEvents() {
if (hxd.Window.getInstance() == null) {
return;
}

if (_deferredEvents == null) {
return;
}

while (_deferredEvents.length > 0) {
var info = _deferredEvents.shift();
mapEvent(info.type, info.listener);
if (_deferredEvents == null) {
break;
}
}
_deferredEvents = null;
}

private override function mapEvent(type:String, listener:UIEvent->Void) {
if (hxd.Window.getInstance() == null) {
if (_deferredEvents == null) {
_deferredEvents = [];
}
_deferredEvents.push({
type: type,
listener: listener
});
return;
}
mapDeferredEvents();

switch (type) {
case MouseEvent.MOUSE_MOVE:
if (_mapping.exists(type) == false) {
Expand Down

0 comments on commit 27ace0f

Please sign in to comment.