17 ms·
Nuklear: A cross-platform GUI library in C
- deleted 6y ago[deleted]
- azhenley 6y agoSingle header, no dependencies, cross platform, immediate mode, and the GUI examples actually look good... that’s wild.
- bitexploder 6y agoImGui is nice too. I use it for quick UI hacks in Python :)
- moonchild 6y agoShould clarify that you're referring (I presume) to dear imgui. Imgui in general refers to the immediate mode gui paradigm in general, as opposed to retained mode gui.
- bitexploder 6y agoYes that one. Though I have only ever seen dear imgui written as ImGui. It’s really sweet. I taught my 14 year old son the basics and he is making all sorts of weird GUIs now lol
- jki275 6y agoIt's really nice. I was surprised at how well it works. Downloaded it, ran make inside the example folder, and it built working examples.
- CyberRabbi 6y agoNot to mention written in C89. This person knows how to distribute code well. I love libraries like this, I wish we had more.
- tom_mellior 6y agoHow relevant is C89 really nowadays? As far as I understand it took MSVC a long time to catch up to C99, but it's been there for a long time now. Is the motivation more related to retrocomputing? I would expect that decades-old compilers for retro platforms might not be reliably C89 conforming either.
- tsegratis 6y agomsvc's still not hit C99, but to be fair, they're not aiming for it (last I checked a year or two ago)
- augustk 6y agohttps://en.wikipedia.org/wiki/C99#Implementations https://en.wikipedia.org/wiki/C99#Implementations Only 7 of the 24 compilers in the list fully implements C99 whereas I would guess all those compilers implement C89. If you want to write long-lived programs, C89 is a good choice.
- tom_mellior 6y agoThanks, though those numbers may be a bit misleading. It's probably feasible to have very widely portable programs in C99-except-obscure-pragmas. But MSVC in particular seems to be less far along than I thought. Oh well.
- augustk 6y agoAlso, the difference between C89 and C99 is not that big.
- CyberRabbi 6y agoIt’s not just retro computing, new hardware platforms bootstrap themselves by providing a c89 compiler. It’s just good form. Imo c99’s additional features are not worth losing nearly universal portability. It’s trivial to reimplement most of c99’s useful features with a small header if you must, as this library does.
- frkloovb 6y agoWhy is a single headerness so important here?
- bmn__ 6y agoFor the general reasons. https://github.com/nothings/stb#why-single-file-headers https://github.com/nothings/stb#why-single-file-headers
- spacechild1 6y agoIt's not important at all. “single-header-library“ in C basically means #including a .c file in disguise. It's for people who are too lazy to add a source directory to their build system...
- Snelius 6y agoC89 yeah :)
- war1025 6y agoThe name reminds me of the website NuklearPower, and specifically the web comic 8-bit Theater [1] that I followed back in the day. Off topic, but also a pleasant reminder of something I used to enjoy quite a lot. [1] http://www.nuklearpower.com/2001/03/02/episode-001-were-going-where/ http://www.nuklearpower.com/2001/03/02/episode-001-were-goin...
- adamnemecek 6y agoThis is only tangentially related but if you are looking for a 2d rendering api for Rust, peep femtovg https://github.com/femtovg/femtovg https://github.com/femtovg/femtovg Join the discord https://discord.gg/V69VdVu https://discord.gg/V69VdVu Quite a few people have been using it to build their own GUI. Add some layout, windowing and event handling and you have yourself a GUI.
- rudedogg 6y agoThis demo UI (https://github.com/femtovg/femtovg/blob/master/assets/demo.png https://github.com/femtovg/femtovg/blob/master/assets/demo.p...) is the same one I've seen in the Pathfinder (https://github.com/servo/pathfinder https://github.com/servo/pathfinder) examples. Is it something common, like the tiger used to demo SVG libraries?
- adamnemecek 6y agoYeah it’s from nanovg https://github.com/memononen/nanovg https://github.com/memononen/nanovg. I wonder if it’s even older than that.
- rudedogg 6y agoInteresting, thanks for letting me know!
- deleted 6y ago[deleted]
- benjaminjackman 6y agoThis looks pretty neat! I briefly looked for Immediate mode gui libraries for Java, just to experiment with. I see this has java bindings (though 3 years old). I had been planning to try out the jni wrapper for Dear Im GUI which I have used in C++ before. Just wondering if anyone has used a decent pure jvm immediate mode gui library before or have suggestions on immediate mode libraries in general to try out? For what I am thinking of trying it out with, my needs aren't too high so I might just write something simple with libGDX/lwjgl3.
- liquidify 6y agoCurious. Why C89?
- psykotic 6y agoC99 support in MSVC was still spotty until very recently. And for single-header libraries in particular it's helpful to use a style of C that can be #included directly into C++ source files without issue.
- sillysaurusx 6y agoI thought MSVC supported C99 since like ... 2012? I guess a decade is sort of "very recently" in MSVC terms, but it's been awhile.
- psykotic 6y agoA post-release update to VS 2017 was the first version which supported a useful subset of C99. But support isn't a binary thing; I was tangentially involved in diagnosing a critical bug in their implementation of C99 lvalue literals just a few months ago. Minimal repro: https://godbolt.org/z/7rTv1M https://godbolt.org/z/7rTv1M
- flohofwoe 6y agoMinor nitpick: Most C99 features were "already" in a VS2015 update (initialization features like designated init and compound literals, and a standard compliant snprintf()). The big missing features were VLAs (those will never be implemented) and _Generic (implemented now in VS2019).
- psykotic 6y agoThanks, I was confusing the VS 2015 update with VS 2017 as the one that got the big pieces like designated initializers and compound literals. I don't think anyone cares about VLAs, but I look forward to being able to rely on _Generic in another 5 years when VS 2019 can be assumed available. :)
- msoloviev 6y agoHas anyone made a serious attempt at a intermediate-mode frontend to desktop GUI toolkits (as opposed to single-application ones that are rendered by some general-purpose accelerated graphics library)? I've experimented a little bit in the past (https://github.com/blackhole89/instagui/blob/master/main.cpp https://github.com/blackhole89/instagui/blob/master/main.cpp, whose implementation is based on something pretty close to my understanding of Elm's "virtual DOM" diffing; don't mind the kooky custom macro system), but wound up bumping into a lot of nasty little problems that made hacking on it not a lot of fun.
- adinisom 6y agoYou might be interested in Mike Dunlavey's Differential Execution demo: https://sourceforge.net/projects/dyndlgdemo/files/ https://sourceforge.net/projects/dyndlgdemo/files/ https://github.com/MikeDunlavey/AucUI https://github.com/MikeDunlavey/AucUI He explains it a bit more here: https://stackoverflow.com/questions/371898/how-does-differential-execution-work https://stackoverflow.com/questions/371898/how-does-differen...
- msoloviev 6y agoOh, yeah, the Stack Overflow post especially seems to talk about very similar problems to what I have been grappling with. Thanks for the pointer! The code is pretty opaque to me, though; it's been well over a decade since I've last had any interaction with the WINAPI programming style, Hungarian notation and all. I wonder why he arrives at the conclusion that he needs a full-fledged DSL for what he is doing. I remember that at the time I was working on this, the impression I had was that a lot of my problems would go away if only there were some unique way to identify every distinct invocation of a function (so I could use data along the lines of "you are currently in the 3rd call of Button() in something.cpp"). __FILE__ and __LINE__ get close but don't disambiguate between multiple calls on the same line (and anyhow would need to be baked into the invocations with macro hackery).
- psykotic 6y agoEvery immediate-mode UI deals with the id namespace issue. What they usually have in common is a hierarchical id namespace where you have an id stack and a child id is derived from the parent id via hashing, child_id = hash(parent_id, widget_type, subid). [1] The subid can be derived from widget arguments that are likely to be unique and stable from frame to frame, e.g. a text edit box's buffer pointer. But there always needs to be a way to provide an explicit subid since the implicit method doesn't always cut it. Alternatively, as long as the default subid is stable you can always make it unique by wrapping the widget (and other nearby related widgets) with an explicit pair of push_id/pop_id calls. You can see an example here: https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp#L1701 https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp#.... The defaults work most of the time but this is definitely an aspect of immediate-mode UIs that can't just be treated as a hidden implementation detail. [1] The prevailing use of hashing is a consequence of the popular immediate-mode UI libraries being focused on minimal state per widget. If you already plan to maintain significant state for every widget (as you would need in an immediate-mode interface to win32 controls) you would just do hierarchical interning with sequential id assignment (i.e. the first time a new subid is used with a given parent, it is assigned a sequential global id and put in a table so the association can be memoized across frames) and then hash collisions won't cause id collisions.
- soheil 6y agoOn Mac I finally got the example to run had to brew install glew and glfw3 and change the makefile to point to the include and lib paths. A lot of the interactions don't seem native, for example tap to click doesn't work, I have to do hard clicks on my Mac. Also dragging doesn't seem to work like other apps, it stops dragging if go outside the boundaries of the element. Overall this is pretty epic and I wonder if serious alternatives to XCode and JS based wrappers like Electron are possible.
- mike_d 6y agoBased on the gallery of examples it looks to be focused on what you might call "full screen" applications, like games. In these use case consistent cross-platform interaction is more important than feeling "native" on any given platform.
- jki275 6y agoYou may have an issue with your installation of glew and glfw -- I didn't have to make any changes to the makefile to build the examples.
- soheil 6y agoProbably my env paths are not set correctly with brew on my M1 Mac.
- jki275 6y agoAh -- brew is definitely not mature on the M1 Macs yet as I understand it. I've been on the fence for a couple of months over this -- I want to grab an M1 Mac for R&D type stuff, but at the same time I want to wait until they release the 16" with a hopefully upgraded M1 of some sort.
- soheil 6y agoYou should probably get one anyway, it's incredibly life changing. You can always sell it on eBay after the 16" comes out, they hold on to their value pretty well.
- tus89 6y agoThis is cool. Has anyone written a C++ "MFC" for this yet?
- Const-me 6y agoI once did something similar in C++, C# and HLSL: https://github.com/Const-me/Vrmac https://github.com/Const-me/Vrmac With more focus on GPU integration, and output quality. Unfortunately, these priorities resulted in more than an order of magnitude of code complexity, compared to Nuklear. For instance, nice but fast anti-aliasing is hard. 16x hardware MSAA is often OK in terms of quality, but too slow on platforms like Raspberry Pi.
- seibelj 6y agoThis has been around a few years, it’s stable and used in some AAA-level games IIRC. Very neat project and makes putting a basic UX on a C program easy to do.
- imvetri 6y agoIt looks cool
- CyberRabbi 6y ago>C89 Very nice
- joeld42 6y agoI’m using this for a game, it’s working great. Takes some getting used to the layout model, and if you need complicated layout (I don’t), particularly more than one column of widgets, you probably don’t want to use the built in layout (the docs say this and suggest using a constraint solver, which seems like a good approach).
- dleslie 6y agoAh, last I had heard this project had been abandoned. I'm happy to see that a community team has picked it up, dusted it off, and is maintaining it.
- rafram 6y agoAs usual, though, an absolute accessibility nightmare. To screen readers, this is just a black box.
- pjmlp 6y agoEven on Web, in almost 40 years developing software, there was one single project where it did matter, the customer was part of a government organization. Like writing secure software, until this becomes a legal requirement no matter what, it will keep being ignored by the large community of developers.
- spijdar 6y ago> until this becomes a legal requirement no matter what, it will keep being ignored by the large community of developers. "no matter what"? One of the more popular uses for these immediate-mode UI toolkits is to create interfaces for video games, either debug UIs or the menus painted over the game's main scene/content. I don't think people who need a screen reader are going to be playing a twitch-reaction shooter game. I agree that these shouldn't be used for general use applications, but I strongly disagree with the sentiment that somehow all programs should be forced to work with screen readers. Some domains and applications are primarily visual and don't really translate well to textual interaction. I think these kinds of toolkits work best with those kinds of applications. You shouldn't use these to write the next Discord or Slack or Firefox or LibreOffice etc. -- but I don't see a problem with making a debug UI or a menu for an action video game with an immediate mode toolkit.
- curlypaul924 6y agoI would think the same thing, but playing video games blindfolded is a thing. Look up ponktus Super Metroid 100% blindfolded and zallard1/sinister1 2p1c blindfolded Punchout for examples. If it's possible for someone to beat these games blindfolded (at a competitive pace, no less!), then it's possible for a blind person to beat it too. The old consoles didn't have screen readers, but watching zallard1 play Wii Punchout blindfolded, I can see where they would help. Amazing fights, yet painful to watch when using the menu system.
- statico 6y agoThere's a demo that works in the browser: http://dexp.in/nuklear-webdemo/ http://dexp.in/nuklear-webdemo/
- flohofwoe 6y agoThis might provide a slightly better "experience" (it's about 10x smaller, doesn't look blurry on Retina displays, and doesn't suffer from the "touchpad taps are ignored" problem): https://floooh.github.io/sokol-html5/nuklear-sapp.html https://floooh.github.io/sokol-html5/nuklear-sapp.html
- yoz-y 6y agoThe radio and checkboxes are weird. Radio buttons seem intuitively inverted (empty circle is the selected one). Where as on checkboxes I think the filled square means checked but I can't say because of the weird radio buttons.
- yudlejoza 6y agoWondering if this was inspired by Wenzel Jakob's nanogui [0] by any chance. (cz that's what I wanted to do, rewrite nanogui in C, so I don't have to rely on a C++ compiler). The appeal of nanogui to me is that it's built on top of OpenGL. [0] https://github.com/wjakob/nanogui https://github.com/wjakob/nanogui
- enriquto 6y agoI don't understand... the documentation says "does not have any dependencies" but still it requires glfw3. Is that alright? Cannot compile the examples without glfw3 but maybe I'm doing something wrong.
- chrisseaton 6y agoI think in this context they mean it doesn't depend on any particular dependencies, but at some point you need a way to render their frame buffer. I guess you could trivially swap out glfw3 for something else, such as using the BIOS video mode directly.
- roblabla 6y agoNuklear doesn't have any dependency, but you must provide it a backend so it can do its drawing. The examples use a glfw3 backend, but you can provide any other backend, it's just a handful of functions to implement and is usually not too hard. See https://immediate-mode-ui.github.io/Nuklear/doc/nuklear.html#nuklear/api/drawing https://immediate-mode-ui.github.io/Nuklear/doc/nuklear.html...
- crazypython 6y agoInteresting. It seems like it would be fairly easy to write a WASM/Canvas2D port of it.
- symlinkk 6y agoThat’s called a dependency.
- enriquto 6y ago> Nuklear doesn't have any dependency, but you must provide it a backend so it can do its drawing. The examples use a glfw3 backend, but you can provide any other backend, it's just a handful of functions to implement and is usually not too hard. The text editor gcc doesn't have any dependency, but you must provide it a backend so it can do its text editing. The example uses a nano backend written in C, but you can provide any other backend like vim or emacs, it's just a handful of functions to implement and is usually not too hard.
- exDM69 6y agoI have used Nuklear in a medium sized hobby project, and it's kinda cool but I will be migrating away from it. I am not aware of it being used in shipped products, unlike Dear Imgui which is a more popular alternative. The first reason is that it doesn't have a good layout system requiring manually specifying positions and sizes in quite a few places and doesn't gracefully handle varying font sizes. My GUI code is littered with x*FONT_SIZE to do some kind of scaling to work on my low res 27" screen and a high res 13" laptop. I don't need it to do any magic behind the scenes with font sizes (such as moving from monitor to monitor), just allow setting the GUI font size to a reasonable value and sticking with it without manually specifying every row height. The motivation for this probably is that the author wanted to have extremely skinnable UI to be able to do fancy game UI's. However, if you look at a lot of modern game UIs they have a flat "material design" type of UI with flexbox-like layouts, and no fancy skinning, just flat colors and rounded corners. Another motivator is that Nuklear can run on triangle-based GPUs and pixel-pushing APIs. This is not valuable to me. The second reason is that it's buggy. The developers have taken to the extremes to avoid dependencies. This includes stuff like home-brewed implementation of printf. Which will hang in an infinite loop when you try to print a float that has INF value. With some hacking, I was able to make Nuklear use standard printf and some other standard library functions instead of the bundled implementations. I appreciate all the effort the developers have put into this, but it's not ready for prime time and expect to spend time fixing bugs if you'll use it. I'll probably be moving away from the immediate mode GUI paradigm as a whole (instead of using Dear Imgui or Nanogui), it's a poor fit for the application I'm developing. Recently I've been seeing a quite polished game UI toolkit used in several published games, like Rise of Industry and Space Haven. Does anyone know what this toolkit is? Something Unity offers or some proprietary library? On my spare time I've also worked on a retained mode flexbox-based UI layout and rendering library that integrates like Nuklear or Dear Imgui. In other words, the GUI library doesn't have any dependencies or have any side effects. You feed in a tree of GUI elements, the events coming from the windowing system and as output you get a vertex buffer and a list of triggered events. This concept shows some promise but unfortunately I don't seem to have the time it takes to turn this into a polished product. I'm happy to talk about it if anyone is interested.
- dkersten 6y ago
- einpoklum 6y agoI wonder how this compares with what's currently used in FOSS games. For example... what does Wesnoth use? More generally - is this really something that's missing? I mean, hasn't something very similar already been implemented (as FOSS, I mean)?
- mosaic_school 6y agoLooks amazing! The only thing missing for me to use it would be Vulkan support. I'm sure it will land soon and if not I guess I can put in the effort and make a patch/PR. =)
- soheil 6y agoHas anyone bundled this inside an Obj-C (/swift) app to see if it's possible to run this on an iPhone?
- jakearmitage 6y agoOther similar libraries: https://github.com/ocornut/imgui https://github.com/ocornut/imgui https://github.com/mitsuba-renderer/nanogui https://github.com/mitsuba-renderer/nanogui
- fao_ 6y agoAgain, this has no integration with accessibility software (AT-SPI/libatk), so please think twice about using it in production software.
- GirkovArpa 6y agoHow does this compare to Sciter? I understand this is primarily to overlay UIs over full screen applications (like games), but Sciter has that capability as well. Particularly how easy is it to style things, considering Sciter allows CSS? I did a CTRL+F for "sciter" and usually I find something, but this time, nope.
- WalterGR 6y agoAbout 400 comments worth of prior discussion: https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=Nuklear%20&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
- mcjkrw 6y agoLooks cool. How flexible is it? Can this be embedded in an existing C++ application to render a screen?
- mcjkrw 6y agoEdit: I just saw the other comments that it was written in C89 to have better support with C++, so I guess the answer is yes.