Skip to content

Commit

Permalink
Resize the debug watch window whenever something gets added / removed (
Browse files Browse the repository at this point in the history
…#3251)

* Resize the watch window whenever something gets added / removed

* reposition window after it resizes, incase we are out of bounds

* fix CI

* remove reposition

* add reposition back

---------

Co-authored-by: George FunBook <[email protected]>
  • Loading branch information
ninjamuffin99 and Geokureli committed Sep 24, 2024
1 parent 4b05488 commit a7b8d9c
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions flixel/system/debug/watch/Watch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Watch extends Window
entriesContainer.y = entriesContainerOffset.y;
addChild(entriesContainer);

FlxG.signals.preStateSwitch.add(removeAll);
FlxG.signals.preStateSwitch.add(clear);
}

public function add(displayName:String, data:WatchEntryData):Void
Expand Down Expand Up @@ -87,7 +87,7 @@ class Watch extends Window
var entry = new WatchEntry(displayName, data, removeEntry);
entries.push(entry);
entriesContainer.addChild(entry);
resetEntries();
updateSize();
}

public function remove(displayName:String, data:WatchEntryData):Void
Expand All @@ -102,19 +102,27 @@ class Watch extends Window
entries.fastSplice(entry);
entriesContainer.removeChild(entry);
entry.destroy();
resetEntries();
updateSize();
}

public function removeAll():Void
/**
* internal method to remove all without calling updateSize
*/
function clear():Void
{
for (i in 0...entries.length)
for (entry in entries)
{
var entry = entries[i];
entriesContainer.removeChild(entry);
entry.destroy();
}
entries.splice(0, entries.length);
resetEntries();

entries.resize(0);
}

public function removeAll():Void
{
clear();
updateSize();
}

override public function update():Void
Expand All @@ -125,9 +133,10 @@ class Watch extends Window

override function updateSize():Void
{
resetEntries();
minSize.setTo(getMaxMinWidth() + entriesContainerOffset.x, entriesContainer.height + entriesContainerOffset.y);
super.updateSize();
resetEntries();
reposition(x, y);
}

function resetEntries():Void
Expand Down

0 comments on commit a7b8d9c

Please sign in to comment.