Skip to content

Commit 0f0bf7e

Browse files
committed
Use internal copy of ImDrawListSplitter to avoid conflicts with Columns API. #28
1 parent 1c1eace commit 0f0bf7e

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed

NodeEditor/Source/imgui_node_editor.cpp

+38-15
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ static void ImDrawList_SwapChannels(ImDrawList* drawList, int left, int right)
226226
ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right);
227227
}
228228

229+
static void ImDrawList_SwapSplitter(ImDrawList* drawList, ImDrawListSplitter& splitter)
230+
{
231+
auto& currentSplitter = drawList->_Splitter;
232+
233+
std::swap(currentSplitter._Current, splitter._Current);
234+
std::swap(currentSplitter._Count, splitter._Count);
235+
currentSplitter._Channels.swap(splitter._Channels);
236+
}
237+
229238
//static void ImDrawList_TransformChannel_Inner(ImVector<ImDrawVert>& vtxBuffer, const ImVector<ImDrawIdx>& idxBuffer, const ImVector<ImDrawCmd>& cmdBuffer, const ImVec2& preOffset, const ImVec2& scale, const ImVec2& postOffset)
230239
//{
231240
// auto idxRead = idxBuffer.Data;
@@ -1031,6 +1040,7 @@ ed::EditorContext::EditorContext(const ax::NodeEditor::Config* config)
10311040
, m_IsInitialized(false)
10321041
, m_Settings()
10331042
, m_Config(config)
1043+
, m_ExternalChannel(0)
10341044
{
10351045
}
10361046

@@ -1042,6 +1052,8 @@ ed::EditorContext::~EditorContext()
10421052
for (auto link : m_Links) delete link.m_Object;
10431053
for (auto pin : m_Pins) delete pin.m_Object;
10441054
for (auto node : m_Nodes) delete node.m_Object;
1055+
1056+
m_Splitter.ClearFreeMemory();
10451057
}
10461058

10471059
void ed::EditorContext::Begin(const char* id, const ImVec2& size)
@@ -1059,6 +1071,11 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size)
10591071
for (auto pin : m_Pins) pin->Reset();
10601072
for (auto link : m_Links) link->Reset();
10611073

1074+
auto drawList = ImGui::GetWindowDrawList();
1075+
1076+
ImDrawList_SwapSplitter(drawList, m_Splitter);
1077+
m_ExternalChannel = drawList->_Splitter._Current;
1078+
10621079
ImGui::PushID(id);
10631080

10641081
auto availableContentSize = ImGui::GetContentRegionAvail();
@@ -1095,8 +1112,6 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size)
10951112

10961113
m_Canvas.SetView(m_NavigateAction.GetView());
10971114

1098-
auto drawList = ImGui::GetWindowDrawList();
1099-
11001115
// #debug #clip
11011116
//ImGui::Text("CLIP = { x=%g y=%g w=%g h=%g r=%g b=%g }",
11021117
// clipMin.x, clipMin.y, clipMax.x - clipMin.x, clipMax.y - clipMin.y, clipMax.x, clipMax.y);
@@ -1408,6 +1423,8 @@ void ed::EditorContext::End()
14081423
if (m_IsCanvasVisible)
14091424
m_Canvas.End();
14101425

1426+
ImDrawList_SwapSplitter(drawList, m_Splitter);
1427+
14111428
// Draw border
14121429
{
14131430
auto& style = ImGui::GetStyle();
@@ -1650,20 +1667,26 @@ void ed::EditorContext::NotifyLinkDeleted(Link* link)
16501667
m_LastActiveLink = nullptr;
16511668
}
16521669

1653-
void ed::EditorContext::Suspend()
1670+
void ed::EditorContext::Suspend(SuspendFlags flags)
16541671
{
1655-
auto lastChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
1656-
ImGui::GetWindowDrawList()->ChannelsSetCurrent(0);
1672+
auto drawList = ImGui::GetWindowDrawList();
1673+
auto lastChannel = drawList->_Splitter._Current;
1674+
drawList->ChannelsSetCurrent(m_ExternalChannel);
16571675
m_Canvas.Suspend();
1658-
ImGui::GetWindowDrawList()->ChannelsSetCurrent(lastChannel);
1676+
drawList->ChannelsSetCurrent(lastChannel);
1677+
if ((flags & SuspendFlags::KeepSplitter) != SuspendFlags::KeepSplitter)
1678+
ImDrawList_SwapSplitter(drawList, m_Splitter);
16591679
}
16601680

