summaryrefslogtreecommitdiff
path: root/src/widget/widget.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget/widget.h')
-rw-r--r--src/widget/widget.h49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/widget/widget.h b/src/widget/widget.h
index 63f3d94..db11164 100644
--- a/src/widget/widget.h
+++ b/src/widget/widget.h
@@ -16,39 +16,42 @@ typedef struct uiWidget {
16 Widget_list children; 16 Widget_list children;
17} uiWidget; 17} uiWidget;
18 18
19/// Button.
20typedef struct uiButton { 19typedef struct uiButton {
21 uiWidget widget; 20 uiWidget widget;
22 string text; 21 string text;
23} uiButton; 22} uiButton;
24 23
25/// Frame.
26typedef struct uiFrame { 24typedef struct uiFrame {
27 uiWidget widget; 25 uiWidget widget;
28} uiFrame; 26} uiFrame;
29 27
30/// Label.
31typedef struct uiLabel { 28typedef struct uiLabel {
32 uiWidget widget; 29 uiWidget widget;
33 string text; 30 string text;
34} uiLabel; 31} uiLabel;
35 32
36/// Table cell. 33typedef struct uiScrollbar {
34 int width;
35 int height; // Total height: handle plus scrollable area.
36 int handle_height; // Height of the scroll handle.
37 int handle_y; // Starting y-coordinate of the handle.
38} uiScrollbar;
39
37typedef struct uiCell { 40typedef struct uiCell {
38 string text; 41 string text;
39} uiCell; 42} uiCell;
40 43
41/// Table.
42typedef struct uiTable { 44typedef struct uiTable {
43 uiWidget widget; 45 uiWidget widget;
44 int rows; 46 int rows;
45 int cols; 47 int cols;
46 int height; // Height in pixels. 48 int height; // Height in pixels.
47 int* widths; // Width, in pixels, for each column. 49 int* widths; // Width, in pixels, for each column.
48 uiCell* header; // If non-null, row of 'cols' header cells. 50 uiCell* header; // If non-null, row of 'cols' header cells.
49 uiCell** cells; // Array of 'rows' rows, each of 'cols' cells. 51 uiCell** cells; // Array of 'rows' rows, each of 'cols' cells.
50 int offset; // Offset into the rows of the table. Units: rows. 52 int offset; // Offset into the rows of the table. Units: rows.
51 int num_visible_rows; // The number of rows that are visible at once. 53 int num_visible_rows; // The number of rows that are visible at once.
54 uiScrollbar scrollbar;
52 struct { 55 struct {
53 bool vertical_overflow : 1; // True if contents overflow vertically. 56 bool vertical_overflow : 1; // True if contents overflow vertically.
54 } flags; 57 } flags;
@@ -56,14 +59,24 @@ typedef struct uiTable {
56 59
57void DestroyWidget(uiWidget** ppWidget); 60void DestroyWidget(uiWidget** ppWidget);
58 61
59const uiCell* GetCell(const uiTable* table, int row, int col); 62/// Set the scrollbar handle's y-coordinate, which is clipped to the scrollbar's
60uiCell* GetCellMut(uiTable* table, int row, int col); 63/// rectangle.
61uiCell** GetLastRow(uiTable* table); 64///
65/// Return the handle's y-coordinate after clipping.
66int ScrollbarScroll(uiScrollbar*, int y);
62 67
63#define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE)) 68const uiCell* TableGetCell(const uiTable*, int row, int col);
69uiCell* TableGetCellMut(uiTable*, int row, int col);
70uiCell** TableGetLastRow(uiTable*);
71void SyncScrollbarToTable(uiTable*);
72void SyncTableToScrollbar(uiTable*);
73
74static inline int Min(int a, int b) { return a < b ? a : b; }
75static inline int Max(int a, int b) { return a > b ? a : b; }
64 76
65static inline void* uiAlloc(size_t count, size_t size) { 77static inline void* uiAlloc(size_t count, size_t size) {
66 void* mem = calloc(count, size); 78 void* mem = calloc(count, size);
67 ASSERT(mem); 79 ASSERT(mem);
68 return mem; 80 return mem;
69} 81}
82#define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE))