Skip to content

Commit

Permalink
feat(examples): update imgui demo
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 16, 2019
1 parent c9bc287 commit bded179
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/imgui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const app = () => {
};

// main GUI update function
const updateGUI = () => {
const updateGUI = (draw: boolean) => {
// obtain atom value
const state = DB.deref();
// setup initial layout (single column)
Expand All @@ -200,7 +200,7 @@ const app = () => {
gui.setTheme(themeForID(state.theme));

// start frame
gui.begin();
gui.begin(draw);

// disable all GUI components if radial menu is active
gui.beginDisabled(radialActive);
Expand Down Expand Up @@ -371,7 +371,7 @@ const app = () => {
}
// menu backdrop
gui.add(
gui.resource("radial", "grad" + hash(radialPos), ()=>
gui.resource("radial", hash(radialPos) + 1, ()=>
["g",{},
["radialGradient",
{ id: "shadow", from: radialPos, to: radialPos, r1: 5, r2: 300},
Expand Down Expand Up @@ -432,8 +432,18 @@ const app = () => {
// call updateGUI twice to compensate for lack of regular 60fps update
// Note: Unless your GUI is super complex, this cost is pretty neglible
// and no actual drawing takes place here ...
const t = <number>bench(timedResult(() => { updateGUI(); updateGUI(); })[1]);

// the `timedResult` function measures execution time and returns tuple
// of [result, time]. We then pass the time taken to our SMA transducer
// to update and return a moving average.
const t = <number>bench(
timedResult(() => {
updateGUI(false);
updateGUI(true);
}
)[1]);
// since the MA will only be available after the configured period,
// we will only display stats when they're ready...
t != null && gui.add(textLabelRaw([10, height - 10 - 4 * 14], "#ff0", `GUI time: ${F2(t)}ms`));
// return hdom-canvas component with embedded GUI
return [
Expand Down

0 comments on commit bded179

Please sign in to comment.