Skip to content

Replace SentinelDrawCallback with a define #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions imgui_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
static constexpr bool value = (sizeof(yes_type) == sizeof(test<mixin>(0))); \
}

// Special sentinel value. This needs to be unique, so allow it to be overidden in the user's imgui config
#ifndef ImDrawCallback_NodeEditorCanvas
#define ImDrawCallback_NodeEditorCanvas (ImDrawCallback)(-2)
#endif

namespace ImCanvasDetails {

DECLARE_HAS_MEMBER(HasFringeScale, _FringeScale);
Expand Down Expand Up @@ -68,12 +73,6 @@ struct VtxCurrentOffsetRef
}
};

static void SentinelDrawCallback(const ImDrawList* parent_list, const ImDrawCmd* cmd)
{
// This is a sentinel draw callback, it's only purpose is to mark draw list command.
IM_ASSERT(false && "This draw callback should never be called.");
}

} // namespace ImCanvasDetails

// Returns a reference to _FringeScale extension to ImDrawList
Expand Down Expand Up @@ -435,7 +434,7 @@ void ImGuiEx::Canvas::EnterLocalSpace()
//
// More investigation is needed. To get to the bottom of this.
if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1)
m_DrawList->AddCallback(&ImCanvasDetails::SentinelDrawCallback, nullptr);
m_DrawList->AddCallback(ImDrawCallback_NodeEditorCanvas, nullptr);

# if IMGUI_EX_CANVAS_DEFERED()
m_Ranges.resize(m_Ranges.Size + 1);
Expand Down Expand Up @@ -554,7 +553,7 @@ void ImGuiEx::Canvas::LeaveLocalSpace()
}

// Remove sentinel draw command if present
if (m_DrawListCommadBufferSize > 0 && m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback)
if (m_DrawListCommadBufferSize > 0 && m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == ImDrawCallback_NodeEditorCanvas)
m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1);

auto& fringeScale = ImFringeScaleRef(m_DrawList);
Expand Down