From a579d6f521cb34d35cd2524e19c27347dd4b79c8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 8 Mar 2015 12:39:50 +0000 Subject: [PATCH] Scrollbar tidying up variable names --- imgui.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7791730b..9fcff6b8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3042,19 +3042,20 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true); if (held) { + // Absolute seeking g.HoveredId = scrollbar_id; - const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y_pixels*0.5f)) / (scrollbar_height - grab_size_y_pixels)); - window->ScrollY = (float)(int)(pos_y_norm * (window->SizeContents.y - window->Size.y)); + const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y_pixels*0.5f)) / (scrollbar_height - grab_size_y_pixels)); + window->ScrollY = (float)(int)(clicked_y_norm * (window->SizeContents.y - window->Size.y)); window->NextScrollY = window->ScrollY; } } - // Normalized height of the grab - const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContents.y - window->Size.y)); + // Render + const float scroll_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContents.y - window->Size.y)); const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); window->DrawList->AddRectFilled( - ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y - grab_size_y_pixels, pos_y_norm)), - ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y - grab_size_y_pixels, pos_y_norm) + grab_size_y_pixels), grab_col); + ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y - grab_size_y_pixels, scroll_y_norm)), + ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y - grab_size_y_pixels, scroll_y_norm) + grab_size_y_pixels), grab_col); } // Render resize grip