r/C_Programming • • 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

39 comments sorted by

37

u/accountForStupidQs Jul 22 '26

Ncurses

3

u/Beliriel Jul 24 '26

This is only for terminals right?

2

u/hyperficial Jul 24 '26

For sufficiently simple UIs you can also directly print out ANSI codes and not rely on any dependencies (e.g. a constantly refreshing display of a few lines)

Pair this with termios.h for real-time keyboard input

-5

u/the_hemperor420 Jul 23 '26

That isn't really cross-plattform tho, but it's still a cool lib

8

u/eddavis2 Jul 23 '26 edited Jul 23 '26

How do you define cross-platform? From the ncurses website - ncurses downloads - it is available for:

  • Win32 console (32 and 64 bit) since v5.8 of ncurses in 2011
  • Linux
  • MacOS
  • BSD
  • UNIX

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.

27

u/Tillua467 Jul 22 '26

Tsoding mentioned 🔥🔥

21

u/Savings_Walk_1022 Jul 22 '26

amistazozin

3

u/ANixosUser Jul 23 '26

zozin indeed.

21

u/trenskow Jul 22 '26

I never tried it, but I always thought this looked interesting: https://github.com/nicbarker/clay

5

u/aethermar Jul 22 '26

+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

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.

6

u/ewmailing Jul 22 '26

Nuklear is a pure C, single header file, immediate mode GUI.

https://github.com/immediate-mode-ui/nuklear

2

u/TwerkingHippo69 Jul 23 '26

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

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/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/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/hgs3 Jul 22 '26

Alternatively, you can build a lightweight app that uses each platforms native web control. See here and here.

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/TheChief275 Jul 27 '26

No? GTK is C

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/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

2

u/Irverter Jul 22 '26

Not an UI library though.

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

4

u/AddaLF Jul 22 '26

Windows and Linux.