From 7437b43b2d946c28ae1be98ae2d5bd3b2041af8d Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 3 Jul 2015 08:15:56 -0600 Subject: [PATCH 1/5] Fixed warnings for more pedantic settings (#258) --- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 2 +- examples/opengl_example/imgui_impl_glfw.cpp | 2 +- imgui.cpp | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index acd36d03..4795f3bd 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -69,7 +69,7 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawList** const cmd_lists, int if (g_VboSize < needed_vtx_size) { g_VboSize = needed_vtx_size + 5000 * sizeof(ImDrawVert); // Grow buffer - glBufferData(GL_ARRAY_BUFFER, g_VboSize, NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW); } // Copy and convert all vertices into a single contiguous buffer diff --git a/examples/opengl_example/imgui_impl_glfw.cpp b/examples/opengl_example/imgui_impl_glfw.cpp index 00390e2c..3ac9cda5 100644 --- a/examples/opengl_example/imgui_impl_glfw.cpp +++ b/examples/opengl_example/imgui_impl_glfw.cpp @@ -76,7 +76,7 @@ static void ImGui_ImplGlfw_RenderDrawLists(ImDrawList** const cmd_lists, int cmd { glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id); glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); - glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); + glDrawArrays(GL_TRIANGLES, vtx_offset, (GLsizei)pcmd->vtx_count); } vtx_offset += pcmd->vtx_count; } diff --git a/imgui.cpp b/imgui.cpp index 002cea48..9cb91d86 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -719,10 +719,8 @@ void ImGuiIO::AddInputCharacter(ImWchar c) const float IM_PI = 3.14159265358979323846f; #ifdef INT_MAX -#define IM_INT_MIN INT_MIN #define IM_INT_MAX INT_MAX #else -#define IM_INT_MIN (-2147483647-1) #define IM_INT_MAX (2147483647) #endif @@ -742,7 +740,7 @@ static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } -static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } +//static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-lhs.w); } @@ -11530,7 +11528,7 @@ void ImGui::ShowTestWindow(bool* opened) if (i > 0) ImGui::SameLine(); ImGui::BeginGroup(); ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom"); - ImGui::BeginChild(ImGui::GetID((void *)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true); + ImGui::BeginChild(ImGui::GetID((void *)(intptr_t)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true); if (scroll_to) ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f); for (int line = 0; line < 100; line++) From fd3c6067bfa81f2520740aebcc3678757d5309ab Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 3 Jul 2015 15:31:54 -0600 Subject: [PATCH 2/5] Add conditional #ifdef prior to imconfig.h to facilitate inclusion in build systems (#255) --- imgui.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui.h b/imgui.h index 66d800c9..226ffb56 100644 --- a/imgui.h +++ b/imgui.h @@ -6,7 +6,9 @@ #pragma once +#if !defined(IMGUI_DISABLE_INCLUDE_IMCONFIG_H) || defined(IMGUI_INCLUDE_IMCONFIG_H) #include "imconfig.h" // User-editable configuration file +#endif #include // FLT_MAX #include // va_list #include // ptrdiff_t, NULL From e9b81dd5ab7cf5edd477e669ddfe5e5164f3d04f Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 3 Jul 2015 15:32:10 -0600 Subject: [PATCH 3/5] Comments --- imgui.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.h b/imgui.h index 226ffb56..1f6ae128 100644 --- a/imgui.h +++ b/imgui.h @@ -60,7 +60,7 @@ struct ImVec2 ImVec2() { x = y = 0.0f; } ImVec2(float _x, float _y) { x = _x; y = _y; } -#ifdef IM_VEC2_CLASS_EXTRA // Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2. +#ifdef IM_VEC2_CLASS_EXTRA // Define constructor and implicit cast operators in imconfig.h to convert back<>forth from your math types and ImVec2. IM_VEC2_CLASS_EXTRA #endif }; @@ -71,7 +71,7 @@ struct ImVec4 ImVec4() { x = y = z = w = 0.0f; } ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } -#ifdef IM_VEC4_CLASS_EXTRA // Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec4. +#ifdef IM_VEC4_CLASS_EXTRA // Define constructor and implicit cast operators in imconfig.h to convert back<>forth from your math types and ImVec4. IM_VEC4_CLASS_EXTRA #endif }; @@ -197,8 +197,8 @@ namespace ImGui IMGUI_API float GetItemsLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y // ID scopes - // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them - // You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide') + // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. + // You can also use "##extra" within your widget name to distinguish them from each others. Read the FAQ for more details. IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack! IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); IMGUI_API void PushID(const void* ptr_id); From a33810d6525f135c3e99c733fe09e53231b33903 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 Jul 2015 16:08:00 -0600 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4b52ccc..7f211b31 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ In your Render function, try translating your projection matrix by (0.5f,0.5f) o Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). -However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. Many programmers have unfortunately been taught by their environment to make complicated things instead of simple things. Strip yourself out of all those heavy layers and start making tools! +However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. Many programmers have unfortunately been taught by their environment to make complicated unproductive things. Strip yourself out of all those heavy layers and start making lots of useful tools! Is ImGui fast? From d76bc3434e4bb5b22eed5807e5b313291e6189d5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 4 Jul 2015 12:17:04 -0600 Subject: [PATCH 5/5] Added DragFloatRange2() DragIntRange2() helpers (#76) --- imgui.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ imgui.h | 2 ++ 2 files changed, 67 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 9cb91d86..2c3458b7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -719,8 +719,10 @@ void ImGuiIO::AddInputCharacter(ImWchar c) const float IM_PI = 3.14159265358979323846f; #ifdef INT_MAX +#define IM_INT_MIN INT_MIN #define IM_INT_MAX INT_MAX #else +#define IM_INT_MIN (-2147483647-1) #define IM_INT_MAX (2147483647) #endif @@ -6406,6 +6408,31 @@ bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power); } +bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed, float v_min, float v_max, const char* display_format, const char* display_format_max, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGui::PushID(label); + ImGui::BeginGroup(); + PushMultiItemsWidths(2); + + bool value_changed = ImGui::DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format, power); + ImGui::PopItemWidth(); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + value_changed |= ImGui::DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, display_format_max ? display_format_max : display_format, power); + ImGui::PopItemWidth(); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); + ImGui::PopID(); + + return value_changed; +} + // NB: v_speed is float to allow adjusting the drag speed with more precision bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format) { @@ -6459,6 +6486,31 @@ bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format); } +bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed, int v_min, int v_max, const char* display_format, const char* display_format_max) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGui::PushID(label); + ImGui::BeginGroup(); + PushMultiItemsWidths(2); + + bool value_changed = ImGui::DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? IM_INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format); + ImGui::PopItemWidth(); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + value_changed |= ImGui::DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? IM_INT_MAX : v_max, display_format_max ? display_format_max : display_format); + ImGui::PopItemWidth(); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); + ImGui::PopID(); + + return value_changed; +} + enum ImGuiPlotType { ImGuiPlotType_Lines, @@ -11171,6 +11223,19 @@ void ImGui::ShowTestWindow(bool* opened) //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4); //ImGui::PopItemWidth(); + if (ImGui::TreeNode("Ranges")) + { + ImGui::Unindent(); + + static float begin = 10, end = 90; + static int begin_i = 100, end_i = 1000; + ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units"); + + ImGui::Indent(); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Multi-component Widgets")) { ImGui::Unindent(); diff --git a/imgui.h b/imgui.h index 1f6ae128..46fc13b5 100644 --- a/imgui.h +++ b/imgui.h @@ -250,10 +250,12 @@ namespace ImGui IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); IMGUI_API bool DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", const char* display_format_max = NULL, float power = 1.0f); IMGUI_API bool DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); // If v_min >= v_max we have no bound IMGUI_API bool DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f", const char* display_format_max = NULL); // Widgets: Input IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);