mirror of https://github.com/ocornut/imgui
ImGuiStorage: Added bool helper functions for completeness.
This commit is contained in:
parent
ce4d731486
commit
69cc00f91f
15
imgui.cpp
15
imgui.cpp
|
@ -1313,6 +1313,11 @@ int ImGuiStorage::GetInt(ImU32 key, int default_val) const
|
||||||
return it->val_i;
|
return it->val_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGuiStorage::GetBool(ImU32 key, bool default_val) const
|
||||||
|
{
|
||||||
|
return GetInt(key, default_val ? 1 : 0) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
|
float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
|
||||||
{
|
{
|
||||||
ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
|
ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
|
||||||
|
@ -1338,6 +1343,11 @@ int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
|
||||||
return &it->val_i;
|
return &it->val_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool* ImGuiStorage::GetBoolRef(ImGuiID key, bool default_val)
|
||||||
|
{
|
||||||
|
return (bool*)GetIntRef(key, default_val ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
|
float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
|
||||||
{
|
{
|
||||||
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
||||||
|
@ -1366,6 +1376,11 @@ void ImGuiStorage::SetInt(ImU32 key, int val)
|
||||||
it->val_i = val;
|
it->val_i = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiStorage::SetBool(ImU32 key, bool val)
|
||||||
|
{
|
||||||
|
SetInt(key, val ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
void ImGuiStorage::SetFloat(ImU32 key, float val)
|
void ImGuiStorage::SetFloat(ImU32 key, float val)
|
||||||
{
|
{
|
||||||
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
ImVector<Pair>::iterator it = LowerBound(Data, key);
|
||||||
|
|
5
imgui.h
5
imgui.h
|
@ -975,6 +975,8 @@ struct ImGuiStorage
|
||||||
IMGUI_API void Clear();
|
IMGUI_API void Clear();
|
||||||
IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const;
|
IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const;
|
||||||
IMGUI_API void SetInt(ImGuiID key, int val);
|
IMGUI_API void SetInt(ImGuiID key, int val);
|
||||||
|
IMGUI_API bool GetBool(ImGuiID key, bool default_val = false) const;
|
||||||
|
IMGUI_API void SetBool(ImGuiID key, bool val);
|
||||||
IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const;
|
IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const;
|
||||||
IMGUI_API void SetFloat(ImGuiID key, float val);
|
IMGUI_API void SetFloat(ImGuiID key, float val);
|
||||||
IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
|
IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
|
||||||
|
@ -986,7 +988,8 @@ struct ImGuiStorage
|
||||||
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
|
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
|
||||||
// - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
|
// - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
|
||||||
IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0);
|
IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0);
|
||||||
IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0);
|
IMGUI_API bool* GetBoolRef(ImGuiID key, bool default_val = false);
|
||||||
|
IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0.0f);
|
||||||
IMGUI_API void** GetVoidPtrRef(ImGuiID key, void* default_val = NULL);
|
IMGUI_API void** GetVoidPtrRef(ImGuiID key, void* default_val = NULL);
|
||||||
|
|
||||||
// Use on your own storage if you know only integer are being stored (open/close all tree nodes)
|
// Use on your own storage if you know only integer are being stored (open/close all tree nodes)
|
||||||
|
|
Loading…
Reference in New Issue