1661-
void ed::EditorContext::Resume()
1681+
void ed::EditorContext::Resume(SuspendFlags flags)
16621682
{
1663-
auto lastChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
1664-
ImGui::GetWindowDrawList()->ChannelsSetCurrent(0);
1683+
auto drawList = ImGui::GetWindowDrawList();
1684+
if ((flags & SuspendFlags::KeepSplitter) != SuspendFlags::KeepSplitter)
1685+
ImDrawList_SwapSplitter(drawList, m_Splitter);
1686+
auto lastChannel = drawList->_Splitter._Current;
1687+
drawList->ChannelsSetCurrent(m_ExternalChannel);
16651688
m_Canvas.Resume();
1666-
ImGui::GetWindowDrawList()->ChannelsSetCurrent(lastChannel);
1689+
drawList->ChannelsSetCurrent(lastChannel);
16671690
}
16681691

16691692
bool ed::EditorContext::IsSuspended()
@@ -4219,7 +4242,7 @@ void ed::CreateItemAction::End()
42194242
if (m_IsInGlobalSpace)
42204243
{
42214244
ImGui::PopClipRect();
4222-
Editor->Resume();
4245+
Editor->Resume(SuspendFlags::KeepSplitter);
42234246

42244247
auto currentChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
42254248
if (currentChannel != m_LastChannel)
@@ -4331,7 +4354,7 @@ ed::CreateItemAction::Result ed::CreateItemAction::QueryLink(PinId* startId, Pin
43314354

43324355
if (!m_IsInGlobalSpace)
43334356
{
4334-
Editor->Suspend();
4357+
Editor->Suspend(SuspendFlags::KeepSplitter);
43354358

43364359
auto rect = Editor->GetRect();
43374360
ImGui::PushClipRect(rect.Min + ImVec2(1, 1), rect.Max - ImVec2(1, 1), false);
@@ -4354,7 +4377,7 @@ ed::CreateItemAction::Result ed::CreateItemAction::QueryNode(PinId* pinId)
43544377

43554378
if (!m_IsInGlobalSpace)
43564379
{
4357-
Editor->Suspend();
4380+
Editor->Suspend(SuspendFlags::KeepSplitter);
43584381

43594382
auto rect = Editor->GetRect();
43604383
ImGui::PushClipRect(rect.Min + ImVec2(1, 1), rect.Max - ImVec2(1, 1), false);
@@ -4934,7 +4957,7 @@ bool ed::HintBuilder::Begin(NodeId nodeId)
49344957

49354958
m_LastChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
49364959

4937-
Editor->Suspend();
4960+
Editor->Suspend(SuspendFlags::KeepSplitter);
49384961

49394962
const auto alpha = ImMax(0.0f, std::min(1.0f, (view.Scale - c_min_zoom) / (c_max_zoom - c_min_zoom)));
49404963

@@ -4966,7 +4989,7 @@ void ed::HintBuilder::End()
49664989

49674990
ImGui::GetWindowDrawList()->ChannelsSetCurrent(m_LastChannel);
49684991

4969-
Editor->Resume();
4992+
Editor->Resume(SuspendFlags::KeepSplitter);
49704993

49714994
m_IsActive = false;
49724995
m_CurrentNode = nullptr;

NodeEditor/Source/imgui_node_editor_internal.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,16 @@ struct Config: ax::NodeEditor::Config
12301230
void EndSave();
12311231
};
12321232

1233+
enum class SuspendFlags : uint8_t
1234+
{
1235+
None = 0,
1236+
KeepSplitter = 1
1237+
};
1238+
1239+
inline SuspendFlags operator |(SuspendFlags lhs, SuspendFlags rhs) { return static_cast<SuspendFlags>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs)); }
1240+
inline SuspendFlags operator &(SuspendFlags lhs, SuspendFlags rhs) { return static_cast<SuspendFlags>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs)); }
1241+
1242+
12331243
struct EditorContext
12341244
{
12351245
EditorContext(const ax::NodeEditor::Config* config = nullptr);
@@ -1289,8 +1299,8 @@ struct EditorContext
12891299

12901300
void NotifyLinkDeleted(Link* link);
12911301

1292-
void Suspend();
1293-
void Resume();
1302+
void Suspend(SuspendFlags flags = SuspendFlags::None);
1303+
void Resume(SuspendFlags flags = SuspendFlags::None);
12941304
bool IsSuspended();
12951305

12961306
bool IsActive();
@@ -1434,6 +1444,9 @@ struct EditorContext
14341444
Settings m_Settings;
14351445

14361446
Config m_Config;
1447+
1448+
int m_ExternalChannel;
1449+
ImDrawListSplitter m_Splitter;
14371450
};
14381451

14391452

0 commit comments

Comments
 (0)