Port of imgui for JS (based off of https://github.com/flyover/imgui-js), with my fixes

@Mark Mark authored on 4 Oct 2019
dist add imgui_demo.umd.js 5 years ago
example update dependencies and rebuild 5 years ago
imgui Move to my private fork of imgui, and update the .gitignore 5 years ago
.gitignore Move to my private fork of imgui, and update the .gitignore 5 years ago
.gitmodules Move to my private fork of imgui, and update the .gitignore 5 years ago
LICENSE.txt import project 7 years ago
Makefile add BINARYEN_TRAP_MODE="clamp" 5 years ago
README.md Improve instructions 5 years ago
bind-imgui.cpp Fix missing reference to deprecated TreeAdvanceToLabelPos 5 years ago
bind-imgui.d.ts Hook up the function arguments to ImGuiContext that allow us to share texture atlases, and make the textureById cache global, se we share those font textures across contexts. 5 years ago
bind-imgui.js Latest built files 5 years ago
emscripten.d.ts a modularized emscripten module does not return a promise 5 years ago
imconfig.js update imgui to v1.62 tag 6 years ago
imconfig.ts update imgui to v1.62 tag 6 years ago
imgui.js Latest built files 5 years ago
imgui.ts Hook up the function arguments to ImGuiContext that allow us to share texture atlases, and make the textureById cache global, se we share those font textures across contexts. 5 years ago
imgui_demo.js add backend checker window to demo 5 years ago
imgui_demo.ts add backend checker window to demo 5 years ago
imgui_memory_editor.js v1.63 6 years ago
imgui_memory_editor.ts v1.63 6 years ago
package.json update dependencies and rebuild 5 years ago
rollup.config.js add imgui_demo.umd.js 5 years ago
tsconfig.json Manually specify libs, so we don't get the iterable dom which causes problems with webgl2 declarations 5 years ago
README.md

imgui-js

JavaScript bindings for Dear ImGui using Emscripten and TypeScript

Example

ImGui JavaScript+WebGL example

The original Dear ImGui demo code from imgui_demo.cpp has been ported to imgui_demo.ts. Also, the Memory Editor from the imgui_club project (imgui_memory_editor.h) has been ported to imgui_memory_editor.ts and added to the demo for browsing the Emscripten memory space.

ImGui JavaScript Sandbox

A CodePen using the Ace editor to live-edit a window.

ImGui JavaScript+Three.js example

A CodePen using Dear ImGui with Three.js.

Support

If you find this useful, please consider donating to this and the Dear ImGui project. I can also invoice for private support, custom development, etc.

PayPal donate button

Notes

All functions in the C++ ImGui namespace are exported at the top level of the module.

import * as ImGui from "imgui-js";

Individual exports can be imported as well.

import { ImVec2 } from "imgui-js";

In general, functions that take an address of a variable in C++ have been changed to take an access function in JavaScript. Calling the access function with no arguments returns the variable, calling with a value sets the variable.

type ImAccess<T> = (value?: T) => T;

let show: boolean = true;

const _show: ImAccess<boolean> = (_: boolean = show): boolean => show = _;

// get the value of show
console.log(_show()); // true

// set the value of show to false (also returns the updated value)
console.log(_show(false)); // false

In the following example, the address of show in the C++ code has been replaced with an inline arrow access function.

#include "imgui.h"
bool show = true;
void draw() {
    if (ImGui::Button("Toggle")) { show = !show; }
    if (show) {
        ImGui::Begin("My Window", &show, ImGuiWindowFlags_AlwaysAutoResize));
        ImGui::Text("Hello, World!");
        ImGui::End();
    }
}
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();
    }
}

Enumerations that begin with ImGui* are also exported with ImGui removed. So the following examples are equivalent.

import * as ImGui from "imgui-js";
const flags: ImGui.WindowFlags = ImGui.WindowFlags.AlwaysAutoResize;
import { ImGuiWindowFlags } from "imgui-js";
const flags: ImGuiWindowFlags = ImGuiWindowFlags.AlwaysAutoResize;

In order to minimize size of the output, the C++ library has been compiled with IMGUI_DISABLE_OBSOLETE_FUNCTIONS and IMGUI_DISABLE_DEMO_WINDOWS.

Building

  • git clone git@github.com:flyover/imgui-js.git
  • cd imgui-js
  • git submodule update --init --recursive
  • download and install Emscripten
  • npm install
  • make
  • make start-example-html

TODO

  • file I/O, imgui.ini, loading external fonts
  • implement ImGuiTextFilter (add support for JavaScript RegExp's)
  • implement ImGuiTextBuffer (simplify to array of strings)
  • fill in remainder of any missing API
  • automate the Emscripten install and environment setup in npm install

License

imgui-js is licensed under the MIT License, see LICENSE for more information.