Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ jsimgui Public
forked from mori2003/jsimgui

JavaScript bindings for Dear ImGui

License

ar065/jsimgui

 
 

Repository files navigation

jsimgui: JavaScript bindings for Dear ImGui

JavaScript bindings for the Dear ImGui library, using the docking branch.

Currently only compatible with WebGL2. Built with: Dear ImGui, Dear Bindings, Deno and Emscripten.

Todo

The library is currently in a very early stage but core functionality is there. Expect many bugs and missing features!

Currently missing but planned:

  • Clipboard support
  • Image and ImageButton
  • Custom fonts
  • Saving ImGui settings
  • WebGPU backend

Examples

  • WebGL2: Basic example using a WebGL2 clear canvas - View Example
  • Three.js: Integration with Three.js WebGL2 renderer - View Example

Getting Started

The package is available on the JSR package registry. Use it with your favorite package manager (See: https://jsr.io/docs/using-packages).

# Deno
deno add jsr:@mori2003/jsimgui

# Node.js
npx jsr add @mori2003/jsimgui

# Bun
bunx jsr add @mori2003/jsimgui

Integrate it into your project.

import { ImGui, ImGuiImplWeb } from "@mori2003/jsimgui";

const canvas = document.querySelector("#your-canvas");
await ImGuiImplWeb.Init(canvas);

function frame() {
    ImGuiImplWeb.BeginRender();

    ImGui.Begin("New Window");
    ImGui.Text("Hello from JS!");
    ImGui.End();

    // Render your scene...

    ImGuiImplWeb.EndRender();
    requestAnimationFrame(frame);
}
requestAnimationFrame(frame);

API Notes

Arrays

Arrays are modified in-place when passed as arguments. Single-sized arrays are also used for references:

const color = [0.2, 0.8, 0.5];
ImGui.ColorEdit3("BackgroundColor", color); // Modifies the color array.
const isVisible = [true];
ImGui.Checkbox("Show Window", isVisible); // Modifies isVisible[0].

Enums

Enums names have been shortened and are accessed through the ImEnum object:

ImGui.SetNextWindowPos(new ImVec2(10, 10), ImEnum.Cond.Once);

Building

Prerequisites:

  1. Clone the repository
git clone https://github.com/mori2003/jsimgui.git
cd jsimgui
  1. Generate the dear_bindings data
deno task build:gen-data
  1. Build the project
deno task build:full

Project Structure

build/        # Distribution files
examples/     # Usage examples
intermediate/ # Generated C++ binding files
nix/          # Nix development shell
src/          # API generator source code
third_party/  # Dependencies (imgui, dear_bindings)

About

JavaScript bindings for Dear ImGui

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.5%
  • C++ 17.3%
  • Nix 0.2%