Giter Club home page Giter Club logo

imgui-js's Introduction

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 [email protected]: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.

imgui-js's People

Contributors

arthuro555 avatar chohner avatar flyover avatar luney112 avatar sh54 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgui-js's Issues

use AddFontFromFileTTF with io.Fonts.GetGlyphRangesChineseFull will crash

console Uncaught (in promise) abort(OOM). Build with -s ASSERTIONS=1 for more info.

I used a cropped droidsansfallback.ttf
This file contains 2500 commonly used Chinese characters
but

I cropped the font file again, and this time it worked when the file contained only 500 commonly used Chinese characters
I think it was a memory burst while creating font data.
What is the solution?
You can clone my git repository :https://gitee.com/AIGAMESTUDIO.AILHC/imgui-js
change example/main.js to check

export_Color4 does not take into account alpha

I noticed the color edit and color picker are not working properly for alpha channel. After exploring a bit I found the issue, the 4th channel is missing on the export function export_Color4(tuple, col) and after adding it works! :D

function export_Color4(tuple, col) {
if (Array.isArray(col)) {
col[0] = tuple[0];
col[1] = tuple[1];
col[2] = tuple[2];
col[3] = tuple[3];
return;
}
if ("r" in col) {
col.r = tuple[0];
col.g = tuple[1];
col.b = tuple[2];
col.a = tuple[3];
return;
}
col.x = tuple[0];
col.y = tuple[1];
col.z = tuple[2];
col.w = tuple[3];
}

High DPI (HiDPI) canvas support

Impressive work! However, it looks blurry on a 4k screen. I think this may be related to #14 and could resolve it.
https://www.html5rocks.com/en/tutorials/canvas/hidpi/

I had this issue with software I was working, and this is the simplest solution I ended up using.

this.canvas.width = e.width * window.devicePixelRatio;
this.canvas.height = e.height * window.devicePixelRatio;
this.canvas.getContext("2d").setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0);

Essentially, you render it in the canvas at double resolution (using a transform, double the size of the document element) and scale the document element down to the desired size.

Or even easier, you can just include a polyfill like this one:
https://github.com/jondavidjohn/hidpi-canvas-polyfill

Canvas Fallback Support

How hard would it be to implement fallback on Context-2D with the way the code is now? Is there a way to get ImGui raw buffer without relying on GL ?

Building failure

(master) ~/youidev/imgui-js $ make
npm run start-example-node

[email protected] start-example-node /Users/developer/youidev/imgui-js
node example/index.js

