CTextLogger: Manage keyboard and mouse inputs

Manage them under 1 member variable.
This commit is contained in:
Kawe Mazidjatari 2023-04-09 19:53:33 +02:00
parent d46cc0d6b1
commit a39afd4efe
2 changed files with 11 additions and 14 deletions

View File

@ -27,8 +27,7 @@ CTextLogger::CTextLogger()
, m_bScrollToBottom(true)
, m_bScrollToCursor(false)
, m_bScrolledToMax(false)
, m_bHandleKeyboardInputs(true)
, m_bHandleMouseInputs(true)
, m_bHandleUserInputs(true)
, m_bWithinLoggingRect(false)
, m_bShowWhiteSpaces(false)
, m_bLinesOffsetForward(false)
@ -769,14 +768,13 @@ void CTextLogger::Render()
bool bHoveredScrollbar = hoveredID && (hoveredID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_X) || hoveredID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_Y));
bool bActiveScrollbar = activeID && (activeID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_X) || activeID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_Y));
if (m_bHandleKeyboardInputs)
if (m_bHandleUserInputs)
{
HandleKeyboardInputs(bHoveredScrollbar, bActiveScrollbar);
ImGui::PushAllowKeyboardFocus(true);
}
if (m_bHandleMouseInputs)
HandleMouseInputs(bHoveredScrollbar, bActiveScrollbar);
}
/* Compute mCharAdvance regarding to scaled font size (Ctrl + mouse wheel)*/
const float fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr).x;
@ -937,7 +935,7 @@ void CTextLogger::Render()
ImGui::Dummy(ImVec2((longest + 2), m_Lines.size() * m_CharAdvance.y));
m_bScrolledToMax = ImGui::GetScrollY() >= ImGui::GetScrollMaxY();
SetScrolledToMax(ImGui::GetScrollY() >= ImGui::GetScrollMaxY());
if (m_bScrollToBottom || (m_bAutoScroll && m_bScrolledToMax && !m_bScrollToCursor))
{
@ -946,7 +944,7 @@ void CTextLogger::Render()
}
m_bScrollToCursor = false;
if (m_bHandleKeyboardInputs)
if (m_bHandleUserInputs)
ImGui::PopAllowKeyboardFocus();
ImGui::PopStyleVar();

View File

@ -134,15 +134,15 @@ public:
void MoveCursor(int aLines, bool aForward = true);
void SetCursorPosition(const Coordinates& aPosition);
inline void SetHandleMouseInputs (bool aValue){ m_bHandleMouseInputs = aValue;}
inline bool IsHandleMouseInputsEnabled() const { return m_bHandleKeyboardInputs; }
inline void SetHandleKeyboardInputs (bool aValue){ m_bHandleKeyboardInputs = aValue;}
inline bool IsHandleKeyboardInputsEnabled() const { return m_bHandleKeyboardInputs; }
inline void SetHandleUserInputs (bool aValue){ m_bHandleUserInputs = aValue;}
inline bool IsHandleUserInputs() const { return m_bHandleUserInputs; }
inline void SetShowWhitespaces(bool aValue) { m_bShowWhiteSpaces = aValue; }
inline bool IsShowingWhitespaces() const { return m_bShowWhiteSpaces; }
inline void SetScrolledToMax(bool aValue) { m_bScrolledToMax = aValue; }
inline bool IsScrolledToMax() const { return m_bScrolledToMax; }
void SetTabSize(int aValue);
inline int GetTabSize() const { return m_nTabSize; }
@ -210,8 +210,7 @@ public:
bool m_bScrollToCursor;
bool m_bScrolledToMax;
private:
bool m_bHandleKeyboardInputs;
bool m_bHandleMouseInputs;
bool m_bHandleUserInputs;
bool m_bWithinLoggingRect;
bool m_bShowWhiteSpaces;
bool m_bLinesOffsetForward;