flyover / imgui-js

JavaScript bindings for Dear ImGui using Emscripten and TypeScript
https://flyover.github.io/imgui-js/example/
MIT License
915 stars 98 forks source link

run native imgui window from node #49

Open LuisMerinoP opened 2 years ago

LuisMerinoP commented 2 years ago

Hello, Not an issue but a question. Sorry I am not very familiar with node.

Built and ran the project example and everything works fine. I run the node example with: npm run-cript start-example-node and the script runs but nothing is drawn (there are logs in the terminal). I expect a native imgui window drawn form node script call.

I would like to run the example

import * as ImGui from "imgui-js";
let show: boolean = true;
function draw(): void {
    if (ImGui.Button("Toggle")) { show = !show; }
    if (show) {
        ImGui.Begin("My Window", (_ = show) => show = _, ImGui.WindowFlags.AlwaysAutoResize));
        ImGui.Text("Hello, World!");
        ImGui.End();
    }
}

from node.

Is this possible? Is there anything that needs to be done in the example/index.js script? Thanks in advanced.

Edit1: There is an error Cannot find name 'System'.ts(2304) error obtained at System.import("main") in the index.js script. Node version: v17.5.0 Edit2: Seems that window is undefined at the main.ts render loop:

if (typeof(window) !== "undefined") {
        window.requestAnimationFrame(done ? _done : _loop);
}

Which makes sense if method is being called from node and node within the browser. However what is the purpose of the node example then?