Sunday, October 6

Microui+fenster=Small GUI

September 7, 2024

Often I simply wish to put pixels on a screen. I do not wish to think of SDL this or OpenGL that– I simply wish to draw my pixel buffer and be done.

fenster, a small 2D canvas library by Serge Zaitsev, does simply that. It’s a small drop-in header-only C/C++ file that weighs no greater than 400 LOC of quite legible code. It deals with WinAPI, Cocoa, and X11. And it deals with keyboard and mouse input, too!

In some cases I wish to do simply a little bit more than draw pixels– possibly have a menu, some buttons, render text– and I do not wish to totally DIY however I still do not wish to consider SDL.

Microui by rxi exists and manages the translation from GUI aspects into an easy retargetable illustration bytecode. It’s likewise a little, drop-in library, weighing just 1500 LOC.

The demonstration program utilizes SDL as a backend for the bytecode. I ‘d been suggesting to see if I might rather utilize fenster however comprehending what a “quad” was or what “glScissor” did appeared daunting. The job went no place.

As typical, Kartik and I had a little argument and that resulted in us producing the fenster backend for microui! I sent him a skeleton to reveal what I wished to do and he did the majority of the heavy lifting for the OpenGL-like parts.

The outcome is a less than 250 LOC file that binds microui to fenster. It’s influenced by the SDL renderer demonstration, however with a number of included functions to abstract away secrets and mouse buttons. It’s hacky and there’s some things we still do not comprehend, however it works! And by “works” I suggest draws the anticipated demo windows, deals with mouse hover and click, and manages keyboard input.

Things delegated find out:

  • How to figure out when to render from the texture and when from the offered drawing command’s color
  • Mod secrets thus that, for instance, Shift +1 renders!
  • Scrolling

Inspect it out here. It’s created to all be dropped straight into your job.

ยป …
Find out more