mirror of https://github.com/ocornut/imgui
Added Set/GetVoidPtr in ImGuiStorage
This commit is contained in:
parent
00842d18e4
commit
c9c41c3874
19
imgui.cpp
19
imgui.cpp
|
@ -1163,6 +1163,14 @@ float* ImGuiStorage::GetFloatPtr(ImGuiID key, float default_val)
|
|||
return &it->val_f;
|
||||
}
|
||||
|
||||
void* ImGuiStorage::GetVoidPtr(ImGuiID key)
|
||||
{
|
||||
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
||||
if (it == Data.end() || it->key != key)
|
||||
it = Data.insert(it, Pair(key, (void*)0));
|
||||
return it->val_p;
|
||||
}
|
||||
|
||||
// FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
|
||||
// However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
|
||||
void ImGuiStorage::SetInt(ImU32 key, int val)
|
||||
|
@ -1187,6 +1195,17 @@ void ImGuiStorage::SetFloat(ImU32 key, float val)
|
|||
it->val_f = val;
|
||||
}
|
||||
|
||||
void ImGuiStorage::SetVoidPtr(ImU32 key, void* val)
|
||||
{
|
||||
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
||||
if (it == Data.end() || it->key != key)
|
||||
{
|
||||
Data.insert(it, Pair(key, val));
|
||||
return;
|
||||
}
|
||||
it->val_p = val;
|
||||
}
|
||||
|
||||
void ImGuiStorage::SetAllInt(int v)
|
||||
{
|
||||
for (size_t i = 0; i < Data.size(); i++)
|
||||
|
|
5
imgui.h
5
imgui.h
|
@ -641,9 +641,10 @@ struct ImGuiStorage
|
|||
struct Pair
|
||||
{
|
||||
ImGuiID key;
|
||||
union { int val_i; float val_f; };
|
||||
union { int val_i; float val_f; void* val_p; };
|
||||
Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
|
||||
Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
||||
Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
|
||||
};
|
||||
ImVector<Pair> Data;
|
||||
|
||||
|
@ -660,6 +661,8 @@ struct ImGuiStorage
|
|||
IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const;
|
||||
IMGUI_API void SetFloat(ImGuiID key, float val);
|
||||
IMGUI_API float* GetFloatPtr(ImGuiID key, float default_val = 0);
|
||||
IMGUI_API void SetVoidPtr(ImGuiID key, void* val);
|
||||
IMGUI_API void* GetVoidPtr(ImGuiID key);
|
||||
IMGUI_API void SetAllInt(int val); // Use on your own storage if you know only integer are being stored.
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue