Skip to content

Commit 459d2d7

Browse files
committed
Editor: Don't steal input from active user widget (#172)
1 parent 89312bb commit 459d2d7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

docs/CHANGELOG.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,6 @@ v0.9.1 (WIP):
202202

203203
BUGFIX: Application: Correctly set DX11 View for NULL textures (#162)
204204

205-
BUGFIX: Application: Recreate DX11 resources lazily (related to #162)
205+
BUGFIX: Application: Recreate DX11 resources lazily (related to #162)
206+
207+
BUGFIX: Editor: Don't steal input from active user widget (#172)

imgui_node_editor.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ ImRect ed::Link::GetBounds() const
10551055
//------------------------------------------------------------------------------
10561056
ed::EditorContext::EditorContext(const ax::NodeEditor::Config* config)
10571057
: m_Config(config)
1058+
, m_EditorActiveId(0)
10581059
, m_IsFirstFrame(true)
10591060
, m_IsFocused(false)
10601061
, m_IsHovered(false)
@@ -1145,6 +1146,7 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size)
11451146
ImDrawList_SwapSplitter(m_DrawList, m_Splitter);
11461147
m_ExternalChannel = m_DrawList->_Splitter._Current;
11471148

1149+
m_EditorActiveId = ImGui::GetID(id);
11481150
ImGui::PushID(id);
11491151

11501152
auto availableContentSize = ImGui::GetContentRegionAvail();
@@ -2305,6 +2307,7 @@ ed::Control ed::EditorContext::BuildControl(bool allowOffscreen)
23052307
ImGui::PushClipRect(editorRect.Min, editorRect.Max, false);
23062308
}
23072309

2310+
ImGuiID activeId = 0;
23082311
Object* hotObject = nullptr;
23092312
Object* activeObject = nullptr;
23102313
Object* clickedObject = nullptr;
@@ -2342,7 +2345,7 @@ ed::Control ed::EditorContext::BuildControl(bool allowOffscreen)
23422345
};
23432346

23442347
// Emits invisible button and returns true if it is clicked.
2345-
auto emitInteractiveAreaEx = [](ObjectId id, const ImRect& rect, ImGuiButtonFlags extraFlags) -> int
2348+
auto emitInteractiveAreaEx = [&activeId](ObjectId id, const ImRect& rect, ImGuiButtonFlags extraFlags) -> int
23462349
{
23472350
char idString[33] = { 0 }; // itoa can output 33 bytes maximum
23482351
snprintf(idString, 32, "%p", id.AsPointer());
@@ -2356,6 +2359,9 @@ ed::Control ed::EditorContext::BuildControl(bool allowOffscreen)
23562359
// #debug
23572360
//ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(0, 255, 0, 64));
23582361

2362+
if (ImGui::IsItemActive())
2363+
activeId = ImGui::GetActiveID();
2364+
23592365
return buttonIndex;
23602366
};
23612367

@@ -2507,6 +2513,12 @@ ed::Control ed::EditorContext::BuildControl(bool allowOffscreen)
25072513
backgroundDoubleClickButtonIndex = -1;
25082514
}
25092515

2516+
if (activeId)
2517+
m_EditorActiveId = activeId;
2518+
2519+
if (ImGui::IsAnyItemActive() && ImGui::GetActiveID() != m_EditorActiveId)
2520+
return Control();
2521+
25102522
m_IsHovered = ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly);
25112523
m_IsHoveredWithoutOverlapp = ImGui::IsItemHovered();
25122524
if (!allowOffscreen && !m_IsHovered)

imgui_node_editor_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ struct EditorContext
14801480

14811481
Config m_Config;
14821482

1483+
ImGuiID m_EditorActiveId;
14831484
bool m_IsFirstFrame;
14841485
bool m_IsFocused;
14851486
bool m_IsHovered;

0 commit comments

Comments
 (0)