SENIOR PRODUCT ENGINEER

UI.h: A Console UI Library for C and C++ in One Header

UI.h: A Console UI Library for C and C++ in One Header

A console can have an interface

C and C++ exercises usually run in a console with simple input and output. Students read a line, print a line, and the interface barely exists. UI.h was written to change that while keeping the familiar console.

The library was written for members of FPT Polytechnic. Users download the source, unzip it into the project folder and write `#include "lavenes.h"`. There is no separate installation step.

Drawing, positioning and color

The library includes functions to draw text at X and Y coordinates, move the cursor to a position, draw a square area, set the text and background colors, and clear the screen. On top of these are the interface parts: a header bar, radio boxes, buttons, text boxes and alerts.

The cost of mouse events

This is where the trade-off appears. To receive mouse and keyboard events, the program has to read each event one at a time. In that mode, `scanf` cannot read input. The user has to take the value from the keyboard event and store it in a variable.

In return, the library offers something a console usually lacks: a menu you can click, and control keys like a real application. The README states this at the top of the events section, so users are not surprised.

A library from 2021

UI.h was written in November 2021, in six commits. The library was developed under the name Lavenes, the name of my company. I planned the features, designed the library and wrote the code myself. The project is now archived.