From 68a3532728b55b73d8bcadb8ccfc1d9396346cd2 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 13 Jul 2024 11:44:32 -0700 Subject: Basic table scrollbar rendering. --- src/render.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/render.c') diff --git a/src/render.c b/src/render.c index 24490c0..b1fd3e8 100644 --- a/src/render.c +++ b/src/render.c @@ -186,6 +186,8 @@ static void RenderTable(const uiTable* table, RenderState* state) { uiRect original_subsurface = {0}; uiPoint original_pen = {0}; + int col_widths_sum = 0; + // Render header. if (table->header) { for (int col = 0; col < table->cols; ++col) { @@ -201,6 +203,9 @@ static void RenderTable(const uiTable* table, RenderState* state) { // Reset the original subsurface and pen for subsequent columns. PopSubsurface(state, &original_subsurface, &original_pen); + // Keep track of the sum of column widths to later render the scroll bar. + col_widths_sum += table->widths[col]; + // Next column. state->pen.x += table->widths[col]; } @@ -235,6 +240,23 @@ static void RenderTable(const uiTable* table, RenderState* state) { state->pen.y += g_ui.font->header.glyph_height; } state->pen.y = y0; + + // Render scrollbar. + if (table->flags.vertical_overflow) { + state->pen.x = col_widths_sum; + + const int y_start = (int)((double)table->offset / (double)table->rows * + (double)table->height); + + const int height = (int)((double)table->num_visible_rows / + (double)table->rows * (double)table->height); + + FillRect( + &(uiRect){.y = y_start, .width = ScrollBarWidth, .height = height}, + uiPink, state); + + state->pen.x = x0; + } } /// Render a widget. -- cgit v1.2.3