Skip to content

Commit 76619c5

Browse files
committed
Use this PR Nelarius/imnodes#169 for ImNodes and use UUIDs as ui node ids
1 parent 7eb0852 commit 76619c5

7 files changed

+749
-323
lines changed

external/imgui/IMNODES_NAMESPACE.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#ifndef IMNODES_NAMESPACE
4+
#define IMNODES_NAMESPACE ImNodes
5+
#endif

external/imgui/ImGuiStorage.h

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#pragma once
2+
3+
#include "IMNODES_NAMESPACE.h"
4+
#include "imnodes_config_or_default.h"
5+
6+
namespace IMNODES_NAMESPACE
7+
{
8+
namespace Internal
9+
{
10+
11+
// Copy-pasted from ImGui because we needed to change the ID type
12+
13+
// Helper: Key->Value storage
14+
// Typically you don't have to worry about this since a storage is held within each Window.
15+
// We use it to e.g. store collapse state for a tree (Int 0/1)
16+
// This is optimized for efficient lookup (dichotomy into a contiguous buffer) and rare insertion
17+
// (typically tied to user interactions aka max once a frame) You can use it as custom user storage
18+
// for temporary values. Declare your own storage if, for example:
19+
// - You want to manipulate the open/close state of a particular sub-tree in your interface (tree
20+
// node uses Int 0/1 to store their state).
21+
// - You want to store custom debug data easily without adding or editing structures in your code
22+
// (probably not efficient, but convenient) Types are NOT stored, so it is up to you to make sure
23+
// your Key don't collide with different types.
24+
struct Storage
25+
{
26+
// [Internal]
27+
struct ImGuiStoragePair
28+
{
29+
ID key;
30+
union
31+
{
32+
int val_i;
33+
float val_f;
34+
void* val_p;
35+
};
36+
ImGuiStoragePair(ID _key, int _val_i)
37+
{
38+
key = _key;
39+
val_i = _val_i;
40+
}
41+
ImGuiStoragePair(ID _key, float _val_f)
42+
{
43+
key = _key;
44+
val_f = _val_f;
45+
}
46+
ImGuiStoragePair(ID _key, void* _val_p)
47+
{
48+
key = _key;
49+
val_p = _val_p;
50+
}
51+
};
52+
53+
ImVector<ImGuiStoragePair> Data;
54+
55+
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
56+
// - Set***() functions find pair, insertion on demand if missing.
57+
// - Sorted insertion is costly, paid once. A typical frame shouldn't need to insert any new
58+
// pair.
59+
void Clear() { Data.clear(); }
60+
IMGUI_API int GetInt(ID key, int default_val = 0) const;
61+
IMGUI_API void SetInt(ID key, int val);
62+
IMGUI_API bool GetBool(ID key, bool default_val = false) const;
63+
IMGUI_API void SetBool(ID key, bool val);
64+
IMGUI_API float GetFloat(ID key, float default_val = 0.0f) const;
65+
IMGUI_API void SetFloat(ID key, float val);
66+
IMGUI_API void* GetVoidPtr(ID key) const; // default_val is NULL
67+
IMGUI_API void SetVoidPtr(ID key, void* val);
68+
69+
// - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if
70+
// you intend to do Get+Set.
71+
// - References are only valid until a new value is added to the storage. Calling a Set***()
72+
// function or a Get***Ref() function invalidates the pointer.
73+
// - A typical use case where this is convenient for quick hacking (e.g. add storage during a
74+
// live Edit&Continue session if you can't modify existing struct)
75+
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f);
76+
// some_var += *pvar;
77+
IMGUI_API int* GetIntRef(ID key, int default_val = 0);
78+
IMGUI_API bool* GetBoolRef(ID key, bool default_val = false);
79+
IMGUI_API float* GetFloatRef(ID key, float default_val = 0.0f);
80+
IMGUI_API void** GetVoidPtrRef(ID key, void* default_val = NULL);
81+
82+
// Use on your own storage if you know only integer are being stored (open/close all tree nodes)
83+
IMGUI_API void SetAllInt(int val);
84+
85+
// For quicker full rebuild of a storage (instead of an incremental one), you may add all your
86+
// contents and then sort once.
87+
IMGUI_API void BuildSortByKey();
88+
};
89+
90+
} // namespace Internal
91+
} // namespace IMNODES_NAMESPACE

0 commit comments

Comments
 (0)