From a4294e4a94189dffb1fdf99c9a60d87d77272926 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 13 Jul 2024 10:52:24 -0700 Subject: Restructure project. --- src/widget/widget.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/widget/widget.h (limited to 'src/widget/widget.h') diff --git a/src/widget/widget.h b/src/widget/widget.h new file mode 100644 index 0000000..a2c96bc --- /dev/null +++ b/src/widget/widget.h @@ -0,0 +1,66 @@ +#pragma once + +#include + +#include +#include + +#include + +DEF_LIST(Widget, uiWidget*) + +#define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE)) + +static inline void* uiAlloc(size_t count, size_t size) { + void* mem = calloc(count, size); + ASSERT(mem); + return mem; +} + +// ----------------------------------------------------------------------------- +// Widgets. + +/// Base widget type. +typedef struct uiWidget { + uiWidgetType type; + uiRect rect; + Widget_list children; +} uiWidget; + +/// Button. +typedef struct uiButton { + uiWidget widget; + string text; +} uiButton; + +/// Frame. +typedef struct uiFrame { + uiWidget widget; +} uiFrame; + +/// Label. +typedef struct uiLabel { + uiWidget widget; + string text; +} uiLabel; + +/// Table cell. +typedef struct uiCell { + uiWidget* child; +} uiCell; + +/// Table. +typedef struct uiTable { + uiWidget widget; + int rows; + int cols; + int* widths; // Width, in pixels, for each column. + uiCell* header; // If non-null, row of 'cols' header cells. + uiCell** cells; // Array of 'rows' rows, each of 'cols' cells. + int offset; // Offset into the rows of the table. Units: rows. + struct { + bool vertical_overflow : 1; // True if contents overflow vertically. + } flags; +} uiTable; + +void DestroyWidget(uiWidget** ppWidget); -- cgit v1.2.3