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.
This commit is contained in:
Kawe Mazidjatari 2024-02-29 00:59:55 +01:00
parent c80d6eb0d2
commit ef6cd5e444
2 changed files with 31 additions and 5 deletions

View File

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

View File

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