Skip to content

Commit 5715a38

Browse files
committed
added in clapping rect and node emplacement from Fattorino#53
1 parent eeea222 commit 5715a38

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

include/ImNodeFlow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ namespace ImFlow
356356
*/
357357
template<typename T, typename... Params>
358358
std::shared_ptr<T> addNode(const ImVec2& pos, Params&&... args);
359+
void emplaceNode(const ImVec2& pos, const std::shared_ptr<BaseNode>& node);
359360

360361
std::function<void(std::shared_ptr<BaseNode>)> onNodeCreateHook = {};
361362
std::function<void(const BaseNode*)> onNodeDestroyHook = {};

src/ImNodeFlow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ namespace ImFlow {
101101
return -1;
102102
}
103103

104+
void ImNodeFlow::emplaceNode(const ImVec2& pos, const std::shared_ptr<BaseNode>& n){
105+
n->setPos(pos);
106+
n->setHandler(this);
107+
if (!n->getStyle())
108+
n->setStyle(NodeStyle::cyan());
109+
110+
auto uid = reinterpret_cast<uintptr_t>(n.get());
111+
n->setUID(uid);
112+
m_nodes[uid] = n;
113+
}
114+
104115
void Link::update() {
105116
// start/end from pinPoint() are in screen coordinates - convert to grid
106117
ImVec2 startScreen = m_left->pinPoint();

src/context_wrapper.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ inline void ContainedContext::setFontDensity()
114114

115115
inline void ContainedContext::begin()
116116
{
117+
auto window = ImGui::GetCurrentWindow();
118+
117119
ImGui::PushID(this);
118120
ImGui::PushStyleColor(ImGuiCol_ChildBg, m_config.color);
119121
ImGui::BeginChild("view_port", m_config.size, 0, ImGuiWindowFlags_NoMove);
@@ -154,10 +156,20 @@ inline void ContainedContext::begin()
154156
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
155157
setFontDensity();
156158
ImGui::PopStyleVar();
159+
160+
auto clip_rect = window->ClipRect;
161+
ImVec2 canvas_p0 = clip_rect.Min;
162+
ImVec2 canvas_p1 = clip_rect.Max;
163+
canvas_p0 = (canvas_p0 - m_origin) / m_scale;
164+
canvas_p1 = (canvas_p1 - m_origin) / m_scale;
165+
166+
ImGui::PushClipRect(canvas_p0, canvas_p1, false);
157167
}
158168

159169
inline void ContainedContext::end()
160170
{
171+
ImGui::PopClipRect();
172+
161173
m_anyWindowHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow);
162174
if (m_config.extra_window_wrapper && ImGui::IsWindowHovered())
163175
m_anyWindowHovered = false;

0 commit comments

Comments
 (0)