From 88436fa400bbdc2bc864a23743e758876c10e099 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 11 Mar 2026 23:24:27 -0700 Subject: [PATCH] Add jump-to-bottom indicator in chat when scrolled up Shows a "New messages" button below the chat history area when the user has scrolled away from the latest messages. Clicking it jumps back to the most recent messages. --- include/ui/game_screen.hpp | 2 ++ src/ui/game_screen.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/ui/game_screen.hpp b/include/ui/game_screen.hpp index 73e318b9..a5ebaf62 100644 --- a/include/ui/game_screen.hpp +++ b/include/ui/game_screen.hpp @@ -91,6 +91,8 @@ private: bool showAddRankModal_ = false; bool refocusChatInput = false; bool vendorBagsOpened_ = false; // Track if bags were auto-opened for current vendor session + bool chatScrolledUp_ = false; // true when user has scrolled above the latest messages + bool chatForceScrollToBottom_ = false; // set to true to jump to bottom next frame bool chatWindowLocked = true; ImVec2 chatWindowPos_ = ImVec2(0.0f, 0.0f); bool chatWindowPosInit_ = false; diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 97351e7f..2052d3fd 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -1462,9 +1462,18 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { ImGui::PopID(); } - // Auto-scroll to bottom - if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) { - ImGui::SetScrollHereY(1.0f); + // Auto-scroll to bottom; track whether user has scrolled up + { + float scrollY = ImGui::GetScrollY(); + float scrollMaxY = ImGui::GetScrollMaxY(); + bool atBottom = (scrollMaxY <= 0.0f) || (scrollY >= scrollMaxY - 2.0f); + if (atBottom || chatForceScrollToBottom_) { + ImGui::SetScrollHereY(1.0f); + chatScrolledUp_ = false; + chatForceScrollToBottom_ = false; + } else { + chatScrolledUp_ = true; + } } ImGui::EndChild(); @@ -1472,6 +1481,17 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { // Reset font scale after chat history ImGui::SetWindowFontScale(1.0f); + // "Jump to bottom" indicator when scrolled up + if (chatScrolledUp_) { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.35f, 0.7f, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.5f, 0.9f, 1.0f)); + if (ImGui::SmallButton(" v New messages ")) { + chatForceScrollToBottom_ = true; + } + ImGui::PopStyleColor(2); + ImGui::SameLine(); + } + ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing();