Skip to content

Commit

Permalink
Use internal copy of ImDrawListSplitter to avoid conflicts with Colum…
Browse files Browse the repository at this point in the history
…ns API. thedmd#28
  • Loading branch information
thedmd authored and fdfxalex committed Dec 31, 2019
1 parent c7a21e3 commit 11048e6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
53 changes: 38 additions & 15 deletions NodeEditor/Source/imgui_node_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ static void ImDrawList_SwapChannels(ImDrawList* drawList, int left, int right)
ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right);
}

static void ImDrawList_SwapSplitter(ImDrawList* drawList, ImDrawListSplitter& splitter)
{
auto& currentSplitter = drawList->_Splitter;

std::swap(currentSplitter._Current, splitter._Current);
std::swap(currentSplitter._Count, splitter._Count);
currentSplitter._Channels.swap(splitter._Channels);
}

//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)
//{
// auto idxRead = idxBuffer.Data;
Expand Down Expand Up @@ -1031,6 +1040,7 @@ ed::EditorContext::EditorContext(const ax::NodeEditor::Config* config)
, m_IsInitialized(false)
, m_Settings()
, m_Config(config)
, m_ExternalChannel(0)
{
}

Expand All @@ -1042,6 +1052,8 @@ ed::EditorContext::~EditorContext()
for (auto link : m_Links) delete link.m_Object;
for (auto pin : m_Pins) delete pin.m_Object;
for (auto node : m_Nodes) delete node.m_Object;

m_Splitter.ClearFreeMemory();
}

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

auto drawList = ImGui::GetWindowDrawList();

ImDrawList_SwapSplitter(drawList, m_Splitter);
m_ExternalChannel = drawList->_Splitter._Current;

ImGui::PushID(id);

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

m_Canvas.SetView(m_NavigateAction.GetView());

auto drawList = ImGui::GetWindowDrawList();

// #debug #clip
//ImGui::Text("CLIP = { x=%g y=%g w=%g h=%g r=%g b=%g }",
// clipMin.x, clipMin.y, clipMax.x - clipMin.x, clipMax.y - clipMin.y, clipMax.x, clipMax.y);
Expand Down Expand Up @@ -1408,6 +1423,8 @@ void ed::EditorContext::End()
if (m_IsCanvasVisible)
m_Canvas.End();

ImDrawList_SwapSplitter(drawList, m_Splitter);

// Draw border
{
auto& style = ImGui::GetStyle();
Expand Down Expand Up @@ -1650,20 +1667,26 @@ void ed::EditorContext::NotifyLinkDeleted(Link* link)
m_LastActiveLink = nullptr;
}

void ed::EditorContext::Suspend()
void ed::EditorContext::Suspend(SuspendFlags flags)
{
auto lastChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
ImGui::GetWindowDrawList()->ChannelsSetCurrent(0);
auto drawList = ImGui::GetWindowDrawList();
auto lastChannel = drawList->_Splitter._Current;
drawList->ChannelsSetCurrent(m_ExternalChannel);
m_Canvas.Suspend();
ImGui::GetWindowDrawList()->ChannelsSetCurrent(lastChannel);
drawList->ChannelsSetCurrent(lastChannel);
if ((flags & SuspendFlags::KeepSplitter) != SuspendFlags::KeepSplitter)
ImDrawList_SwapSplitter(drawList, m_Splitter);
}

void ed::EditorContext::Resume()
void ed::EditorContext::Resume(SuspendFlags flags)
{
auto lastChannel = ImGui::GetWindowDrawList()->_Splitter._Current;
ImGui::GetWindowDrawList()->ChannelsSetCurrent(0);
auto drawList = ImGui::GetWindowDrawList();
if ((flags & SuspendFlags::KeepSplitter) != SuspendFlags::KeepSplitter)
ImDrawList_SwapSplitter(drawList, m_Splitter);
auto lastChannel = drawList->_Splitter._Current;
drawList->ChannelsSetCurrent(m_ExternalChannel);
m_Canvas.Resume();
ImGui::GetWindowDrawList()->ChannelsSetCurrent(lastChannel);
drawList->ChannelsSetCurrent(lastChannel);
}

bool ed::EditorContext::IsSuspended()
Expand Down Expand Up @@ -4219,7 +4242,7 @@ void ed::CreateItemAction::End()
if (m_IsInGlobalSpace)
{
ImGui::PopClipRect();
Editor->Resume();
Editor->Resume(SuspendFlags::KeepSplitter);

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

if (!m_IsInGlobalSpace)
{
Editor->Suspend();
Editor->Suspend(SuspendFlags::KeepSplitter);

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

if (!m_IsInGlobalSpace)
{
Editor->Suspend();
Editor->Suspend(SuspendFlags::KeepSplitter);

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

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

Editor->Suspend();
Editor->Suspend(SuspendFlags::KeepSplitter);

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

Expand Down Expand Up @@ -4966,7 +4989,7 @@ void ed::HintBuilder::End()

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

Editor->Resume();
Editor->Resume(SuspendFlags::KeepSplitter);

m_IsActive = false;
m_CurrentNode = nullptr;
Expand Down
17 changes: 15 additions & 2 deletions NodeEditor/Source/imgui_node_editor_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,16 @@ struct Config: ax::NodeEditor::Config
void EndSave();
};

enum class SuspendFlags : uint8_t
{
None = 0,
KeepSplitter = 1
};

inline SuspendFlags operator |(SuspendFlags lhs, SuspendFlags rhs) { return static_cast<SuspendFlags>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs)); }
inline SuspendFlags operator &(SuspendFlags lhs, SuspendFlags rhs) { return static_cast<SuspendFlags>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs)); }


struct EditorContext
{
EditorContext(const ax::NodeEditor::Config* config = nullptr);
Expand Down Expand Up @@ -1289,8 +1299,8 @@ struct EditorContext

void NotifyLinkDeleted(Link* link);

void Suspend();
void Resume();
void Suspend(SuspendFlags flags = SuspendFlags::None);
void Resume(SuspendFlags flags = SuspendFlags::None);
bool IsSuspended();

bool IsActive();
Expand Down Expand Up @@ -1434,6 +1444,9 @@ struct EditorContext
Settings m_Settings;

Config m_Config;

int m_ExternalChannel;
ImDrawListSplitter m_Splitter;
};


Expand Down

0 comments on commit 11048e6

Please sign in to comment.