15 ms·
Nuklear: A single-header ANSI C GUI library
- skibz 9y agoAn earlier discussion: https://news.ycombinator.com/item?id=11522452 https://news.ycombinator.com/item?id=11522452
- book_mentioned 9y agoMost likely re-submitted after being mentioned 2 days ago. https://news.ycombinator.com/item?id=16327918#16328912 https://news.ycombinator.com/item?id=16327918#16328912
- akmittal 9y agoIt looks quite nice also. Last time I saw it I wanted to port to to Go(not bindings) but could not find details docs about implementation. Anyone know how it is drawing OpenGL or native?
- badsectoracula 9y agoIt is API agnostic, you have to provide the functionality. There are some examples using various APIs here: https://github.com/vurtun/nuklear/tree/master/demo https://github.com/vurtun/nuklear/tree/master/demo
- gmueckl 9y agoNuklear isn't doing any actual rendering. It depends on other, platform-dependent code to do that. Look into the headers inside the demo folder to get an idea of how that works.
- frostburg 9y agoI used it once to provide a simple GUI for a some simulated annealing I had written in C, was more straightforward than I expected.
- hjek 9y agoIt's even got bindings for Chicken Scheme: http://wiki.call-cc.org/eggref/4/nuklear http://wiki.call-cc.org/eggref/4/nuklear
- TeMPOraL 9y agoAlso some for Common Lisp: https://github.com/borodust/bodge-nuklear https://github.com/borodust/bodge-nuklear They are purpose-built for a particular engine though, so I'm not sure how generally usable they are.
- borodust 9y agoThis one is a generic but full thin wrapper over Nuklear. It's not tied to cl-bodge in any way :) https://github.com/borodust/nuklear-blob https://github.com/borodust/nuklear-blob is an asdf system with loadable compiled shared libraries for it. Hopefully, it soon will be in the main quicklisp distribution.
- cryptos 9y agoNot the best name in times of Trump...
- lou1306 9y agoCould be a pun on Electron, though.
- akvadrako 9y agoYou can't build a "ANSI C GUI library", because ANSI C has no graphical capabilities.
- deleted 9y ago[deleted]
- jsd1982 9y agoIt is a GUI library written in ANSI C. Graphical capability is not a property of programming languages. It is an orthogonal matter.
- deleted 9y ago[deleted]
- badsectoracula 9y agoYou can if you rely on the library's users to provide the non-ANSI functionality (like Nuklear does - you have to provide the graphics and input functionality).
- deleted 9y ago[deleted]
- akvadrako 9y agoI would say the requirements of the functionality you have to provide define what kind of library it is. It's a very different thing if it's a raw framebuffer, OpenGL context, Carbon API, a terminal or something like WASM.
- EpicEng 9y agoC, the language, doesn't come with e.g. a MySQL driver either, but I'm pretty sure you can write one in C. If you're going to be pedantic at least be correct.
- akvadrako 9y agoI didn't say it wasn't written in C.
- zevv 9y agoI really do not understand why 'single header' is considered a good thing, but I see this more and more often on libraries. What is the reason all the code is put in the header file?
- kzrdude 9y agobecause dependency management and build systems are hard to get right and not standardized. It's a simple distribution model that works everywhere.
- badsectoracula 9y agoYes, but why a single header file and not a pair of .c and .h files (personally this is what i do for my small libs)? With a single header file you'd need the user to put it in a specially designated "this is the implementation" .c file anyway. I can see it for C++ which supports placing code in a header as a language, but C requires jumping over awkward preprocessor hoops that can be avoided by using a .c file.
- c-smile 9y agoWith .h only files, when you need to include needed functionality, you modify only your own source file. But with .c files, when you have multiplatform project, you need to put it in other "3rd party" tools. Think about the whole zoo: Visual Studio, XCode, Code::Blocks, make, NMake, etc.
- badsectoracula 9y agoWhy you need to do that with .c files? You can just drop the .c/.h pair into the same place as you would put the single .h file and the rest of your C/C++ files and use it like that.
- satysin 9y agoYou are free to split it into .h and .c if you want, every single header library I have used has an IMPLEMENTATION block to make doing so very simple.
- gnud 9y agoI'm guessing this deals with accessibility the same way most other 'light' UI toolkits do - by not dealing with it at all?
- mrtweetyhack 9y agoI don't see a problem.
- mwcampbell 9y agoCorrect. I started my own subthread on this subject: https://news.ycombinator.com/item?id=16347902 https://news.ycombinator.com/item?id=16347902
- chj 9y agoHow do you handle accessibility across Win/Mac/Linux?
- gnud 9y agoWell, you could use Qt...
- mwcampbell 9y agoBefore you use this in your next important application, please read the comment on accessibility that I posted the other day on the LCUI thread: https://news.ycombinator.com/item?id=16329640 https://news.ycombinator.com/item?id=16329640
- TeMPOraL 9y agoYour note is good in general, but for this particular case, note this is an immediate mode GUI library. I.e. the kind of stuff that's primarily used in videogames. A typical game (or supporting tool) where this is included would already be not accessible (imagine playing e.g. an RTS with a screen reader).
- mwcampbell 9y agoPoint taken. Some games, though, could be accessible if not for the way the UI was implemented. For example, repackaged text adventures. I downloaded the Lost Treasures of Infocom app for iOS, and it was completely useless with VoiceOver. Presumably because the dev at Activision who was working on this packaging used the same kind of UI toolkit that they always use for games. The same goes for turn-based strategy games, if it's feasible to provide text for all the graphics. Accessibility for games is definitely a much lower priority than accessibility for applications that are used in business, education, and everyday communication/social networking. Still, a blind person can feel excluded if their friends are playing a game that they can't play. Sometimes a given game can't be made accessible without changing the whole game mechanic. But that's not always the case. So, something to consider.
- TeMPOraL 9y agoI agree. It's good that you bring this up, and also great you provided some extra context about why you're doing this in another comment.
- bastijn 9y agoAccessibility is always important to mention, which is why we should thank you for reminding us. In return, you have to understand that not every next important application will be used by blind people or people with disabilities, and as of such there is still room for people to develop new UI toolkits if they so please. Again, thanks for reminding everybody. People need to think about it. Your advice could be toned down a bit to “please think about your audience, if you expect people with disabilities to be part of it think twice when making your own UI toolkit, or at least factor in the costs to build in accessibility features.”
- aphextron 9y agoIs there a good reason for having logic in an H file?
- rightbyte 9y agoNope, but less typing of #include:s? Easier to send by mail? He seems to use defines to keeps function and variable definitions to one in the program it's included in.
- pka 9y ago> No global or hidden state Does that mean that one can detach an input field, save its state somewhere, create a new one and attach it somewhere else again and have it appear exactly as it was before (i.e. cursor position, selection, focus, etc)? That's one of the pain points with VDOM frameworks (i.e. need to diff around UI components which shouldn't lose state), so I'm curious if this library gets it right.
- TeMPOraL 9y agoThere is no "input field", the UI state is entirely on your end :). This is immediate mode UI. It handles inputs and renders simultaneously. Consider a line from the example in the README: nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); That line is responsible for both drawing the slider (at a place determined by value, with min = 0, max = 1, step = 0.1) and setting the variable `value` to whatever position user is currently dragging the slider to. Or: if (nk_button_label(&ctx, "button")) { /* event handling */ } That simultaneously draws the button and executes the conditional if the button was just pressed. Immediate mode GUIs are used in games, where you think in terms of drawing frames, each visible for a fraction of a second. When using such GUI, you usually "clear" it at the beginning of the frame, feed it with input from current frame, then build up the UI at the same time as you're drawing it[0]. So basically, you're in total control of the state; there is no persistent "input field", you recreate it each frame with a function call, and it's up to you whether or not it's meaningfully the same input field as it was the last frame. -- [0] - most times, like in this case, "drawing" means you "build up" a list of display commands which then you feed to the renderer at the end - this lets an immediate mode GUI be independent of whatever graphics library you're using.
- jstimpfle 9y ago> It handles inputs and renders simultaneously. I'm not sure that's the point. I think it's a good idea to decouple input and output (render). The point of IMGUI vs traditional toolkits is, I think, rather that you don't have to communicate through an API to manipulate and sync state with the framework/library. The latter imposes lots of communication overhead and second guessing, and can't offer the same level of control.
- thecodeboy 9y agoWow! This is the first time I'm seeing a project having two licenses. MIT and unlicense. You can choose whichever you want.
- billsix 9y agoFor python fans, I've been working on pyNuklear https://github.com/billsix/pyNuklear https://github.com/billsix/pyNuklear
- technomalogical 9y agoMy first thought: I wonder if I can invoke this with ctypes from Python? I'll check this out, thanks!
- billsix 9y agoMy plan of action is result-driven: incrementally port nuklear's demo overview.c file to python. Each new piece of that requires adding more ctypes bindings. Help/patches are welcome, as I only have limited free time to implement this.
- ComputerGuru 9y agoReposting from a previous thread: I have not had a chance to try it out for myself yet, but I have recently learned that webkit includes a direct-to-opengl renderer such that one can skip the Qt or GTK backend and write HTML/CSS/JS that outputs to the framebuffer directly.
- random_upvoter 9y agoAs a small criticism, looking at the project page I get no clue whether this library works on Microsoft Windows.
- jstimpfle 9y ago"C89", "no dependencies". That pretty certainly means "yes".
- random_upvoter 9y ago"no depencies" until you actually want to use it. Because then of course you'll have to link with some non-standard library that can actually paint pixels on the screen. That was precisely what confused me.
- billsix 9y agoYes it works on windows. Hopefully this does not come across as rude, but from the readme "It was designed as a simple embeddable user interface for application and does not have any dependencies, a default renderbackend or OS window and input handling but instead provides a very modular library approach by using simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends it only focuses on the actual UI." Under the demo folder, there are examples. Nuklear works with opengl 2 and 3 both with sdl2 and glfw (both of which support windows) it works with direct 3d 9 and 11, with gdi (windows specific libraries)
- random_upvoter 9y agoYes, I did see the readme and I do remember thinking "so does this means it runs on Windows as well?". It's not unheard of for linux-specific projects to simply ignore the existence of Microsoft world. So I cloned the repository and opened up nuklear.h. If this library supports Windows, then CERTAINLY this file has to include "Windows.h", somewhere, right? Uhm.. no, it does not. Bad sign, I thought. So, still confused, I thought "so let's look into this folder called "example". I look into canvas.c and I notice "#include <GL/glew.h>". So I thought "Oh dear, this is gonna be a bother to compile on Windows, forget it". As luck would have it, I never looked into the folder called "demo". So at that point I honestly believed that this library was only sort of "semi-supported" on Windows, as often happens with these kind of projects. You know, the usual "if you're a bit of a masochist and you're willing to muck around with mingw and download glib.tar.gz stuff, you may get this to work". The fact that the GUI has a definite linux look reinforced that impression. What I'm saying is, all my confusion could have been solved by just one line in the readme explicitely stating "this builds on Microsoft Windows using Visual Studio and a direct X backend, etc...". A little bit of redundancy, it helps sometimes.
- faragon 9y agoAmazing. A great candidate to be included into suckless.org [1], in my opinion. [1] https://suckless.org/rocks https://suckless.org/rocks
- ericjang 9y agoNice. I also recommend checking out Nanogui (C++) by Wenzel Jakob: https://github.com/wjakob/nanogui https://github.com/wjakob/nanogui
- billsix 9y agoThe reason that I love immediate mode GUIs like nuklear and dearimgui is that, unlike callback based GUIs like nanogui, qt, gtk, wxwidgets etc, I do not need to learn how the framework Works internally in order to use it effectively. The lack of callbacks in particular, means that I do not need to worry about memory management very much. Or, I should say, I don't have to defer memory management to later. I own books on wxwidgets and on qt. To be honest, although I've read them fully, I still don't quite know how to use them well, nor how would I teach teammates how to even if I did. Using a tool like dearimgui or nuklear, I have no books, but 95% of the time I can just copy example code from the demo into my app, modify it slightly for my needs, and call it a day.
- geobourazanas 9y agoHey all, we are a team working toward democratising genetic testing. We are trying to gauge how much people know about genetic testing and what people feel about it. I have a super short form (4 questions only). Would really really appreciate some input from the good folks on this channel! https://joannavass.typeform.com/to/Vy18OL https://joannavass.typeform.com/to/Vy18OL
- mattlondon 9y agoGolang bindings: https://github.com/golang-ui/nuklear https://github.com/golang-ui/nuklear Never used it myself, but looks interesting considering the current state of go's UI programming options (i.e. fairly limited at the moment)
- xmichael99 9y agoC# Wrapper please!
- merlish 9y agoThere should be a link on the page. I started binding it to C# over Christmas out of frustration of one not existing, and someone else quickly picked it up and made a cleaner binding that I recommend more. Google NuklearDotNet for the latter.
- FraKtus 9y agoI love it because I can write applications for iOS macOS android windows and have most of the code identical. There is no need of resources to make that easy. Almost too good to be true.
- FraKtus 9y agoI could make an iOS application that is only 1 MB in size thanks to Nuklear.. More and more users will not want to try an app if it feels bloated. Nuklear allows to generate tiny binaries, I appreciate that.
- alok-g 9y agoQuestion: How easy or difficult would it be to make responsive UI's with this? Also, what would the performance be like as compared to native OS GUI controls?
- niutech 9y agoCheck out these alternative C++ GUI libs running in a web browser using WebAssembly: - AssortedWidgets: https://shi-yan.github.io/AssortedWidgets/ https://shi-yan.github.io/AssortedWidgets/ - Dear ImGUI: https://pbrfrat.com/post/imgui_in_browser.html https://pbrfrat.com/post/imgui_in_browser.html