From af641426fad35cd857c1f14bda523db3d85a70cd Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 May 2024 16:44:28 -0700 Subject: Initial commit. --- include/ui.h | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 include/ui.h (limited to 'include/ui.h') diff --git a/include/ui.h b/include/ui.h new file mode 100644 index 0000000..43bb2e7 --- /dev/null +++ b/include/ui.h @@ -0,0 +1,136 @@ +#pragma once + +#include +#include + +typedef uint8_t uiChannel; + +typedef struct uiPixel { + uiChannel r, g, b, a; +} uiPixel; + +typedef struct uiSize { + int width; + int height; +} uiSize; + +/// A UI surface to which widgets are rendered. +typedef struct uiSurface { + int width; + int height; + uiPixel* pixels; +} uiSurface; + +/// Rectangle. +/// (x,y) is the top-left corner. +typedef struct uiRect { + int x; + int y; + int width; + int height; +} uiRect; + +/// Point. +typedef struct uiPoint { + int x; + int y; +} uiPoint; + +/// Widget type. +typedef enum uiWidgetType { + uiTypeButton, + uiTypeFrame, + uiTypeLabel, + uiTypeTable, + uiTypeMax, +} uiWidgetType; + +typedef struct uiButton uiButton; +typedef struct uiFrame uiFrame; +typedef struct uiLabel uiLabel; +typedef struct uiTable uiTable; +typedef struct uiWidget uiWidget; + +/// Widget pointer. +typedef struct uiWidgetPtr { + uiWidgetType type; + union { + uiButton* button; + uiFrame* frame; + uiLabel* label; + uiTable* table; + uiWidget* widget; + }; +} uiWidgetPtr; + +// ----------------------------------------------------------------------------- +// Library. + +/// Initialize the UI library. +/// This should be called once during application startup. +bool uiInit(void); + +/// Shutdown the UI library. +/// This should be called once during application shutdown. +void uiShutdown(void); + +// ----------------------------------------------------------------------------- +// Widget. + +uiWidgetPtr uiMakeButtonPtr(uiButton*); +uiWidgetPtr uiMakeFramePtr(uiFrame*); +uiWidgetPtr uiMakeLabelPtr(uiLabel*); +uiWidgetPtr uiMakeTablePtr(uiTable*); + +void uiWidgetSetParent(uiWidgetPtr child, uiWidgetPtr parent); + +// ----------------------------------------------------------------------------- +// Button. + +/// Create a button. +uiButton* uiMakeButton(const char* text); + +// ----------------------------------------------------------------------------- +// Frame. + +/// Create a frame. +uiFrame* uiMakeFrame(void); + +/// Destroy the frame. +void uiDestroyFrame(uiFrame**); + +/// Resize the frame. +void uiResizeFrame(uiFrame*, int width, int height); + +/// Get the frame's dimensions. +uiSize uiGetFrameSize(const uiFrame*); + +// ----------------------------------------------------------------------------- +// Label. + +/// Create a label. +uiLabel* uiMakeLabel(const char* text); + +// ----------------------------------------------------------------------------- +// Table. + +/// Create a table. +uiTable* uiMakeTable(int rows, int cols, const char** header); + +/// Add a row. +void uiTableAddRow(uiTable*, const char** row); + +/// Set the table's cell. +void uiTableSet(uiTable*, int row, int col, uiWidgetPtr widget); + +/// Get the table's cell. +const uiWidget* uiTableGet(const uiTable*, int row, int col); + +/// Get the table's cell. +uiWidget* uiTableGetMut(uiTable*, int row, int col); + +// ----------------------------------------------------------------------------- +// Rendering. + +/// Render the frame. +void uiRender(const uiFrame*, uiSurface*); -- cgit v1.2.3