From 92978a10576d52a0f6c9983d3b6afae7c40eff40 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 12 Mar 2026 15:29:23 -0700 Subject: Support scrolling by dragging scrollbars --- src/layout.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/layout.c') 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) { // Table contents. for (int row = 0; row < table->rows; ++row) { for (int col = 0; col < table->cols; ++col) { - const uiCell* cell = GetCell(table, row, col); + const uiCell* cell = TableGetCell(table, row, col); const int length = (int)string_length(cell->text); widths[col] = length > widths[col] ? length : widths[col]; @@ -110,13 +110,28 @@ static void ResizeTable(uiTable* table, int width, int height) { } // Now make room for the scroll bar, if necessary. + uiScrollbar* scrollbar = &table->scrollbar; if (table->flags.vertical_overflow) { - const int offset = ScrollBarWidth / table->cols; - const int remainder = ScrollBarWidth % table->cols; + // Subtract room from table columns. + const int offset = ScrollbarWidth / table->cols; + const int remainder = ScrollbarWidth % table->cols; for (int col = 0; col < table->cols; ++col) { table->widths[col] -= offset + (col < remainder ? 1 : 0); assert(table->widths[col] >= 0); } + + // Set scrollbar layout. + scrollbar->width = ScrollbarWidth; + scrollbar->height = table->height; + scrollbar->handle_height = + (int)((double)table->num_visible_rows / (double)table->rows * + (double)table->height); + uiTableScroll(table, table->offset); + } else { // Scroll bar not visible. + scrollbar->width = 0; + scrollbar->height = 0; + scrollbar->handle_height = 0; + scrollbar->handle_y = 0; } } -- cgit v1.2.3