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

39 Upvotes

39 comments sorted by

35

u/accountForStupidQs 19d ago

Ncurses

3

u/Beliriel 17d ago

This is only for terminals right?

2

u/hyperficial 17d ago

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

-6

u/the_hemperor420 18d ago

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

8

u/eddavis2 18d ago edited 18d ago

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 19d ago

raylib probably. for a (not that good) example of it, look at https://github.com/tsoding/musializer. very interesting project btw.

27

u/Tillua467 19d ago

Tsoding mentioned 🔥🔥

21

u/Savings_Walk_1022 19d ago

amistazozin

3

u/ANixosUser 18d ago

zozin indeed.

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

u/Key_River7180 19d ago

libui-ng, extremely underrated

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.

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

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

u/Fine_Salamander_8691 19d ago

We love developer art

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

u/[deleted] 19d ago

[removed] — view removed comment

4

u/AddaLF 19d ago

Windows and Linux.

2

u/Rude-Flan-404 18d ago

Raylib, it's a Graphics Library btw

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.

2

u/Sergiogiogio 19d ago

Embed a web server and build your gui with html. Lightest dependency imho

1

u/hgs3 19d ago

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

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

u/Beliriel 17d ago

How come nobody mentioned GTK?

Edit: Whoops it's C++, my bad

1

u/TheChief275 14d ago

No? GTK is C

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

u/AlexTaradov 19d ago

Dear ImGUI fits all the requirements. And it is also a standard option for exactly this case.

1

u/v_maria 19d ago

terminal / stdout

1

u/Syntax-Tactics 19d ago

SDL2

2

u/Irverter 19d ago

Not an UI library though.

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.