r/C_Programming • u/AddaLF • Jul 22 '26
Question The easiest UI library? (cross-platform)
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.
42
Upvotes
37
u/accountForStupidQs Jul 22 '26
Ncurses
35
u/ANixosUser Jul 22 '26
raylib probably. for a (not that good) example of it, look at https://github.com/tsoding/musializer. very interesting project btw.
21
u/trenskow Jul 22 '26
I never tried it, but I always thought this looked interesting: https://github.com/nicbarker/clay
6
u/Key_River7180 Jul 22 '26
libui-ng, extremely underrated
10
u/NoneRighteous Jul 22 '26
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/chrism239 Jul 22 '26 edited Jul 22 '26
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
4
u/electricalRoof80 Jul 23 '26 edited Jul 23 '26
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.
3
u/DescriptionOptimal15 Jul 22 '26
Termbox
3
u/the_hemperor420 Jul 22 '26
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.
5
u/Tillua467 Jul 22 '26
For GUI? Raylib for sure it's for games but it works great for GUI too and for TUI probably ncurses
2
u/RedWineAndWomen Jul 22 '26
nappgui
2
u/Rude-Flan-404 Jul 23 '26
Raylib, it's a Graphics Library btw
2
u/Brok3nHalo Jul 23 '26
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.
2
u/Sergiogiogio Jul 22 '26
Embed a web server and build your gui with html. Lightest dependency imho
1
u/edk-not-a-bot Jul 23 '26
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
u/Beliriel Jul 24 '26
How come nobody mentioned GTK?
Edit: Whoops it's C++, my bad
1
u/GenericFoodService Jul 25 '26
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
u/No_Bookkeeper_9603 Jul 22 '26
LVGL
1
u/AlexTaradov Jul 22 '26
Dear ImGUI fits all the requirements. And it is also a standard option for exactly this case.
0
u/v_maria Jul 22 '26
terminal / stdout
1
u/Syntax-Tactics Jul 22 '26
SDL2
1
u/jason-reddit-public Jul 22 '26
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.
2
u/[deleted] Jul 22 '26
[removed] — view removed comment