From 79e457fcf8d2defa4b31fc1360f85daa141f0131 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 29 Feb 2024 00:59:55 +0100 Subject: [PATCH] ImGui: add ability to reset horizontal scroll position This allows us to reset the horizontal position only when an user submitted a console command in the text box. We don't want to reset the horizontal position if new lines are added since user could still be reading text that is otherwise clipped away. --- src/thirdparty/imgui/misc/imgui_logger.cpp | 14 ++++++++++++-- src/thirdparty/imgui/misc/imgui_logger.h | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/thirdparty/imgui/misc/imgui_logger.cpp b/src/thirdparty/imgui/misc/imgui_logger.cpp index cc3c5a5f..6be9b025 100644 --- a/src/thirdparty/imgui/misc/imgui_logger.cpp +++ b/src/thirdparty/imgui/misc/imgui_logger.cpp @@ -897,14 +897,24 @@ void CTextLogger::Render() } } + // This dummy is here to let Dear ImGui know where the last character of + // the line had ended, so that it could properly process the horizontal + // scrollbar ImGui::Dummy(ImVec2((longest + 2), m_Lines.size() * m_CharAdvance.y)); + + m_bScrolledToStart = ImGui::GetScrollX() == 0.0f; + + if (m_bScrollToStart || (m_bAutoScroll && m_bScrolledToStart && !m_bScrollToCursor)) + { + ImGui::SetScrollHereX(0.0f); + m_bScrollToStart = false; + } + m_bScrolledToBottom = ImGui::GetScrollY() >= ImGui::GetScrollMaxY(); if (m_bScrollToBottom || (m_bAutoScroll && m_bScrolledToBottom && !m_bScrollToCursor)) { - ImGui::SetScrollHereX(0.0f); // TODO[ AMOS ]: only scroll x if a command has been submitted ImGui::SetScrollHereY(1.0f); - m_bScrollToBottom = false; } diff --git a/src/thirdparty/imgui/misc/imgui_logger.h b/src/thirdparty/imgui/misc/imgui_logger.h index 64e7caea..f46b4d9e 100644 --- a/src/thirdparty/imgui/misc/imgui_logger.h +++ b/src/thirdparty/imgui/misc/imgui_logger.h @@ -142,10 +142,12 @@ public: inline void SetHandleUserInputs (bool aValue){ m_bHandleUserInputs = aValue;} inline bool IsHandleUserInputs() const { return m_bHandleUserInputs; } - inline void ShouldScrollToBottom(bool aValue) { m_bScrollToBottom = aValue; } - inline bool IsScrollingToBottom() const { return m_bScrollToBottom; } + inline void ShouldScrollToStart(const bool aValue) { m_bScrollToStart = aValue; } + inline bool IsScrollingToStart() const { return m_bScrollToStart; } + inline bool IsScrolledToStart() const { return m_bScrolledToStart; } - inline void SetScrolledToBottom(bool aValue) { m_bScrolledToBottom = aValue; } + inline void ShouldScrollToBottom(const bool aValue) { m_bScrollToBottom = aValue; } + inline bool IsScrollingToBottom() const { return m_bScrollToBottom; } inline bool IsScrolledToBottom() const { return m_bScrolledToBottom; } void SetTabSize(int aValue); @@ -213,13 +215,27 @@ public: bool m_bAutoScroll; private: + // Whether to scroll to the cursor bool m_bScrollToCursor; + + // Whether to scroll to the start of the logging pane (horizontal axis), and + // whether we are already scrolled to the start + bool m_bScrollToStart; + bool m_bScrolledToStart; + + // Whether to scroll to the bottom of the logging pane (vertical axis), and + // whether we are already scrolled to the bottom bool m_bScrollToBottom; bool m_bScrolledToBottom; + bool m_bHandleUserInputs; bool m_bWithinLoggingRect; + + // TODO[ AMOS ]: remove these as they aren't used and causes the structure to + // pad by 7 bytes bool m_bLinesOffsetForward; int m_nLinesOffsetAmount; + int m_nTabSize; int m_nLeftMargin; float m_flLineSpacing;