top | item 34106762

Nuklear – A single-header ANSI C immediate mode cross-platform GUI library

326 points| andsoitis | 3 years ago |github.com

100 comments

order
[+] flohofwoe|3 years ago|reply
Here's a simple WASM version of the Nuklear standard demo:

https://floooh.github.io/sokol-html5/nuklear-sapp.html

The big difference to Dear ImGui is that Nuklear has a C API and is also implemented in C - and apparently it has more skinning/themeing options, which I haven't tinkered with yet.

TBH, for tools I prefer cimgui (a C wrapper around Dear ImGui), my impression is that Nuklear has a 'purer' immediate-mode design at the cost of some convenience, while Dear ImGui has a more pragmatic design approach, but also has less friction for writing UI code. I haven't needed skinning options so far though, that might be the actual USP of Nuklear.

It all might also just be personal bias, because I used Dear ImGui before Nuklear :)

For shits'n'giggles, here's both UI systems in the same application:

https://floooh.github.io/sokol-html5/nuklear-sapp-ui.html

(the menu bar and all windows that open from it is Dear ImGui, the rest is Nuklear).

[+] 0x0203|3 years ago|reply
Another advantage of Nuklear is that it has a pure software renderer back end that comes with it. If you're developing on a system where you don't have OpenGL or any of the other myriad of software/hardware renderers, nuklear is pretty handy. It makes it easy to write your own driver for custom/embedded systems.
[+] mixmastamyk|3 years ago|reply
Pretty cool that works in a browser on a canvas. Might I consider it to build something like a simplified photopea or powerpoint? However it requires webgl and writing in C translated to wasm? Looks like webgl is well supported, do many folks have it disabled?

Not sure about that, maybe javascript with svg would be easier to write such an app in.

[+] reassembled|3 years ago|reply
DearIMGUI has both an unofficial C wrapper and a new official C binding generator. I have personally used the CIMGUI wrapper with C99 apps using the Direct3D11 backend and it works great. The new API is started by the DearIMGUI creator but is still adding features that are available in CIMGUI.

Unofficial C API - https://github.com/cimgui/cimgui Official binding gen - https://github.com/dearimgui/dear_bindings

[+] cshenton|3 years ago|reply
Dear ImGui certainly seems more popular wherever skinning isn’t a priority (though I’ve seen games use it even for user facing UI). It’s become a bit of a Wilhelm scream, love spotting it in the wild.
[+] andrewmcwatters|3 years ago|reply
No, the biggest difference is one is only intended for development and debugging.

> Dear ImGui is designed to enable fast iterations and to empower programmers to create content creation tools and visualization / debug tools (as opposed to UI for the average end-user).

[+] camhenlin|3 years ago|reply
Nuklear is great. I’ve spent countless hours hacking around with it. I’ve also built a customized version for classic Macintosh systems (down to System 2.0 or so) and built some simple Macintosh software for it. I put it on GitHub here: https://github.com/CamHenlin/nuklear-quickdraw
[+] chrsig|3 years ago|reply
I've been using nanogui[0] to fit the bill for personal uses.

To be honest though, I'm at the point where I'd really prefer an easy and lightweight library to setup a http and/or websocket server, and just make a ui in the browser. I've got a simple use case -- I'm just making a simple scene editor & debugging ui for a toy ray tracer.

I know there are a ton of different libraries out there for the task, but that just makes it hard to evaluate the quality of any given library. I haven't given any a shot, I've only gone so far as to look at them and ponder what the size of the user base is, and question if the project will go inactive in a couple years. Or if it's going to require me to pull in some other host of dependencies.

Recommendations from HNers welcome!

[0] https://github.com/mitsuba-renderer/nanogui

[+] giraffe_lady|3 years ago|reply
Would redbean work for your purpose? It's very lightweight and fun to work with, though not suited for everything.

https://redbean.dev

[+] bboygravity|3 years ago|reply
> To be honest though, I'm at the point where I'd really prefer an easy and lightweight library to setup a http and/or websocket server, and just make a ui in the browser.

Wouldn't that mean that the expiry date of your GUI is like: a few years or so?

Since web-stuff seems to change so constantly with breaking changes and revamps every few years being the norm.

Whereas a WIN32 app (or Unix or other) from 25 years ago probably still runs fine? I can't imagine the same for any web-app that was written for Netscape and now has to run in a modern browser.

[+] veyh|3 years ago|reply
This is a simple and easy to use library. I made my first immediate mode UI with it recently: https://autoptt.com/

Of course, I forgot to add a frame limit so it ate up a full CPU core at first, but after fixing that, the usage was basically zero.

[+] rahen|3 years ago|reply
Interesting, this seems more resource efficient than even fltk, which is the lightest usable cross-platform GUI library. And it's pure C unlike fltk.

It's great to see such projects in an era of unabashed resource consumption.

[+] aarongeisler|3 years ago|reply
I use Nuklear for a Steam game I made in C. It worked well for my needs but there are a few things I still haven't figured out yet - like rendering centered multi-line text. Localizing my game was very straightforward with Nuklear - I didn't run into any roadblocks with fonts or different alphabets. I was able to get the interfaces to be controller-friendly too. Overall, I had a positive experience and will use it again.
[+] schemescape|3 years ago|reply
Did the Steam Overlay work?
[+] tete|3 years ago|reply
I really like this trend. Also see:

* Raylib - A single header file game engine https://www.raylib.com/ * Miniaudio - A single header file audio library https://miniaud.io/

Both (actually, not just three systems) cross-platform.

For their design and cross-platform support they make for great bases for Go libraries, unlike most C code out there.

[+] bschwindHN|3 years ago|reply
I can't say I'm excited about this trend, if it is a trend.

Immediate mode GUIs are usually pretty nice from a developer point of view, but many of them are lacking many things like accessibility and text selection. Maybe good for 3D modelers, video editors, etc., but not for more general purpose apps.

[+] canistel|3 years ago|reply
Having a peep at miniaud.io, I am astounded to say the least.

It supports almost all of the popular back-ends across platforms. A library as complex as PortAudio in a (largish) header.

[+] taylorius|3 years ago|reply
I tend to use ImGui for testbed projects. It's flexible and quick to get up and running. I only have two minor complaints about it.

1. It would be nice to have some built in image handling functions, i.e. to be able to allocate and draw images on the screen.

2. Skinning is currently rather limited. (I know this has been a long requested feature).

Other than those minor gripes, I like it a lot.

[+] flohofwoe|3 years ago|reply
> 1. It would be nice to have some built in image handling functions, i.e. to be able to allocate and draw images on the screen.

I think this would actually be fairly tricky to handle inside Dear ImGui, because the image object must be in a format that's understood by the rendering backend. The way ImGui handles image rendering via an opaque ImTextureID handle which is passed through to the renderer backend is actually quite elegant IMHO.

[+] cshenton|3 years ago|reply
I suspect (1) is just because Dear ImGui is BYO graphics backend, so it doing lots of clever texture management stuff for lots of images would increase the surface area of that integration which would make it harder to use for most folks.
[+] avidphantasm|3 years ago|reply
This looks cool, but I don’t do a lot of GUI work. Why would one use this as opposed to Qt?
[+] flohofwoe|3 years ago|reply
License issues aside the typical use case is that you want to integrate the UI with an existing 3D renderer (e.g. you have a 3D engine, and want an UI overlay for tooling and debugging). 'Bring your own renderer' UI frameworks like Nuklear or Dear ImGui are perfect for this use case. With 'traditional' UI frameworks like Qt, WPF, GTK... this is a massive PITA and even if it's possible would add an incredible amount of bloat.

...and then there's also the convenience of writing immediate mode UI code. Personally, I would never want to go back to event-/callback-/signal-driven UIs.

[+] 0x0203|3 years ago|reply
In addition to what others have said, they are different types of GUI systems. As an immediate mode UI, the logic behind what gets drawn to the screen in Nuklear runs every frame, and it draws/updates the entire screen every frame. A retained mode UI like QT draws elements once when they need to be updated, and they get left there until an event occurs that requires something change. So immediate mode UIs like Nuklear and Dear ImGUI, tend to be more appropriate for rendering the UI elements of games and other programs that already draw/update the screen each frame. Retained mode tends to be more useful for traditional "desktop" like applications where interacting with the standard toolkit widgets serves the primary purpose of the program. Of course there are many ways of blurring the lines and using either for both, so this isn't a hard and fast rule, just a rule of thumb.
[+] M4v3R|3 years ago|reply
QT is a huge dependency that you have to bundle with your app. This is tiny in comparison. Also probably easier to prototype with.
[+] fpiazza|3 years ago|reply
rapid development/prototyping
[+] NeutralForest|3 years ago|reply
Does anyone know of something similarly lightweight but retained mode?
[+] 0x0203|3 years ago|reply
You can check out LVGL: https://github.com/lvgl/lvgl/

It's geared more for embedded, but you can use an sdl back end for desktop (which might kill your light weight requirement depending on your strictness level). I wrote my own tty/framebuffer driver for it and use it directly on the frame buffer (not Linux) but it's pretty nice to work with. But if you need metal/openGL/Vulcan/directX and hardware acceleration, it's probably not what you're after.

[+] ianseyler|3 years ago|reply
Does this support writing to a linear frame buffer? Would be interesting to port to run on my OS if so.
[+] 0x0203|3 years ago|reply
It does. I've done it, starting with their x11_rawfb demo. It's pretty nice, but I've personally switched to using LVGL (https://github.com/lvgl/lvgl) for the OS I work on, as I find it a better fit for the purpose. I do still have a soft spot for Nuklear though, and depending on what you're trying to do with your OS, could also be a good fit. Really not hard to get it going if you don't mind implementing your own keyboard/mouse driver layer.
[+] flohofwoe|3 years ago|reply
Nuklear returns a bunch of vertices, vertex-indices and draw commands, so it plugs best into a 3D API (like GL, D3D, Metal, Vulkan...). To render into a frame buffer you'd need to implement a simple software rasterizer with texturing support.
[+] tov_objorkin|3 years ago|reply
I have backend for the Hisilicon SoC from 2016, its about 1500 lines of C code, few calls to 2D API and copypasta of the triangle rasterizer. Dunno about modern version requirements.
[+] teknopaul|3 years ago|reply
Sounds like the answer to just about everybody's areweuiyet? Question
[+] UltraViolence|3 years ago|reply
Why didn't they write it in Rust? Rust really needs a good GUI library to take off.

I'm hoping the wxWidgets creators will rewrite their library in Rust or at the very least create bindings for it.