Total allocated space (uordblks) @ _init: 6528
ReferenceError: HTMLCanvasElement is not defined
at Object.Init (file:///Users/developer/youidev/imgui-js/example/imgui_impl.js:177:31)
at file:///Users/developer/youidev/imgui-js/example/main.js:88:28
at Generator.next ()
at fulfilled (file:///Users/developer/youidev/imgui-js/example/main.js:5:62)
at processTicksAndRejections (internal/process/next_tick.js:81:5)

Is it possible to forward or not clipboard events?

Currently, copy/cut/paste events works as expected within canvas, where ImGui is rendered.

But, this prevent any normal copy/cut/paste events outside the canvas. Is it possible to restore normal clipboard behaviors?
Use case would be to use normal clipboard behaviors when canvas is not focused, and forward it to ImGui only when canvas is focused.

Any ideas would be much appreciated.

Too small on HDPI macbook

The UI isn't scaling properly on mac with a hdpi screen when running any of the examples listed in the readme. This makes too hard to read or use properly.
Screenshot 2019-08-23 22 54 37

imgui_impl.umd.js's ImGui_Impl.Init crashes with null exception

I'm trying to use imgui-js within the PlayCanvas engine with the dist/umd version https://github.com/flyover/imgui-js/tree/master/dist

I'm hitting an error when I call ImGui_Impl.Init as bind is undefined. Looking at the file itself, I can't see where it is assigned a value as well.

Comparing it to example/imgui_impl.js, also notice some logic differences .

In the example/imgui_impl.js, the Init function looks like this:

    function Init(value) {
        const io = ImGui.GetIO();

Whereas, the UMD looks like this:

    function Init(value) {
        const io = GetIO();

Where GetIO is

    function GetIO() { return new ImGuiIO(bind.GetIO()); }

Am I doing something wrong in the setup or should I not use the dist/umd versions of the library?

make build-bind-imgui

PS C:\Users\Administrator\Desktop\imgui-js-master> make build-bind-imgui
emcc -Os -s NO_FILESYSTEM=1 -s MODULARIZE=1 -s EXPORT_BINDINGS=1 -s SINGLE_FILE=1 -s ALLOW_MEMORY_GROWTH=1 -s EMBIND_STD_STRING_IS_UTF8=1 -D "IM_ASSERT(EXPR)=((void)(EXPR))" -D IMGUI_DISABLE_OBSOLETE_FUNCTIONS -D IMGUI_DISABLE_DEMO_WINDOWS -I imgui -c imgui/imgui.cpp -o imgui/imgui.bc
Traceback (most recent call last):
File "C:/Users/Administrator/emsdk/upstream/emscripten/emcc.py", line 42, in
import emscripten
File "C:\Users\Administrator\emsdk\upstream\emscripten\emscripten.py", line 22, in
from tools import building
File "C:\Users\Administrator\emsdk\upstream\emscripten\tools\building.py", line 23, in
from . import shared
File "C:\Users\Administrator\emsdk\upstream\emscripten\tools\shared.py", line 1641, in
parse_config_file()
File "C:\Users\Administrator\emsdk\upstream\emscripten\tools\shared.py", line 340, in parse_config_file
config_text = open(CONFIG_FILE, 'r').read() if CONFIG_FILE else EM_CONFIG
PermissionError: [Errno 13] Permission denied: 'C:\Users\Administrator\emsdk\upstream\emscripten'
make: *** [imgui/imgui.bc] 错误 1
PS C:\Users\Administrator\Desktop\imgui-js-master>

Retina display on mac

On retina displays, the mouse coordinates do not line up with IMGUI coordinates.
Which makes it almost impossible to interact with the UI.
This might be an IMGUI issue or an IMGUI-JS issue. Not sure.

To reproduce this issue, move your Chrome browser to the high dpi mac display and hit refresh.
The UI will shrink down and moving the mouse around will highlight the wrong UI elements.

windows10 emcc build fail

[email protected] build E:\ImgGuiLearnSpace\imgui-js
make build-bind-imgui && npm run build-imgui

process_begin: CreateProcess(NULL, uname, ...) failed.
process_begin: CreateProcess(NULL, uname, ...) failed.
mkdir -p build/imgui
命令语法不正确。
make: *** [build/imgui/imgui.bc] 错误 1
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: make build-bind-imgui && npm run build-imgui
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

How to import imgui-js properly in a ReactJS project

I imported the package as instructed in the README.md file,

import * as ImGui from 'imgui-js';

but it gives the following error:

Cannot find module 'imgui-js' or its corresponding type declarations. ts(2307)

Intermittent problem

image
image

Sometimes the interface has problems (visible in the images), the color scheme starts screwed, the text is inverted, and sometimes imperceptible as if it assumed another font.
I'm using BabylonJS.

Any suggestion of the cause of this problem?

Build broken under windows and wsl

while following the build instructions. when running make the build errors with

npm run start-example-node

> [email protected] start-example-node /mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js
> node example/index.js

(node:13175) UnhandledPromiseRejectionWarning: ReferenceError: __dirname is not defined
    at ModuleNamespace.<anonymous> (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/bind-imgui.js:8:1038)
    at Promise (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/imgui.js:17:29)
    at new Promise (<anonymous>)
    at Object.<anonymous> (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/imgui.js:16:20)
    at Generator.next (<anonymous>)
    at file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/imgui.js:9:75
    at new Promise (<anonymous>)
    at __awaiter (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/imgui.js:5:16)
    at Object.default_1 [as default] (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/imgui.js:15:16)
    at ModuleNamespace.<anonymous> (file:///mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/example/main.js:22:32)
(node:13175) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:13175) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 

__dirname can be replaced by hand with process.cwd() which then reveals another error:

npm run start-example-node

> [email protected] start-example-node /mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js
> node example/index.js

{ ENOENT: no such file or directory, open '/mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/main.js'
  Instantiating /mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/main.js
  Loading ./main
  Error: ENOENT: no such file or directory, open '/mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/main.js'
  originalErr:
   { Error: ENOENT: no such file or directory, open '/mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/main.js'
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/mnt/c/Users/ehb56/OneDrive/Documents/GitHub/Timeline/imgui-js/main.js' } }```

ImGui.BeginMenuBar() not displaying

Hello guys,

I am trying to create a menubar on top of a window but no menu is displayed. I followed the example code in the Docs

ImGui.Begin("Debug");
    if ( ImGui.BeginMenuBar()) {
      if ( ImGui.BeginMenu("FIle")) {
          if (ImGui.Menuitem("Open..", "Ctrl+O")) { /* Do stuff */ }
          if (ImGui.Menuitem("Save", "Ctrl+S")) { /* Do stuff */ }
          if (ImGui.Menuitem("Close", "Ctrl+W")) { /* Do stuff */ }
          ImGui.EndMenu();
        }
      ImGui.EndMenuBar();
    }
    ImGui.End();

any help would be appreciated!

this.native.SelectAll is not a function

Had this error on the demo page recently. Not exactly sure what triggered since I had a load of different things running.

imgui.ts:1320 Uncaught TypeError: this.native.SelectAll is not a function
    at ImGuiInputTextCallbackData.SelectAll (imgui.ts:1320:44)
    at MyCallback (imgui_demo.ts:1333:34)
    at InputText._callback (imgui.ts:3566:97)
    at __emval_call (bind-imgui.js:9:663775)
    at 001bebea:0x123b1
    at 001bebea:0x45602
    at 001bebea:0x1bb65
    at 001bebea:0x15d5b
    at 001bebea:0x56eee
    at 001bebea:0x514ad

Camera rotates when using three.js OrbitControl

Hi there,
I setup imgui with the three.js FBX loader example.
Everything works fine, but when I drag a imgui window, the camera rotates as well.
I spend some time trying to figure out a workaround, but I'm curious if I'm missing the obvious.

Thanks in advance!

I tried to rebuild after enabling parameter ALLOW_MEMORY_GROWTH=1, but the build failed with the following error:

slicol@ubuntu:/imgui-js$ make build
mkdir -p build
emcc -Os -D "IM_ASSERT(EXPR)=((void)(EXPR))" -D IMGUI_DISABLE_OBSOLETE_FUNCTIONS -D IMGUI_DISABLE_DEMO_WINDOWS -I imgui -c src/bind-imgui.cpp -o build/bind-imgui.o
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImVec2 *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^

/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImVec2 *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImVec2 *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:499:9: note: in instantiation of function template specialization 'emscripten::val::val<const ImVec2 *&>' requested here
499 | CLASS_MEMBER_GET_RAW_REFERENCE(ImGuiSizeCallbackData, Pos)
| ^
src/bind-imgui.cpp:47:39: note: expanded from macro 'CLASS_MEMBER_GET_RAW_REFERENCE'
47 | auto p = &that.MEMBER; return emscripten::val(p);
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImGuiTableColumnSortSpecs *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImGuiTableColumnSortSpecs *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImGuiTableColumnSortSpecs *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:541:20: note: in instantiation of function template specialization 'emscripten::val::val<const ImGuiTableColumnSortSpecs *&>' requested here
541 | return emscripten::val(spec);
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImVec4 *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImVec4 *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImVec4 *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:555:9: note: in instantiation of function template specialization 'emscripten::val::val<const ImVec4 *&>' requested here
555 | CLASS_MEMBER_GET_RAW_REFERENCE(ImDrawCmd, ClipRect)
| ^
src/bind-imgui.cpp:47:39: note: expanded from macro 'CLASS_MEMBER_GET_RAW_REFERENCE'
47 | auto p = &that.MEMBER; return emscripten::val(p);
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImDrawCmd *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImDrawCmd *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImDrawCmd *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:567:26: note: in instantiation of function template specialization 'emscripten::val::val<const ImDrawCmd *&>' requested here
567 | callback(emscripten::val(pcmd), emscripten::val(ElemStart));
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImDrawList *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImDrawList *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImDrawList *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:815:26: note: in instantiation of function template specialization 'emscripten::val::val<const ImDrawList *&>' requested here
815 | callback(emscripten::val(cmd_list));
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImFontGlyph *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImFontGlyph *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImFontGlyph *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:945:9: note: in instantiation of function template specialization 'emscripten::val::val<const ImFontGlyph *&>' requested here
945 | CLASS_MEMBER_GET_SET_RAW_POINTER(ImFont, FallbackGlyph)
| ^
src/bind-imgui.cpp:40:76: note: expanded from macro 'CLASS_MEMBER_GET_SET_RAW_POINTER'
40 | auto p = that.MEMBER; return p == NULL ? emscripten::val::null() : emscripten::val(p);
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:226:20: error: assigning to 'void *' from 'const ImFontConfig *' discards qualifiers
226 | cursor->w[0].p = wt;
| ^~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImFontConfig *&>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImFontConfig *&>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:963:26: note: in instantiation of function template specialization 'emscripten::val::val<const ImFontConfig *&>' requested here
963 | callback(emscripten::val(cfg));
| ^
In file included from src/bind-imgui.cpp:14:
In file included from /home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:23:
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:239:20: error: static_cast from 'const ImVec2 *' to 'unsigned int' is not allowed
239 | cursor->w[0].u = static_cast(wt);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:248:3: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireType<const ImVec2 *>' requested here
248 | writeGenericWireType(cursor, BindingType::toWireType(std::forward(first)));
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:256:5: note: in instantiation of function template specialization 'emscripten::internal::writeGenericWireTypes<const ImVec2 *const &>' requested here
256 | writeGenericWireTypes(cursor, std::forward(args)...);
| ^
/home/slicol/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:389:21: note: in instantiation of member function 'emscripten::internal::WireTypePack<const ImVec2 *const &>::WireTypePack' requested here
389 | WireTypePack argv(std::forward(value));
| ^
src/bind-imgui.cpp:1533:70: note: in instantiation of function template specialization 'emscripten::val::val<const ImVec2 *const &>' requested here
1533 | const auto p = &that->MouseClickedPos[index]; return emscripten::val(p);
| ^
8 errors generated.
emcc: error: '/home/slicol/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/slicol/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -Os -D IM_ASSERT(EXPR)=((void)(EXPR)) -D IMGUI_DISABLE_OBSOLETE_FUNCTIONS -D IMGUI_DISABLE_DEMO_WINDOWS -Iimgui -c src/bind-imgui.cpp -o build/bind-imgui.o' failed (returned 1)
Makefile:88: recipe for target 'build/bind-imgui.o' failed
make: *** [build/bind-imgui.o] Error 1

"npm install" step fails

Hi Flyover.
I'm having issues following the building steps, specially the "npm install" part.
I have already run "sudo npm install -g npm@latest" to see if it might fix it.
I don't know if had anything todo with me updating the pacage.json to the following ( because it was giving me errors saying that rollup version that is now in the repository is depracated ):

package.json:

{
  "name": "imgui-js",
  "version": "1.0.0",
  "description": "JavaScript bindings for Dear ImGui using Emscripten and TypeScript",
  "main": "imgui.js",
  "types": "imgui.ts",
  "scripts": {
    "build": "make build-bind-imgui && npm run build-imgui",
    "clean": "make clean-bind-imgui && npm run clean-imgui",
    "watch": "npm run watch-example",
    "start": "npm run start-example",
    "dist": "rollup -c",
    "build-imgui": "tsc",
    "watch-imgui": "tsc --watch",
    "clean-imgui": "echo TODO: clean-imgui",
    "build-example": "tsc -p example",
    "watch-example": "tsc -p example --watch",
    "clean-example": "echo TODO: clean-example",
    "start-example": "npm run start-example-html",
    "start-example-html": "echo http://localhost:8080/example/index.html && http-server -c-1 -o",
    "start-example-node": "node example/index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Isaac Burns <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "@types/emscripten": "^1.39.4",
    "@types/node": "^12.12.41",
    "@types/systemjs": "^0.20.7",
    "node-fetch": "^2.6.0",
    "systemjs": "^0.21.6"
  },
  "devDependencies": {
    "http-server": "^0.12.3",
    "node-fetch": "^2.6.0",
    "rollup": "2.22.2",
    "@rollup/plugin-commonjs": "13.0.2",
    "rollup-plugin-node-builtins": "^2.1.2",
    "rollup-plugin-typescript2": "^0.27.1",
    "systemjs": "^0.21.6",
    "typescript": "^3.9.3"
  }
}

error log ( npm_debug.log)
npm-debug.log

node version:
v8.10.0

pleaes let me know what other info you might need or help me our where I am failing.

Thank you

Add WebGPU implementation

It would be nice to target WebGPU too. That should eventually be replacing WebGL. Its api is starting to settle down so any breaking changes will probably just be name stuff and petty argument changes rather than anything big.

I don't mind implementing it. I am using this library with clojurescript and I have it rendering via WebGPU there. Porting it over should not be much of a hassle.

One question I have is structuring related. All the HTML platform stuff (canvas_on_keydown etc) is the same so really should be shared. In my own implementation I keep the platform and renderer stuff separate. This maps up to the imgui concept that there is a io.BackendPlatformName and a io.BackendRendererName.

I propose splitting out the html platform stuff into its own file. Then add a WebGL renderer file, a new WebGPU renderer file, and perhaps split out the canvas fallback renderer into its own file. To maintain backwards compatibility keep imgui_impl.ts (and thus imgui_impl.umd.js) but it would just import in the html platform implementation and the webgl renderer plus the canvas renderer as fallback.

Import with webpack

I'm trying to use imgui-js with webpack, it do compile, but output "System.register is not supported by webpack." in the browser console, is it necessary to use systemJS to embed imgui-js?

run native imgui window from node

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?

Drag and Drop causes imgui to crash

This bug is quite easy to reproduce. Just go to the example page and in the demo window: Widgets -> Drag and Drop, and try clicking and dragging one of the boxes. Imgui crashes.

It seems to do this for every browser I've tried: Edge 76.0.152.0, Chrome 74.0.3729.131, whatever safari my friend had on his macbook.

ImGui-js crashes with "Context Lost" on newish Nvidia drivers and Chrome on Windows

Not sure if this is exclusive to this exact setup, but both the example application at https://flyover.github.io/imgui-js/example/ and the local version of ImGui-JS I've got crash with "Context lost" on the Nvidia Game Ready Driver 496.76, Chrome 96.0.4664.45, Windows 19042.631.
Have confirmed also occurs on a Friend's PC (Windows ver. 19042.1348, same Chrome version, Nvidia driver 496.49) - Can give more details if needed.

The only error returned in console is "WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost"

Keyboard issue

Hi,
I'm just trying ImGui on a webpage after a good experience in C++, and that's awesome.
The thing is that I start using an InputText, but the text never change in despite of key pressed:

ImGui.InputText(idd, (value = window[idd]) => window[idd] = value );

Is there anything special to do to get ImGui-js to obtain keyboard events, or this some other issue ?
Everything looks ok, cursor is changing when focusing the textbox, I registered a window.addEventListener("keydown" which catch events correctly, and ImGui.GetIO() wants keyboard when the field is selected.
I have no clue...

Better packaging?

As of right now, this implementation feels a little too oriented around building and showing the demo. I am not sure how many people use System.js, but I do think some better defaults around the module would help a lot of people. Just so one could do a typical import ImGui from "imgui-js", even import {ImGui, ImGui_Impl} from "imgui-js" out of the box.

I can certainly take this on and do a PR, (I already have a fork with the minimal changes needed to do a regular import) but just wanted to see if the library maintainers have any interest in it, because it would be some substantial, breaking changes depending on how people are using the library.

ImGui Transfer Function

I'm sorry for asking this question here but, I just realized imgui can be use on web browsers
Is it possible to integrate imgui transfer function (here) to imgui-js ?
If so, how can it be done?

No ImDrawListSplitter in bindings

The autogenerated bindings don't seem to container ImDrawListSplitter, which is required to port some imgui widgets.

I tried to figure out the binding mechanism, but had no luck. Any help would be much appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.