diff options
Diffstat (limited to 'src/widget/table.c')
| -rw-r--r-- | src/widget/table.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widget/table.c b/src/widget/table.c index e7d412e..d9a6440 100644 --- a/src/widget/table.c +++ b/src/widget/table.c | |||
| @@ -3,11 +3,12 @@ | |||
| 3 | #define Min(a, b) ((a) < (b) ? (a) : (b)) | 3 | #define Min(a, b) ((a) < (b) ? (a) : (b)) |
| 4 | #define Max(a, b) ((a) > (b) ? (a) : (b)) | 4 | #define Max(a, b) ((a) > (b) ? (a) : (b)) |
| 5 | 5 | ||
| 6 | uiTable* uiMakeTable(int rows, int cols, const char** header) { | 6 | uiTable* uiMakeTable(uiPtr parent, int rows, int cols, const char** header) { |
| 7 | uiTable* table = UI_NEW(uiTable); | 7 | uiTable* table = UI_NEW(uiTable); |
| 8 | 8 | ||
| 9 | *table = (uiTable){ | 9 | *table = (uiTable){ |
| 10 | .widget = (uiWidget){.type = uiTypeTable}, | 10 | .widget = |
| 11 | (uiWidget){.type = uiTypeTable, .stretch = (uiStretchX | uiStretchY)}, | ||
| 11 | .rows = rows, | 12 | .rows = rows, |
| 12 | .cols = cols, | 13 | .cols = cols, |
| 13 | .widths = (cols > 0) ? calloc(cols, sizeof(int)) : 0, | 14 | .widths = (cols > 0) ? calloc(cols, sizeof(int)) : 0, |
| @@ -15,6 +16,7 @@ uiTable* uiMakeTable(int rows, int cols, const char** header) { | |||
| 15 | .cells = (rows * cols > 0) ? calloc(rows, sizeof(uiCell*)) : 0, | 16 | .cells = (rows * cols > 0) ? calloc(rows, sizeof(uiCell*)) : 0, |
| 16 | .flags = {0}, | 17 | .flags = {0}, |
| 17 | }; | 18 | }; |
| 19 | WidgetSetParent(uiMakeTablePtr(table), parent); | ||
| 18 | 20 | ||
| 19 | if (header) { | 21 | if (header) { |
| 20 | for (int col = 0; col < cols; ++col) { | 22 | for (int col = 0; col < cols; ++col) { |
| @@ -91,13 +93,14 @@ void SyncScrollbarToTable(uiTable* table) { | |||
| 91 | assert(table); | 93 | assert(table); |
| 92 | ScrollbarScroll( | 94 | ScrollbarScroll( |
| 93 | &table->scrollbar, (int)((double)table->offset / (double)table->rows * | 95 | &table->scrollbar, (int)((double)table->offset / (double)table->rows * |
| 94 | (double)table->height)); | 96 | (double)table->widget.rect.height)); |
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | void SyncTableToScrollbar(uiTable* table) { | 99 | void SyncTableToScrollbar(uiTable* table) { |
| 98 | assert(table); | 100 | assert(table); |
| 99 | table->offset = (int)((double)table->scrollbar.handle_y / | 101 | table->offset = |
| 100 | (double)table->height * (double)table->rows); | 102 | (int)((double)table->scrollbar.handle_y / |
| 103 | (double)table->widget.rect.height * (double)table->rows); | ||
| 101 | } | 104 | } |
| 102 | 105 | ||
| 103 | const uiCell* TableGetCell(const uiTable* table, int row, int col) { | 106 | const uiCell* TableGetCell(const uiTable* table, int row, int col) { |
