Skip to content

Commit de65bd2

Browse files
author
SShikhali
committed
Minor improvements & fixes
- Extended API - Fixed inconsistent namespace name
1 parent d9a4b13 commit de65bd2

4 files changed

+30
-14
lines changed

imgui_node_editor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,15 @@ ed::NodeSettings* ed::Settings::FindNode(NodeId id)
27532753
return nullptr;
27542754
}
27552755

2756+
const ed::NodeSettings* ed::Settings::FindNode(NodeId id) const
2757+
{
2758+
for (auto& settings : m_Nodes)
2759+
if (settings.m_ID == id)
2760+
return &settings;
2761+
2762+
return nullptr;
2763+
}
2764+
27562765
void ed::Settings::RemoveNode(NodeId id)
27572766
{
27582767
auto node = FindNode(id);

imgui_node_editor.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
namespace ax {
3636
namespace NodeEditor {
3737

38+
namespace Detail {
39+
//------------------------------------------------------------------------------
40+
struct EditorContext;
41+
}
3842

3943
//------------------------------------------------------------------------------
4044
struct NodeId;
@@ -281,16 +285,14 @@ struct Style
281285
};
282286

283287

284-
//------------------------------------------------------------------------------
285-
struct EditorContext;
286288

287289

288290
//------------------------------------------------------------------------------
289-
IMGUI_NODE_EDITOR_API void SetCurrentEditor(EditorContext* ctx);
290-
IMGUI_NODE_EDITOR_API EditorContext* GetCurrentEditor();
291-
IMGUI_NODE_EDITOR_API EditorContext* CreateEditor(const Config* config = nullptr);
292-
IMGUI_NODE_EDITOR_API void DestroyEditor(EditorContext* ctx);
293-
IMGUI_NODE_EDITOR_API const Config& GetConfig(EditorContext* ctx = nullptr);
291+
IMGUI_NODE_EDITOR_API void SetCurrentEditor(Detail::EditorContext* ctx);
292+
IMGUI_NODE_EDITOR_API Detail::EditorContext* GetCurrentEditor();
293+
IMGUI_NODE_EDITOR_API Detail::EditorContext* CreateEditor(const Config* config = nullptr);
294+
IMGUI_NODE_EDITOR_API void DestroyEditor(Detail::EditorContext* ctx);
295+
IMGUI_NODE_EDITOR_API const Config& GetConfig(Detail::EditorContext* ctx = nullptr);
294296

295297
IMGUI_NODE_EDITOR_API Style& GetStyle();
296298
IMGUI_NODE_EDITOR_API const char* GetStyleColorName(StyleColor colorIndex);

imgui_node_editor_api.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ static int BuildIdList(C& container, I* list, int listSize, F&& accept)
4444

4545

4646
//------------------------------------------------------------------------------
47-
ax::NodeEditor::EditorContext* ax::NodeEditor::CreateEditor(const Config* config)
47+
ax::NodeEditor::Detail::EditorContext* ax::NodeEditor::CreateEditor(const Config* config)
4848
{
49-
return reinterpret_cast<ax::NodeEditor::EditorContext*>(new ax::NodeEditor::Detail::EditorContext(config));
49+
return reinterpret_cast<ax::NodeEditor::Detail::EditorContext*>(new ax::NodeEditor::Detail::EditorContext(config));
5050
}
5151

52-
void ax::NodeEditor::DestroyEditor(EditorContext* ctx)
52+
void ax::NodeEditor::DestroyEditor(Detail::EditorContext* ctx)
5353
{
5454
auto lastContext = GetCurrentEditor();
5555

@@ -65,7 +65,7 @@ void ax::NodeEditor::DestroyEditor(EditorContext* ctx)
6565
SetCurrentEditor(lastContext);
6666
}
6767

68-
const ax::NodeEditor::Config& ax::NodeEditor::GetConfig(EditorContext* ctx)
68+
const ax::NodeEditor::Config& ax::NodeEditor::GetConfig(Detail::EditorContext* ctx)
6969
{
7070
if (ctx == nullptr)
7171
ctx = GetCurrentEditor();
@@ -83,14 +83,14 @@ const ax::NodeEditor::Config& ax::NodeEditor::GetConfig(EditorContext* ctx)
8383
}
8484
}
8585

86-
void ax::NodeEditor::SetCurrentEditor(EditorContext* ctx)
86+
void ax::NodeEditor::SetCurrentEditor(Detail::EditorContext* ctx)
8787
{
8888
s_Editor = reinterpret_cast<ax::NodeEditor::Detail::EditorContext*>(ctx);
8989
}
9090

91-
ax::NodeEditor::EditorContext* ax::NodeEditor::GetCurrentEditor()
91+
ax::NodeEditor::Detail::EditorContext* ax::NodeEditor::GetCurrentEditor()
9292
{
93-
return reinterpret_cast<ax::NodeEditor::EditorContext*>(s_Editor);
93+
return reinterpret_cast<ax::NodeEditor::Detail::EditorContext*>(s_Editor);
9494
}
9595

9696
ax::NodeEditor::Style& ax::NodeEditor::GetStyle()

imgui_node_editor_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ struct Settings
546546

547547
NodeSettings* AddNode(NodeId id);
548548
NodeSettings* FindNode(NodeId id);
549+
const NodeSettings* FindNode(NodeId id) const;
549550
void RemoveNode(NodeId id);
550551

551552
void ClearDirty(Node* node = nullptr);
@@ -1473,6 +1474,10 @@ struct EditorContext
14731474

14741475
ImDrawList* GetDrawList() { return m_DrawList; }
14751476

1477+
const Settings& GetSettings() const { return m_Settings; }
1478+
void SetViewScroll(ImVec2 scroll) { m_Settings.m_ViewScroll = scroll; }
1479+
void SetViewZoom(float zoom) { m_Settings.m_ViewZoom = zoom; }
1480+
14761481
private:
14771482
void LoadSettings();
14781483
void SaveSettings();

0 commit comments

Comments
 (0)