# \[ANN\] CImGui.jl - A Wrapper for Bloat-free Immediate Mode Graphical User interface(Dear ImGui)

**URL:** https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268
**Category:** Package Announcements
**Created:** [February 27, 2019, 4:22pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268 "2019-02-27T16:22:39Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 6, 2019, 11:54am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/21 "2019-03-06T11:54:25Z")

</div>

I don’t think the _blame_ is on you 😀 In the Dear ImGui site they have a zip file with pre-compiled binaries and both the OpenGL & Vulcan ones show the same GPU usage behavior. So the issue is more fundamental in its origins.

---

<div class="post-metadata">

### Author: ![drjrkuhn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drjrkuhn/32/920_2.png) [@drjrkuhn](https://discourse.julialang.org/u/drjrkuhn)
#### Post date: [March 6, 2019, 4:26pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/22 "2019-03-06T16:26:36Z")

</div>

Nicolas Guillemot addresses the power inefficiency in his [C++ lightning talk on Dear imgui](https://youtu.be/LSRJ1jZq90k). It is an immediate mode renderer that recreates the entire gui every time through the event loop. It is very responsive, but power hungry.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 6, 2019, 8:15pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/23 "2019-03-06T20:15:39Z")

</div>

Had seen references to it but didn’t realize the effects of that _continuous recreation_ were so drastic.

---

<div class="post-metadata">

### Author: ![sefffal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sefffal/32/23640_2.png) [@sefffal](https://discourse.julialang.org/u/sefffal)
#### Post date: [August 29, 2020, 10:11pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/24 "2020-08-29T22:11:04Z")

</div>

Just gave this a try combined with [ImPlot.jl](https://github.com/wsphillips/ImPlot.jl) and I’m really impressed with how responsive it is. Also, it seems I can run the loop on a background thread. I wrapped the examples in [https://github.com/wsphillips/ImPlot.jl/blob/master/demo/example\_plots.jl](https://github.com/wsphillips/ImPlot.jl/blob/master/demo/example_plots.jl) in a function and called it with Threads.@spawn and it all worked like magic. This seems like a real advantage over other plotting / UI libraries for Julia.

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [August 30, 2020, 2:47am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/25 "2020-08-30T02:47:05Z")

</div>

Could you share the example code? I got a crash on my machine. I guess I just did something wrong when using `Threads.@spawn`.

```julia
 2020-08-30 10:40:44.470 julia[42621:627679] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1677.104/Foundation/Misc.subproj/NSUndoManager.m:363
2020-08-30 10:40:44.471 julia[42621:627679] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
)
libc++abi.dylib: terminating with uncaught exception of type NSException

signal (6): Abort trap: 6
in expression starting at none:0
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 7965270 (Pool: 7963320; Big: 1950); GC: 7
[1] 42621 abort julia

```

---

<div class="post-metadata">

### Author: ![sefffal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sefffal/32/23640_2.png) [@sefffal](https://discourse.julialang.org/u/sefffal)
#### Post date: [August 30, 2020, 3:08am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/26 "2020-08-30T03:08:16Z")

</div>

Sure. It might be platform dependent.

You can see what I tried in [this gist](https://gist.github.com/sefffal/c422395cbdf5fea13986b99b2f2e85bd) which I adapted from the ImPlot.jl example.

I tested on Julia 1.5.0 on Windows 10 (20H2).

If that doesn’t work for you, you could use `@async` instead and put `yeild()` at the end of the event loop. Not multi-threading, but at least it runs in the background.

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [August 30, 2020, 3:20am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/27 "2020-08-30T03:20:39Z")

</div>

Looks like this doesn’t work on macOS. Maybe this is due to CImGui.jl isn’t thread-safe, will try to fix it later.

update: it turns out to be a GLFW limitation: [Which Thread For Handling OpenGL's Window? - #2 by mmozeiko - support - GLFW](https://discourse.glfw.org/t/which-thread-for-handling-opengls-window/871/2)

---

<div class="post-metadata">

### Author: ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)
#### Post date: [August 30, 2020, 8:38am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/28 "2020-08-30T08:38:29Z")

</div>

Works fine in Julia 1.5.0 on Ubuntu. Very impressive!

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [August 30, 2020, 11:45am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/29 "2020-08-30T11:45:43Z")

</div>

Here’s how my oscilloscope GUI works so far. I’m very happy with CImGui and ImPlot!  
 ![ezgif-5-3afeb5688cfc](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d07078df9d70da20c0371f74711732cfb56f927.gif)

---

<div class="post-metadata">

### Author: ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)
#### Post date: [August 30, 2020, 8:21pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/30 "2020-08-30T20:21:30Z")

</div>

Wow, I have been thinking of trying this for a long time! Is this via serial or GPIB?

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [August 30, 2020, 8:56pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/31 "2020-08-30T20:56:06Z")

</div>

[https://github.com/iuliancioarca/TIVM](https://github.com/iuliancioarca/TIVM)  
You can find the code here. The gui is somehow separate from the instrument driver, I still have to tidy things up.  
The gif above is the gui actually connected to a Lecroy HDO6054 via USB( not the TDS2002 in the repo).  
The Lecroy setup has decent refresh rate, depending on the size of the waveform( this one was tested with only 5k samples).  
I’m struggling however with the TDS2002(also USB), which has 100ms delay for every command I send. Fetching a waveform (2500 pts) for one channel takes 1 second and it’s driving me crazy. I don’t know if it’s the scope that is slow or if I have a problem with the computer( it’s a different computer than the Lecroy setup, some old core duo laptop), but other instruments exhibit this behavior as well…

---

<div class="post-metadata">

### Author: ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)
#### Post date: [August 31, 2020, 7:41am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/32 "2020-08-31T07:41:24Z")

</div>

Many thanks! I misread the oscilloscope type and thought it’s older series, of course USB nowadays.

---

<div class="post-metadata">

### Author: ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)
#### Post date: [August 31, 2020, 3:29pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/33 "2020-08-31T15:29:37Z")

</div>

> [@Gnimuc](#):
>
> `'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'`

This is because on macOS the GUI must run on the application main thread, I hit the same problem in QML.jl, and presumably Gtk.jl would be similarly affected. Maybe we should figure out a way to keep the main thread free for this kind of application?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [August 31, 2020, 3:38pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/34 "2020-08-31T15:38:57Z")

</div>

I guess at least we should notify those Mac users to always run GUI code on the main thread. Is it feasible to define a function that will throw the warning when called with `Threads.@spawn`?

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [September 1, 2020, 4:45am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/35 "2020-09-01T04:45:34Z")

</div>

> [@Iulian.Cioarca](#):
>
> via USB

How are you talking via USB using Julia ?

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [September 1, 2020, 5:34am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/36 "2020-09-01T05:34:48Z")

</div>

I have this VISA wrapper: [https://github.com/iuliancioarca/GenericInstruments.jl](https://github.com/iuliancioarca/GenericInstruments.jl)

---

<div class="post-metadata">

### Author: ![sefffal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sefffal/32/23640_2.png) [@sefffal](https://discourse.julialang.org/u/sefffal)
#### Post date: [September 3, 2020, 9:56pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/37 "2020-09-03T21:56:45Z")

</div>

That makes sense. Interesting that some platforms don’t have that same restriction.

For keeping the main thread free ThreadPools.jl works very well. I normally use either `@bthreads` macro or `bmap`. The one thing missing is something like `@bspawn` to launch a single task on a background thread, but `@tspawnat 2` works well enough.

---

<div class="post-metadata">

### Author: ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)
#### Post date: [February 17, 2021, 6:22pm UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/38 "2021-02-17T18:22:35Z")

</div>

So I just asked a question on your package’s [GitHub discussions](https://github.com/Gnimuc/CImGui.jl/discussions) after seeing your post there @Gnimuc. A suggestion - if that’s where you’d prefer Q&A etc to go then maybe mention this in the README in order to direct people there?

CImGui looks really awesome, BTW. I’m especially excited that it seems that it may be possible to integrate Makie.

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [February 18, 2021, 1:28am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/39 "2021-02-18T01:28:07Z")

</div>

Github discussions and Julia discourse are both fine to me, when asking general questions about CImGui on discourse, feel free to ping me if I missed that post.

> [@airpmb](#):
>
> BTW. I’m especially excited that it seems that it may be possible to integrate Makie.

[SteffenPL](https://discourse.julialang.org/u/SteffenPL) has an example in thie post:

> [@Is it possible to use Makie in CImGui?](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/3):
>
> Or the other way around, let Makie do the off-screen rendering, then re-render the output of framebuffer as an CImGui.Image object. This way is probably more feasible since Makie has some recording APIs around there.

---

<div class="post-metadata">

### Author: ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)
#### Post date: [January 29, 2022, 11:33am UTC](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268/40 "2022-01-29T11:33:38Z")

</div>

Hey @Gnimuc, first off, thanks again for this package.

Quick question. You provide a `Renderer.jl`

For myself, when I’m using coroutines or threads in Julia I control the exit by having the corouting or thread running on `while run_flag[]` where run\_flag is a `Threads.Atomic{Bool}`.

From your Renderer.jl, I see that you do something that feels similar, but I don’t really understand it. This line:  
[https://github.com/Gnimuc/CImGui.jl/blob/db5f0983eca284baba0ce21fb8cbdbc30df4a8ac/examples/Renderer.jl#L58](https://github.com/Gnimuc/CImGui.jl/blob/db5f0983eca284baba0ce21fb8cbdbc30df4a8ac/examples/Renderer.jl#L58)

How can I set `GLFW.WindowShouldClose(window)` to `true`, so that the renderloop exits?

Thank you.

EDIT: I just checked, and I can use my solution alongside yours by replace your while with `while run_flag[] && !GLFW.WindowShouldClose(window)`. However, this solution A) makes me feel like I’m missing something, and B) it skips the `finally`, so maybe it’s not cleaning up properly…?

[Previous page](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268.md?page=1)

[Next page](https://discourse.julialang.org/t/ann-cimgui-jl-a-wrapper-for-bloat-free-immediate-mode-graphical-user-interface-dear-imgui/21268.md?page=3)
