summaryrefslogtreecommitdiff
path: root/src/layout.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-03-12 15:29:23 -0700
committer3gg <3gg@shellblade.net>2026-03-12 15:29:23 -0700
commit92978a10576d52a0f6c9983d3b6afae7c40eff40 (patch)
treebf73faed8aa1ecd71b9f61c37a549faf4cd30372 /src/layout.c
parent58c0f40df5947b3933bf7b6564b2ba5dc39fbd92 (diff)
Support scrolling by dragging scrollbars
Diffstat (limited to 'src/layout.c')
-rw-r--r--src/layout.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/layout.c b/src/layout.c
index c8f5995..5261eb3 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -51,7 +51,7 @@ static void ResizeTable(uiTable* table, int width, int height) {
51 // Table contents. 51 // Table contents.
52 for (int row = 0; row < table->rows; ++row) { 52 for (int row = 0; row < table->rows; ++row) {
53 for (int col = 0; col < table->cols; ++col) { 53 for (int col = 0; col < table->cols; ++col) {
54 const uiCell* cell = GetCell(table, row, col); 54 const uiCell* cell = TableGetCell(table, row, col);
55 const int length = (int)string_length(cell->text); 55 const int length = (int)string_length(cell->text);
56 56
57 widths[col] = length > widths[col] ? length : widths[col]; 57 widths[col] = length > widths[col] ? length : widths[col];
@@ -110,13 +110,28 @@ static void ResizeTable(uiTable* table, int width, int height) {
110 } 110 }
111 111
112 // Now make room for the scroll bar, if necessary. 112 // Now make room for the scroll bar, if necessary.
113 uiScrollbar* scrollbar = &table->scrollbar;
113 if (table->flags.vertical_overflow) { 114 if (table->flags.vertical_overflow) {
114 const int offset = ScrollBarWidth / table->cols; 115 // Subtract room from table columns.
115 const int remainder = ScrollBarWidth % table->cols; 116 const int offset = ScrollbarWidth / table->cols;
117 const int remainder = ScrollbarWidth % table->cols;
116 for (int col = 0; col < table->cols; ++col) { 118 for (int col = 0; col < table->cols; ++col) {
117 table->widths[col] -= offset + (col < remainder ? 1 : 0); 119 table->widths[col] -= offset + (col < remainder ? 1 : 0);
118 assert(table->widths[col] >= 0); 120 assert(table->widths[col] >= 0);
119 } 121 }
122
123 // Set scrollbar layout.
124 scrollbar->width = ScrollbarWidth;
125 scrollbar->height = table->height;
126 scrollbar->handle_height =
127 (int)((double)table->num_visible_rows / (double)table->rows *
128 (double)table->height);
129 uiTableScroll(table, table->offset);
130 } else { // Scroll bar not visible.
131 scrollbar->width = 0;
132 scrollbar->height = 0;
133 scrollbar->handle_height = 0;
134 scrollbar->handle_y = 0;
120 } 135 }
121} 136}
122 137