From db6f54c9f739369903169c59d2651389c0a4ed75 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:05:58 +0300 Subject: [PATCH] Draw scroll bar. --- UnleashedRecomp/ui/options_menu.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 6632c112..baa17b65 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -345,7 +345,7 @@ static void DrawCategories() ResetGradient(); } - drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, clipRectMax); + drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, { clipRectMax.x - gridSize * 2.0f, clipRectMax.y }); } template @@ -359,7 +359,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, const ConfigDef constexpr ImU32 COLOR1 = IM_COL32(0x92, 0xFF, 0x31, 0x80); auto gridSize = Scale(GRID_SIZE); - auto optionWidth = gridSize * 56.0f; + auto optionWidth = gridSize * 54.0f; auto optionHeight = gridSize * 5.5f; auto optionPadding = gridSize * 0.5f; auto valueWidth = Scale(192.0f); @@ -540,6 +540,24 @@ static void DrawConfigOptions() if (g_firstVisibleRowIndex + visibleRowCount - 1 < g_selectedRowIndex) g_firstVisibleRowIndex = std::max(0, g_selectedRowIndex - visibleRowCount + 1); + + // Pop clip rect from DrawCategories + drawList->PopClipRect(); + + // Draw scroll bar + if (rowCount > visibleRowCount) + { + float totalHeight = (clipRectMax.y - clipRectMin.y); + float heightRatio = float(visibleRowCount) / float(rowCount); + float offsetRatio = float(g_firstVisibleRowIndex) / float(rowCount); + float minY = offsetRatio * totalHeight + clipRectMin.y; + + drawList->AddRectFilled( + { clipRectMax.x + gridSize, minY }, + { clipRectMax.x + gridSize * 2.0f, minY + totalHeight * heightRatio }, + IM_COL32(0, 128, 0, 255) + ); + } } void DrawSettingsPanel() @@ -553,9 +571,6 @@ void DrawSettingsPanel() DrawCategories(); DrawConfigOptions(); - // Pop clip rect from DrawCategories - drawList->PopClipRect(); - // Pop clip rect from DrawContainer drawList->PopClipRect(); }