From 69cc00f91fa440476453ab30d2597481f6b96c6d Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 7 May 2016 18:18:37 +0200 Subject: [PATCH] ImGuiStorage: Added bool helper functions for completeness. --- imgui.cpp | 15 +++++++++++++++ imgui.h | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 613e8db6f..b982a71e4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1313,6 +1313,11 @@ int ImGuiStorage::GetInt(ImU32 key, int default_val) const 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 { ImVector::iterator it = LowerBound(const_cast&>(Data), key); @@ -1338,6 +1343,11 @@ int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val) 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) { ImVector::iterator it = LowerBound(Data, key); @@ -1366,6 +1376,11 @@ void ImGuiStorage::SetInt(ImU32 key, int val) it->val_i = val; } +void ImGuiStorage::SetBool(ImU32 key, bool val) +{ + SetInt(key, val ? 1 : 0); +} + void ImGuiStorage::SetFloat(ImU32 key, float val) { ImVector::iterator it = LowerBound(Data, key); diff --git a/imgui.h b/imgui.h index 2a7199c9b..2683308c1 100644 --- a/imgui.h +++ b/imgui.h @@ -975,6 +975,8 @@ struct ImGuiStorage IMGUI_API void Clear(); IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const; 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 void SetFloat(ImGuiID key, float val); 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; // - 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 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); // Use on your own storage if you know only integer are being stored (open/close all tree nodes)