summaryrefslogtreecommitdiff
path: root/src/widget
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-03-08 10:12:57 -0700
committer3gg <3gg@shellblade.net>2026-03-08 10:13:29 -0700
commit89188be968ac39e0e12077e6b596efaf00d06986 (patch)
tree725b290d574f6a284631a4c70e4212031420751c /src/widget
parent7f2987db18e515aec099a281fb4499fad8ffd4e0 (diff)
Store strings inside table cells for simplicity
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/table.c22
-rw-r--r--src/widget/widget.h2
2 files changed, 9 insertions, 15 deletions
diff --git a/src/widget/table.c b/src/widget/table.c
index 7a0ea03..dfb2e69 100644
--- a/src/widget/table.c
+++ b/src/widget/table.c
@@ -33,7 +33,7 @@ uiTable* uiMakeTable(int rows, int cols, const char** header) {
33 33
34 if (header) { 34 if (header) {
35 for (int col = 0; col < cols; ++col) { 35 for (int col = 0; col < cols; ++col) {
36 table->header[col].child = (uiWidget*)uiMakeLabel(header[col]); 36 table->header[col].text = string_new(header[col]);
37 } 37 }
38 } 38 }
39 39
@@ -47,7 +47,7 @@ void uiTableClear(uiTable* table) {
47 if (table->cells) { 47 if (table->cells) {
48 for (int row = 0; row < table->rows; ++row) { 48 for (int row = 0; row < table->rows; ++row) {
49 for (int col = 0; col < table->cols; ++col) { 49 for (int col = 0; col < table->cols; ++col) {
50 DestroyWidget(&table->cells[row][col].child); 50 string_del(&table->cells[row][col].text);
51 } 51 }
52 free(table->cells[row]); 52 free(table->cells[row]);
53 } 53 }
@@ -81,23 +81,17 @@ void uiTableAddRow(uiTable* table, const char** row) {
81 uiCell* lastRow = *pLastRow; 81 uiCell* lastRow = *pLastRow;
82 82
83 for (int col = 0; col < table->cols; ++col) { 83 for (int col = 0; col < table->cols; ++col) {
84 lastRow[col].child = (uiWidget*)uiMakeLabel(row[col]); 84 lastRow[col].text = string_new(row[col]);
85 } 85 }
86} 86}
87 87
88void uiTableSet(uiTable* table, int row, int col, uiPtr child) { 88void uiTableSet(uiTable* table, int row, int col, const char* text) {
89 assert(table); 89 assert(table);
90 assert(child.widget); 90 assert(text);
91 91 GetCellMut(table, row, col)->text = string_new(text);
92 GetCellMut(table, row, col)->child = child.widget;
93}
94
95const uiWidget* uiTableGet(const uiTable* table, int row, int col) {
96 assert(table);
97 return GetCell(table, row, col)->child;
98} 92}
99 93
100uiWidget* uiTableGetMut(uiTable* table, int row, int col) { 94const char* uiTableGet(const uiTable* table, int row, int col) {
101 assert(table); 95 assert(table);
102 return GetCellMut(table, row, col)->child; 96 return string_data(GetCell(table, row, col)->text);
103} 97}
diff --git a/src/widget/widget.h b/src/widget/widget.h
index 79a72f3..38acb9c 100644
--- a/src/widget/widget.h
+++ b/src/widget/widget.h
@@ -35,7 +35,7 @@ typedef struct uiLabel {
35 35
36/// Table cell. 36/// Table cell.
37typedef struct uiCell { 37typedef struct uiCell {
38 uiWidget* child; 38 string text;
39} uiCell; 39} uiCell;
40 40
41/// Table. 41/// Table.