Code Monkey home page Code Monkey logo

swigimgui's Introduction

swigimgui

SWIG binding for Dear ImGui

This repo genertates Dear ImGui bindings to other languages (eg. Lua), by providing a imgui.i SWIG interface file.

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages (C#, Java, Lua, Python, Ruby, ...)

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Current Status

  • SWIG 4.0.2
  • ImGui 1.85 master branch
    • imconfig.h (or customized IMGUI_USER_CONFIG)
    • imgui.h
  • Supported languages:
    • Lua
  • Supported backends:
    • none (You can compile the project without a backend)
    • glfw_opengl (for demonstrating how to add support for a particular backend. See files in the backendWrapper folder.)

Build

This provided build method requires xmake and SWIG installed.

xmake config --menu # Config the project using a terminal ui. You choose a target language and other options in the menu `Project Configuration`.
xmake               # Build with saved configs.

Example

Lua

-- To run this example, you need to config and build the repo with a working backend, eg.:
--   ```sh
--   xmake config --backend="glfw_opengl3" --language="lua" --lua_flavor="luajit"
--   xmake
--   ```
-- Then add the library into search path when starting Lua or LuaJIT. eg.:
--   ```sh
--   luajit -e "package.cpath=package.cpath..';./build/linux/x86_64/release/swigimgui_lua.so'" "example.lua"
--   ```

-- Load the modules from the library.
local ig = require "imgui"
local wrapper = require "imgui_backendWrapper"
local showDemo = true

-- Create a ImGui and backend context by initializing a window.
wrapper.InitWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example")

-- Main loop.
while not wrapper.WindowShouldClose() do

    -- Begin a new backend rendering frame.
    wrapper.FrameBegin()

    -- Do any ImGui or backend stuffs.
    if showDemo then
        showDemo = ig.ShowDemoWindow(showDemo)
    end
    ig.Begin("Hello, world!")
    ig.Text("This is some useful text.")
    ig.End()

    -- Apply and render the ImGui draw list, and end the frame.
    wrapper.FrameEnd()
end

-- Destroy the ImGui and backend context.
wrapper.Shutdown()

Performance Notes

  • Interops are expensive. Here are some tips to save interop counts:
    • If a simple struct instance is to be modified many times (eg. C++ ImVec2 value calculated inside a loop):
      • It might not be a good idea to use the struct fields directly in complex calculations, because SWIG wraps the getter and setter functions to contain implicit C/C++ <-> script type conversions. Instead, if needed, copy the fields as local types, and after calculations copy back the results to the struct instance.
      • ImVec2AsFloatP, ImVec4AsFloatP, FloatPAsImVec2, FloatPAsImVec4 are added as helper functions inside imgui.swig and usable for binding target languages.
    • You can modify the binding file to contain you own C/C++ functions to possibly prevent some interops happen, and generate bindings of them for your need.

Pull Requests are welcomed

Would be nicer if this repo can be a collection featuring Ruby/Python/... bindings as well!

LICENSE

MIT

swigimgui's People

Contributors

rinkaa avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

rinkaa jonathhhan

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.