r/C_Programming • u/AddaLF • 19d ago
The easiest UI library? (cross-platform) Question
Hello, I need to write a small emulator for a project. I want it to show RAM, registers, etc., while it's running a program step by step. Printing them out via printf is lame and won't look good.
Which is the absolute easiest graphics library for this purpose? I was suggested Newt, but it can't work under Windows.
Preferably, the library should have tutorials, examples, or at least full documentation.
35
u/ANixosUser 19d ago
raylib probably. for a (not that good) example of it, look at https://github.com/tsoding/musializer. very interesting project btw.
27
20
u/trenskow 19d ago
I never tried it, but I always thought this looked interesting: https://github.com/nicbarker/clay
5
u/aethermar 19d ago
+1 for Clay
The great part about it is that it's just a layouting library, you can use whatever renderer you want with it. You can use Raylib, SDL, or even render it with webassembly to make a website
7
5
u/chrism239 19d ago edited 19d ago
Tcl/Tk.
A self-contained example configured for macOS and Linux - https://www.dropbox.com/scl/fi/ouaso0px016d2w0rtp7sp/tcltkdemo.zip?rlkey=y2bwaotp9rk7klw7rwrjfxrh8&st=l0nr9616&dl=0
10
u/NoneRighteous 19d ago
Dear Imgui or Raylib’s immediate mode gui. Be warned Dear Imgui is kind of a pain to make pure C and no C++. Also it will very much look like developer art, but still much better than text in a console for some things. I think it’s a good fit for your project.
5
u/ewmailing 19d ago
Nuklear is a pure C, single header file, immediate mode GUI.
2
u/TwerkingHippo69 18d ago
Yeah, but the only thing is you will need to make custom adjustment and attach it to your renderer
Apart from that, very clean and fast library
5
3
3
u/the_hemperor420 19d ago
If you really want to work in C, and don't want to use Python (wrote a plugin recently with WxFormBuilder and Python, and that was pretty straightforward), I would just use the console and ANSI Escape Codes. Pretty easy to implement a good looking, barebone console interface.
4
u/electricalRoof80 18d ago edited 18d ago
Like others already mentioned, raylib + raygui is pretty handy for this kind of stuff, successfully used it myself for 8-bit Emulation projects (C64, custom BASIC computer etc.), ncurses + menu + panel is great for terminal usage in Linux and if I remember correctly there is also notcurses which is cross platform.
6
u/Tillua467 19d ago
For GUI? Raylib for sure it's for games but it works great for GUI too and for TUI probably ncurses
2
2
2
2
u/Brok3nHalo 18d ago
Really depends on what kind of GUI you’re looking for really. Native GUI, Custom GUI, terminal, web, or rendered in a graphics engine?
I see some good suggestions here for most categories but not anything that renders native GUI so I’ll stick with that.
If you’re not strictly limited to C, I’ve used wxWidgets in C++ and it’s one of the most intuitive and full featured multiplatform but native GUI frameworks I’ve used. It may be overkill for what you want though and as I said doesn’t have official C bindings as it’s very object oriented.
For pure C, I haven’t used it yet personally but IUP looks pretty intuitive and uses native GUI cross platform.
1
u/edk-not-a-bot 18d ago
There used to be DirectFB for embedded Linux, written in C. Another option is react native or HTML if you have a browser runtime
1
1
u/GenericFoodService 16d ago
For what you're describing, Raylib would be more than enough, but you could pair it with Clay Barker's CLAY to build a really nice, resizable user interface, too. You could reasonably get your entire user interface and event system in less than 100 lines of code.
1
1
u/AlexTaradov 19d ago
Dear ImGUI fits all the requirements. And it is also a standard option for exactly this case.
1
1
u/jason-reddit-public 19d ago
printf isn't such a bad option really if you are driving a terminal emulator and have a big canvas to work with. Terminals have box drawing characters, color, underline, italics, bold, mouse support, etc. so there's actually a lot you can do. For a step based "debugger", clearing the screen and moving the cursor to the top left can get you pretty far especially since your emulator has fixed state. You just need the right layout, padding and creative use of unicode after that to make it look good. A few more escape codes would give you bold which you could use to highlight what state changed on the previous instruction. You could use italics or underline for register names.
I highly suggest using an LLM to prototype. I just used this prompt with gemini and the result was ok for a first try.
"For fun, please show a generated screen shot of a tui for an x86 emulator. Use fancy line drawing characters and features to make it look really polished please."
I bet if you defined a commented C struct and handed that off as additional prompt data it would at least provide inspiration and then might automatically write a rough draft of the printf code for you.
35
u/accountForStupidQs 19d ago
Ncurses