diff options
Diffstat (limited to 'src/widget/widget.h')
| -rw-r--r-- | src/widget/widget.h | 49 |
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. | ||
| 20 | typedef struct uiButton { | 19 | typedef struct uiButton { |
| 21 | uiWidget widget; | 20 | uiWidget widget; |
| 22 | string text; | 21 | string text; |
| 23 | } uiButton; | 22 | } uiButton; |
| 24 | 23 | ||
| 25 | /// Frame. | ||
| 26 | typedef struct uiFrame { | 24 | typedef struct uiFrame { |
| 27 | uiWidget widget; | 25 | uiWidget widget; |
| 28 | } uiFrame; | 26 | } uiFrame; |
| 29 | 27 | ||
| 30 | /// Label. | ||
| 31 | typedef struct uiLabel { | 28 | typedef struct uiLabel { |
| 32 | uiWidget widget; | 29 | uiWidget widget; |
| 33 | string text; | 30 | string text; |
| 34 | } uiLabel; | 31 | } uiLabel; |
| 35 | 32 | ||
| 36 | /// Table cell. | 33 | typedef 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 | |||
| 37 | typedef struct uiCell { | 40 | typedef struct uiCell { |
| 38 | string text; | 41 | string text; |
| 39 | } uiCell; | 42 | } uiCell; |
| 40 | 43 | ||
| 41 | /// Table. | ||
| 42 | typedef struct uiTable { | 44 | typedef 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 | ||
| 57 | void DestroyWidget(uiWidget** ppWidget); | 60 | void DestroyWidget(uiWidget** ppWidget); |
| 58 | 61 | ||
| 59 | const uiCell* GetCell(const uiTable* table, int row, int col); | 62 | /// Set the scrollbar handle's y-coordinate, which is clipped to the scrollbar's |
| 60 | uiCell* GetCellMut(uiTable* table, int row, int col); | 63 | /// rectangle. |
| 61 | uiCell** GetLastRow(uiTable* table); | 64 | /// |
| 65 | /// Return the handle's y-coordinate after clipping. | ||
| 66 | int ScrollbarScroll(uiScrollbar*, int y); | ||
| 62 | 67 | ||
| 63 | #define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE)) | 68 | const uiCell* TableGetCell(const uiTable*, int row, int col); |
| 69 | uiCell* TableGetCellMut(uiTable*, int row, int col); | ||
| 70 | uiCell** TableGetLastRow(uiTable*); | ||
| 71 | void SyncScrollbarToTable(uiTable*); | ||
| 72 | void SyncTableToScrollbar(uiTable*); | ||
| 73 | |||
| 74 | static inline int Min(int a, int b) { return a < b ? a : b; } | ||
| 75 | static inline int Max(int a, int b) { return a > b ? a : b; } | ||
| 64 | 76 | ||
| 65 | static inline void* uiAlloc(size_t count, size_t size) { | 77 | static 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)) | ||
