All Projects → RblSb → khm.imgui

RblSb / khm.imgui

Licence: MIT license
Imgui core for Kha

Programming Languages

haxe
709 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to khm.imgui

Node editor framework
A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
Stars: ✭ 1,751 (+10843.75%)
Mutual labels:  imgui
Imgui Ws
Dear ImGui over WebSockets
Stars: ✭ 165 (+931.25%)
Mutual labels:  imgui
Nuklear
A single-header ANSI C gui library
Stars: ✭ 13,365 (+83431.25%)
Mutual labels:  imgui
Sequentity
A single-file, immediate-mode sequencer widget for C++17, Dear ImGui and EnTT
Stars: ✭ 134 (+737.5%)
Mutual labels:  imgui
Rapidgui
Unity OnGUI(IMGUI) extensions for Rapid prototyping/development
Stars: ✭ 144 (+800%)
Mutual labels:  imgui
Webgui
An example demo of IMGUI (Immediate Mode GUI) on the web. Using only WebGL, GLFW and ImGui. Suitable for being compiled to web assembly (WASM).
Stars: ✭ 180 (+1025%)
Mutual labels:  imgui
Sonyheadphonesclient
A {Windows, macOS, Linux} client recreating the functionality of the Sony Headphones app
Stars: ✭ 123 (+668.75%)
Mutual labels:  imgui
Imgui Filebrowser
File browser implementation for dear-imgui. C++17 is required.
Stars: ✭ 231 (+1343.75%)
Mutual labels:  imgui
Imguifontstudio
Font Helper Gui Tool for programming
Stars: ✭ 149 (+831.25%)
Mutual labels:  imgui
Netimgui
'Dear Imgui' remote access library and application
Stars: ✭ 189 (+1081.25%)
Mutual labels:  imgui
Imgui sdl
ImGuiSDL: SDL2 based renderer for Dear ImGui
Stars: ✭ 134 (+737.5%)
Mutual labels:  imgui
Bimpy
imgui for python
Stars: ✭ 144 (+800%)
Mutual labels:  imgui
Vxr
General purpose engine written in C++ with emphasis on materials rendering (PBR, clear coat, anisotropy, iridescence)
Stars: ✭ 181 (+1031.25%)
Mutual labels:  imgui
Imgui
Immediate Mode GUI for C#
Stars: ✭ 133 (+731.25%)
Mutual labels:  imgui
Goesp
Cross-platform streamproof ESP hack for Counter-Strike: Global Offensive, written in modern C++. Rendering and GUI powered by Dear ImGui.
Stars: ✭ 210 (+1212.5%)
Mutual labels:  imgui
Nukleardotnet
.NET binding for the Nuklear immediate mode GUI
Stars: ✭ 126 (+687.5%)
Mutual labels:  imgui
Libtorch Yolov3 Deepsort
Stars: ✭ 165 (+931.25%)
Mutual labels:  imgui
Simplerenderengine
Small C++14 render engine
Stars: ✭ 253 (+1481.25%)
Mutual labels:  imgui
Nimgl
NimGL is a Nim library that offers bindings for popular libraries used in computer graphics
Stars: ✭ 218 (+1262.5%)
Mutual labels:  imgui
Imguizmo.quat
ImGui GIZMO widget - 3D object manipulator / orientator
Stars: ✭ 187 (+1068.75%)
Mutual labels:  imgui

khm.imgui

Imgui core for Kha.

Online demo

Pros:

  • Multitouch, singletouch groups
  • Keyboard support, tab navigation
  • Event blocking/skipping via gui
  • Widget clipping/overlapping
  • Documented API for custom widgets

Cons:

  • Only one draw cycle per imgui instance
  • Caching should be done on widget side
  • This is just core with independent test widgets, not something more

Basic usage

import kha.Assets;
import kha.Framebuffer;
import kha.System;
import khm.imgui.Imgui;
using khm.imgui.Widgets;

class ImguiDemo {
	var ui:Imgui;

	public function new():Void {
		ui = new Imgui({});
		System.notifyOnFrames(onRender);
	}

	function onRender(fbs:Array<Framebuffer>):Void {
		final g = fbs[0].g2;
		g.begin(0xFF404040);
		g.font = Assets.fonts.OpenSans_Regular;
		g.fontSize = 24;

		ui.begin(g);
		if (ui.button(50, 50, "Hello")) trace("Hello");
		ui.end();

		// call only after gui rendering
		g.end();
	}
}

Integration

For actual usage I recommend to disable automatic input listeners:

ui = new Imgui({autoNotifyInput: false});

And use all your listeners with imgui like that:

function onMouseDown(button:Int, x:Int, y:Int):Void {
	// send mouseDown to imgui instance, returns true if imgui blocks event
	if (ui.onMouseDown(button, x, y)) return;
	// click stuff behind gui
}
function onTouchDown(id:Int, x:Int, y:Int):Void {
	if (ui.onMouseDown(id, x, y)) return;
	// touch stuff behind gui
}
// same for onMouseUp, onMouseMove, onMouseWheel, onTouchMove, onTouchUp
// and for onKeyDown, onKeyUp, onKeyPress

Also, do not create events for the mouse and for the touch together, select only one thing for current kha target.

Commercial break Or use it with khm.Screen to get mouse/touch unification, scale support and pointer/keys state arrays.

import khm.Screen;
class Name extends Screen { // all listeners creates after new Name().show()
	override function onMouseDown(p:Pointer):Void { // also works as onTouchDown
		if (ui.onPointerDown(p)) return;
	}
	override function onRender(canvas:kha.Canvas):Void {
		final g = canvas.g2;
		...
	}
	// you still need to override onMouseMove, onMouseWheel
	// and key events for sending it to imgui
}

Widget example

Actual button code with comments:

public static function button(ui:Imgui, x:Int, y:Int, text = ""):Bool {
	final g = ui.g; // graphics2 from imgui.begin(g)
	// generates int id (previous widget id += 1)
	final id = ui.getId();
	final w = buttonW; // static vars
	final h = buttonH;
	// WidgetRect is inlined class
	final rect = new WidgetRect(id, x, y, w, h);
	// add to current frame (for input event prevention and overlapping)
	ui.addWidget(rect);
	// set widget state idle/hovered/active based on overlapping, widget groups and pointer ids
	ui.checkWidgetState(rect);

	// every widget can have multiply states at once, like Active + Hover + Focus.
	// this can be checked with ui.isActive(id)/isHovered/isFocused/isIdle

	// If widget focused draw focus border (custom function)
	if (ui.isFocused(id)) drawFocusBorder(g, rect);

	// returns only most priority state (order is Active > Focus > Hover > Idle)
	final state = ui.getWidgetState(id);
	// set bg color (colors is static vars)
	g.color = switch (state) {
		case Idle: bgColor;
		case Hover, Focus: hoverColor;
		case Active: activeColor;
	}
	g.fillRect(x, y, w, h);

	// draw text color
	if (ui.isActive(id)) g.color = bgColor;
	else g.color = activeColor;
	// draw text
	final textW = g.font.width(g.fontSize, text);
	final textH = g.font.height(g.fontSize);
	g.drawString(text, x + w / 2 - textW / 2, y + h / 2 - textH / 2);

	// pointer (mouse/touch) released with widget be selected (focus/hover) and active
	return ui.isWidgetClicked(id);
}

Widget caching

Create non-static state class with render target. Draw to render target only on widget focus/hovering, other time draw cached render target.

For widgets with subwidgets inside, like panels/windows, there is imgui.setGraphics(g2) and imgui.resetGraphics() for graphic context swap. Example:

// if window hovered/focused:
// save windowId to window state
// set custom g2
// return true
if (imgui.beginWindow(window)) {
	// redraw button to render target
	imgui.button(...);
	// reset g2
	// you can get latest subwidget id with `imgui.prevId()`
	// and make checks on range (id => windowId && id <= prevId)
	// about hover/active subwidgets
	imgui.endWindow(window);
}

Fullscreen / Pointer lock workaround

Browsers block fullscreen / pointer lock if they are not called from event handler functions. Imgui of course calls the buttons from the render function, so we need to call the renderer right after mouse down / mouse up / key down.

ui = new Imgui({autoNotifyInput: false, redrawOnEvents: true});
...
override function onMouseUp(p:Pointer):Void {
	if (ui.onPointerUp(p)) {
		if (ui.redrawOnEvents) onRender(ui.g);
		return;
	}
}

For key listeners redrawOnEvents: true don't needed, but render call is required.

Unnecessary redrawing is not the best solution, but another is difficult to achieve. For optimization, I recommend to put the imgui rendering in a separate function and call it like renderGUI(ui.g), and most importantly, create an imgui instance with redrawOnEvents: true only for the menu/settings screen with fullscreen / pointer lock buttons, not for everything. Or, if you do not want to recreate the imgui instance, set the ui.redrawOnEvents = true/false at the right moment.

Plans

  • Cache test, more examples, api stabilization
  • Zui-like widget system based on current components, but with relative cords?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].