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.
This commit is contained in:
Kelsi 2026-03-11 23:24:27 -07:00
parent c433188edb
commit 88436fa400
2 changed files with 25 additions and 3 deletions

View file

@ -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;

View file

@ -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();