diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout.c | 14 | ||||
| -rw-r--r-- | src/render.c | 6 | ||||
| -rw-r--r-- | src/widget/table.c | 22 | ||||
| -rw-r--r-- | src/widget/widget.h | 2 |
4 files changed, 16 insertions, 28 deletions
diff --git a/src/layout.c b/src/layout.c index 62e1876..2b43ce8 100644 --- a/src/layout.c +++ b/src/layout.c | |||
| @@ -44,22 +44,18 @@ static void ResizeTable(uiTable* table, int width, int height) { | |||
| 44 | int* widths = table->widths; | 44 | int* widths = table->widths; |
| 45 | // Header. | 45 | // Header. |
| 46 | for (int col = 0; col < table->cols; ++col) { | 46 | for (int col = 0; col < table->cols; ++col) { |
| 47 | const uiCell* cell = &table->header[col]; | 47 | const uiCell* cell = &table->header[col]; |
| 48 | const uiLabel* label = (uiLabel*)cell->child; | 48 | const int length = (int)string_length(cell->text); |
| 49 | const int length = (int)string_length(label->text); | ||
| 50 | 49 | ||
| 51 | widths[col] = length; | 50 | widths[col] = length; |
| 52 | } | 51 | } |
| 53 | // Table contents. | 52 | // Table contents. |
| 54 | for (int row = 0; row < table->rows; ++row) { | 53 | for (int row = 0; row < table->rows; ++row) { |
| 55 | for (int col = 0; col < table->cols; ++col) { | 54 | for (int col = 0; col < table->cols; ++col) { |
| 56 | const uiCell* cell = GetCell(table, row, col); | 55 | const uiCell* cell = GetCell(table, row, col); |
| 57 | if (cell->child) { | 56 | const int length = (int)string_length(cell->text); |
| 58 | const uiLabel* label = (uiLabel*)cell->child; | ||
| 59 | const int length = (int)string_length(label->text); | ||
| 60 | 57 | ||
| 61 | widths[col] = length > widths[col] ? length : widths[col]; | 58 | widths[col] = length > widths[col] ? length : widths[col]; |
| 62 | } | ||
| 63 | } | 59 | } |
| 64 | } | 60 | } |
| 65 | // Multiply string lengths times glyph width to compute pixel size. | 61 | // Multiply string lengths times glyph width to compute pixel size. |
diff --git a/src/render.c b/src/render.c index f716e1a..2d3764a 100644 --- a/src/render.c +++ b/src/render.c | |||
| @@ -163,7 +163,6 @@ static void RenderText(const char* text, size_t length, RenderState* state) { | |||
| 163 | /// Render a frame. | 163 | /// Render a frame. |
| 164 | static void RenderFrame(const uiFrame* frame, RenderState* state) { | 164 | static void RenderFrame(const uiFrame* frame, RenderState* state) { |
| 165 | assert(frame); | 165 | assert(frame); |
| 166 | |||
| 167 | FillRect(&frame->widget.rect, uiBlack, state); | 166 | FillRect(&frame->widget.rect, uiBlack, state); |
| 168 | } | 167 | } |
| 169 | 168 | ||
| @@ -171,7 +170,6 @@ static void RenderFrame(const uiFrame* frame, RenderState* state) { | |||
| 171 | static void RenderLabel(const uiLabel* label, RenderState* state) { | 170 | static void RenderLabel(const uiLabel* label, RenderState* state) { |
| 172 | assert(label); | 171 | assert(label); |
| 173 | assert(state); | 172 | assert(state); |
| 174 | |||
| 175 | RenderText(string_data(label->text), string_length(label->text), state); | 173 | RenderText(string_data(label->text), string_length(label->text), state); |
| 176 | } | 174 | } |
| 177 | 175 | ||
| @@ -198,7 +196,7 @@ static void RenderTable(const uiTable* table, RenderState* state) { | |||
| 198 | &original_subsurface, &original_pen); | 196 | &original_subsurface, &original_pen); |
| 199 | 197 | ||
| 200 | const uiCell* cell = &table->header[col]; | 198 | const uiCell* cell = &table->header[col]; |
| 201 | RenderWidget(state, cell->child); | 199 | RenderText(string_data(cell->text), string_length(cell->text), state); |
| 202 | 200 | ||
| 203 | // Reset the original subsurface and pen for subsequent columns. | 201 | // Reset the original subsurface and pen for subsequent columns. |
| 204 | PopSubsurface(state, &original_subsurface, &original_pen); | 202 | PopSubsurface(state, &original_subsurface, &original_pen); |
| @@ -228,7 +226,7 @@ static void RenderTable(const uiTable* table, RenderState* state) { | |||
| 228 | state->pen.x = 0; | 226 | state->pen.x = 0; |
| 229 | 227 | ||
| 230 | const uiCell* cell = GetCell(table, row, col); | 228 | const uiCell* cell = GetCell(table, row, col); |
| 231 | RenderWidget(state, cell->child); | 229 | RenderText(string_data(cell->text), string_length(cell->text), state); |
| 232 | 230 | ||
| 233 | // Reset the original subsurface and pen for subsequent columns. | 231 | // Reset the original subsurface and pen for subsequent columns. |
| 234 | PopSubsurface(state, &original_subsurface, &original_pen); | 232 | PopSubsurface(state, &original_subsurface, &original_pen); |
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 | ||
| 88 | void uiTableSet(uiTable* table, int row, int col, uiPtr child) { | 88 | void 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 | |||
| 95 | const uiWidget* uiTableGet(const uiTable* table, int row, int col) { | ||
| 96 | assert(table); | ||
| 97 | return GetCell(table, row, col)->child; | ||
| 98 | } | 92 | } |
| 99 | 93 | ||
| 100 | uiWidget* uiTableGetMut(uiTable* table, int row, int col) { | 94 | const 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. |
| 37 | typedef struct uiCell { | 37 | typedef struct uiCell { |
| 38 | uiWidget* child; | 38 | string text; |
| 39 | } uiCell; | 39 | } uiCell; |
| 40 | 40 | ||
| 41 | /// Table. | 41 | /// Table. |
