Skip to content

Commit

Permalink
refactor(imgui): minor updates IMGUI class
Browse files Browse the repository at this point in the history
- extract gc() method
- update endTheme()/endDisabled()
  • Loading branch information
postspectacular committed Sep 19, 2020
1 parent 69332d9 commit aec84c6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/imgui/src/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export class IMGUI implements IClear, IToHiccup {
* Removes current theme from stack (unless only one theme left).
*/
endTheme() {
const stack = this.themeStack;
stack.length > 1 && stack.pop();
popIfNotLast(this.themeStack);
}

/**
Expand Down Expand Up @@ -178,8 +177,7 @@ export class IMGUI implements IClear, IToHiccup {
* Removes current disabled flag from stack (unless only one theme left).
*/
endDisabled() {
const stack = this.disabledStack;
stack.length > 1 && stack.pop();
popIfNotLast(this.disabledStack);
}

/**
Expand Down Expand Up @@ -313,7 +311,13 @@ export class IMGUI implements IClear, IToHiccup {
}
this.key === Key.TAB && (this.focusID = "");
this.key = "";
// garbage collect unused component state / resources
this.gc();
}

/**
* Garbage collect unused component state / resources.
*/
gc() {
const prev = this.prevIDs;
const curr = this.currIDs;
for (let id of prev) {
Expand Down Expand Up @@ -461,3 +465,5 @@ export class IMGUI implements IClear, IToHiccup {
];
}
}

const popIfNotLast = (stack: any[]) => stack.length > 1 && stack.pop();

0 comments on commit aec84c6

Please sign in to comment.