Skip to content

Commit

Permalink
fix focus detection
Browse files Browse the repository at this point in the history
  • Loading branch information
santiago committed Oct 2, 2022
1 parent 1a37e65 commit c0bc41f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,9 @@ ImU32 TextEditor::GetGlyphColor(const Glyph & aGlyph) const
return color;
}

void TextEditor::HandleKeyboardInputs()
void TextEditor::HandleKeyboardInputs(bool aParentIsFocused)
{
if (ImGui::IsWindowFocused())
if (ImGui::IsWindowFocused() || aParentIsFocused)
{
if (ImGui::IsWindowHovered())
ImGui::SetMouseCursor(ImGuiMouseCursor_TextInput);
Expand Down Expand Up @@ -1070,7 +1070,7 @@ void TextEditor::UpdatePalette()
}
}

void TextEditor::Render()
void TextEditor::Render(bool aParentIsFocused)
{
/* 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;
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void TextEditor::Render()
}
if (cursorCoordsInThisLine.size() > 0)
{
auto focused = ImGui::IsWindowFocused();
auto focused = ImGui::IsWindowFocused() || aParentIsFocused;

// Render the cursors
if (focused)
Expand Down Expand Up @@ -1353,7 +1353,7 @@ void TextEditor::Render()
}
}

void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)
void TextEditor::Render(const char* aTitle, bool aParentIsFocused, const ImVec2& aSize, bool aBorder)
{
for (int c = 0; c <= mState.mCurrentCursor; c++)
{
Expand All @@ -1375,15 +1375,15 @@ void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)

if (mHandleKeyboardInputs)
{
HandleKeyboardInputs();
HandleKeyboardInputs(aParentIsFocused);
ImGui::PushAllowKeyboardFocus(true);
}

if (mHandleMouseInputs)
HandleMouseInputs();

ColorizeInternal();
Render();
Render(aParentIsFocused);

if (mHandleKeyboardInputs)
ImGui::PopAllowKeyboardFocus();
Expand Down
6 changes: 3 additions & 3 deletions TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class IMGUI_API TextEditor
void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }

void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);
void Render(const char* aTitle, bool aParentIsFocused = false, const ImVec2& aSize = ImVec2(), bool aBorder = false);
void SetText(const std::string& aText);
std::string GetText() const;

Expand Down Expand Up @@ -413,10 +413,10 @@ class IMGUI_API TextEditor
std::string GetWordAt(const Coordinates& aCoords) const;
ImU32 GetGlyphColor(const Glyph& aGlyph) const;

void HandleKeyboardInputs();
void HandleKeyboardInputs(bool aParentIsFocused = false);
void HandleMouseInputs();
void UpdatePalette();
void Render();
void Render(bool aParentIsFocused = false);

float mLineSpacing;
Lines mLines;
Expand Down

0 comments on commit c0bc41f

Please sign in to comment.