From 00418d13e369bf53cc4b8f817eb10b8ce65f0904 Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Fri, 22 Jun 2018 17:45:03 +0200 Subject: [PATCH 1/8] Demo: Fixed mismatched TreePush/TreePop in Property Editor, due to incorrect revert in 826d77185e5967b5d572304945e37102efb58181 (#1895) --- imgui_demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8c31ea03..8a0665a1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3220,7 +3220,7 @@ static void ShowExampleAppPropertyEditor(bool* p_open) { // Here we use a TreeNode to highlight on hover (we could use e.g. Selectable as well) ImGui::AlignTextToFramePadding(); - ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_Bullet, "Field_%d", i); + ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet, "Field_%d", i); ImGui::NextColumn(); ImGui::PushItemWidth(-1); if (i >= 5) From 20e89201cb12b9b958f8b0dc24e12649f163380d Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Sat, 23 Jun 2018 09:42:47 +0200 Subject: [PATCH 2/8] Examples: Fixes. --- examples/example_glfw_opengl3/build_win32.bat | 2 +- examples/imgui_impl_dx12.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_glfw_opengl3/build_win32.bat b/examples/example_glfw_opengl3/build_win32.bat index 8b54affd..e5c15c53 100644 --- a/examples/example_glfw_opengl3/build_win32.bat +++ b/examples/example_glfw_opengl3/build_win32.bat @@ -1,3 +1,3 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. mkdir Debug -cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include /I ..\libs\gl3w *.cpp ..\imgui_impl_glfw.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/example_glfw_opengl3.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib +cl /nologo /Zi /MD /I .. /I ..\.. /I ..\libs\glfw\include /I ..\libs\gl3w *.cpp ..\imgui_impl_glfw.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/example_glfw_opengl3.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 15fb7119..f8ceab3c 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -365,7 +365,7 @@ static void ImGui_ImplDX12_CreateFontsTexture() } // Store our identifier - static_assert(sizeof(ImTextureID) >= sizeof(g_hFontSrvGpuDescHandle.ptr), "Can't pack descriptor handle into TexID"); + static_assert(sizeof(ImTextureID) >= sizeof(g_hFontSrvGpuDescHandle.ptr), "Can't pack descriptor handle into TexID, 32-bit not supported yet."); io.Fonts->TexID = (void *)g_hFontSrvGpuDescHandle.ptr; } From fb0106fad270de2a7669f7e7c55c4f5def17ab94 Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Mon, 25 Jun 2018 09:32:55 +0200 Subject: [PATCH 3/8] Demo: Fixed incorrect response to Begin() returning false in overlay demo (which cannot happen since we don't have a title bar, but that doesn't make it a good behaving demo!). --- imgui_demo.cpp | 2 +- imgui_draw.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8a0665a1..500e08b6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2608,8 +2608,8 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) if (p_open && ImGui::MenuItem("Close")) *p_open = false; ImGui::EndPopup(); } - ImGui::End(); } + ImGui::End(); } // Demonstrate using "##" and "###" in identifiers to manipulate ID generation. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1945ed09..427594d3 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2855,8 +2855,9 @@ void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, Im //----------------------------------------------------------------------------- // DEFAULT FONT DATA //----------------------------------------------------------------------------- -// Compressed with stb_compress() then converted to a C array. +// Compressed with stb_compress() then converted to a C array and encoded as base85. // Use the program in misc/fonts/binary_to_compressed_c.cpp to create the array from a TTF file. +// The purpose of encoding as base85 instead of "0x00,0x01,..." style is only save on _source code_ size. // Decompression from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h //----------------------------------------------------------------------------- @@ -2978,7 +2979,8 @@ static unsigned int stb_decompress(unsigned char *output, const unsigned char *i // Download and more information at http://upperbounds.net //----------------------------------------------------------------------------- // File: 'ProggyClean.ttf' (41208 bytes) -// Exported using binary_to_compressed_c.cpp +// Exported using misc/fonts/binary_to_compressed_c.cpp (with compression + base85 string encoding). +// The purpose of encoding as base85 instead of "0x00,0x01,..." style is only save on _source code_ size. //----------------------------------------------------------------------------- static const char proggy_clean_ttf_compressed_data_base85[11980+1] = "7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/" From c1d8dee6c5b6d0ee1c33901ade096d5a4459da71 Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Mon, 25 Jun 2018 09:40:09 +0200 Subject: [PATCH 4/8] Version 1.63 WIP --- imgui.cpp | 2 +- imgui.h | 4 ++-- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 0148099d..e4e340be 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.62 +// dear imgui, v1.63 WIP // (main code and documentation) // Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. diff --git a/imgui.h b/imgui.h index 1e0de67e..2f8f40f6 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.62 +// dear imgui, v1.63 WIP // (headers) // See imgui.cpp file for documentation. @@ -22,7 +22,7 @@ #include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp // Version -#define IMGUI_VERSION "1.62" +#define IMGUI_VERSION "1.63 WIP" #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 500e08b6..f8fc547d 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.62 +// dear imgui, v1.63 WIP // (demo code) // Message to the person tempted to delete this file when integrating ImGui into their code base: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 427594d3..cb1ed9d7 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.62 +// dear imgui, v1.63 WIP // (drawing and font code) // Contains implementation for diff --git a/imgui_internal.h b/imgui_internal.h index bd129ae6..ec04672a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.62 +// dear imgui, v1.63 WIP // (internals) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! From a1ec7723ef2a80571199ec0fbb9ecccfb7658372 Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Mon, 25 Jun 2018 09:50:06 +0200 Subject: [PATCH 5/8] Examples: OpenGL3: Remove misleading or unnecessary "#version 150" strings. --- examples/imgui_impl_opengl3.cpp | 2 +- examples/imgui_impl_opengl3.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index a24af552..fb266e93 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -31,7 +31,7 @@ //#include <glew.h> // OpenGL Data -static char g_GlslVersion[32] = "#version 150"; +static char g_GlslVersion[32] = ""; static GLuint g_FontTexture = 0; static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index e49ff761..1dbb5da6 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -9,7 +9,7 @@ // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! -IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = "#version 150"); +IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); From 9d67d18d86f2727e3a05ab8696168fcf8befd99e Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Mon, 25 Jun 2018 14:01:21 +0200 Subject: [PATCH 6/8] Internals: Moved some of the SliderBehaviorT code into SliderBehavior to reduce the amount of instanciated code. --- imgui.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e4e340be..51af4877 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9073,14 +9073,9 @@ template<typename TYPE, typename SIGNEDTYPE, typename FLOATTYPE> static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, float power, ImGuiSliderFlags flags) { ImGuiContext& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = g.CurrentWindow; const ImGuiStyle& style = g.Style; - // Draw frame - const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); - RenderNavHighlight(bb, id); - RenderFrame(bb.Min, bb.Max, frame_col, true, style.FrameRounding); - const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0; const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); const bool is_power = (power != 1.0f) && is_decimal; @@ -9241,10 +9236,16 @@ static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType d } // For 32-bits and larger types, slider bounds are limited to half the natural type range. -// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2. -// It would be possible to life that limitation with some work but it doesn't seem to be work it for sliders. +// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2 will be ok. +// It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders. bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags) { + // Draw frame + ImGuiContext& g = *GImGui; + const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); + RenderNavHighlight(bb, id); + RenderFrame(bb.Min, bb.Max, frame_col, true, g.Style.FrameRounding); + switch (data_type) { case ImGuiDataType_S32: @@ -9520,7 +9521,7 @@ static bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed if (g.IO.KeyShift) adjust_delta *= 10.0f; } - if (g.ActiveIdSource == ImGuiInputSource_Nav) + else if (g.ActiveIdSource == ImGuiInputSource_Nav) { int decimal_precision = (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImParseFormatPrecision(format, 3) : 0; adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x; From 14ceaaf4607f999a5a425dd906e13b4ba81678ad Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Tue, 26 Jun 2018 12:37:10 +0200 Subject: [PATCH 7/8] ArrowButton: Fixed to honor PushButtonRepeat() setting (and internals' ImGuiItemFlags_ButtonRepeat). Setup current line text baseline so that ArrowButton() + SameLine() + Text() are aligned properly. --- CHANGELOG.txt | 9 +++++++++ imgui.cpp | 21 +++++++++++++++------ imgui_demo.cpp | 45 +++++++++++++++++++++++++++++---------------- imgui_internal.h | 1 + 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 39bcfa50..32e9bdfe 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -29,6 +29,15 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.63 WIP (IN PROGRESS) +----------------------------------------------------------------------- + +Other Changes: + - ArrowButton: Fixed to honor PushButtonRepeat() setting (and internals' ImGuiItemFlags_ButtonRepeat). + - ArrowButton: Setup current line text baseline so that ArrowButton() + SameLine() + Text() are aligned properly. + + ----------------------------------------------------------------------- VERSION 1.62 (Released 2018-06-22) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 51af4877..c33b53ae 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8072,7 +8072,7 @@ bool ImGui::SmallButton(const char* label) return pressed; } -bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir) +bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiButtonFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -8080,24 +8080,33 @@ bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir) ImGuiContext& g = *GImGui; const ImGuiID id = window->GetID(str_id); - float sz = ImGui::GetFrameHeight(); - const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(sz, sz)); - ItemSize(bb); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + const float default_size = GetFrameHeight(); + ItemSize(bb, (size.y >= default_size) ? g.Style.FramePadding.y : 0.0f); if (!ItemAdd(bb, id)) return false; + if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) + flags |= ImGuiButtonFlags_Repeat; + bool hovered, held; - bool pressed = ButtonBehavior(bb, id, &hovered, &held); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); // Render const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, g.Style.FrameRounding); - RenderArrow(bb.Min + g.Style.FramePadding, dir); + RenderArrow(bb.Min + ImVec2(ImMax(0.0f, size.x - g.FontSize - g.Style.FramePadding.x), ImMax(0.0f, size.y - g.FontSize - g.Style.FramePadding.y)), dir); return pressed; } +bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir) +{ + float sz = GetFrameHeight(); + return ArrowButtonEx(str_id, dir, ImVec2(sz, sz), 0); +} + // Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack. // Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id) bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index f8fc547d..a8c41dce 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -12,11 +12,11 @@ // Thank you, // -Your beloved friend, imgui_demo.cpp (that you won't delete) -// Message to beginner C/C++ programmers. About the meaning of 'static': in this demo code, we frequently we use 'static' variables inside functions. -// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code. +// Message to beginner C/C++ programmers about the meaning of the 'static' keyword: in this demo code, we frequently we use 'static' variables inside functions. // A static variable persist across calls, so it is essentially like a global variable but declared inside the scope of the function. +// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code. // It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant or used in threads. -// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your function. +// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your functions. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS @@ -76,6 +76,7 @@ #if !defined(IMGUI_DISABLE_DEMO_WINDOWS) +// Forward Declarations static void ShowExampleAppConsole(bool* p_open); static void ShowExampleAppLog(bool* p_open); static void ShowExampleAppLayout(bool* p_open); @@ -89,6 +90,7 @@ static void ShowExampleAppCustomRendering(bool* p_open); static void ShowExampleAppMainMenuBar(); static void ShowExampleMenuFile(); +// Helper to display a little (?) mark which shows a tooltip when hovered. static void ShowHelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); @@ -102,6 +104,7 @@ static void ShowHelpMarker(const char* desc) } } +// Helper to display basic user controls. void ImGui::ShowUserGuide() { ImGui::BulletText("Double-click on title bar to collapse window."); @@ -124,10 +127,11 @@ void ImGui::ShowUserGuide() ImGui::Unindent(); } -// Demonstrate most ImGui features (big function!) +// Demonstrate most Dear ImGui features (this is big function!) +// You may execute this function to experiment with the UI and understand what it does. You may then search for keywords in the code when you are interested by a specific feature. void ImGui::ShowDemoWindow(bool* p_open) { - // Examples apps + // Examples Apps (accessible from the "Examples" menu) static bool show_app_main_menu_bar = false; static bool show_app_console = false; static bool show_app_log = false; @@ -139,10 +143,6 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool show_app_simple_overlay = false; static bool show_app_window_titles = false; static bool show_app_custom_rendering = false; - static bool show_app_style_editor = false; - - static bool show_app_metrics = false; - static bool show_app_about = false; if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); if (show_app_console) ShowExampleAppConsole(&show_app_console); @@ -156,6 +156,11 @@ void ImGui::ShowDemoWindow(bool* p_open) if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles); if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering); + // Dear ImGui Apps (accessible from the "Help" menu) + static bool show_app_metrics = false; + static bool show_app_style_editor = false; + static bool show_app_about = false; + if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); } if (show_app_style_editor) { ImGui::Begin("Style Editor", &show_app_style_editor); ImGui::ShowStyleEditor(); ImGui::End(); } if (show_app_about) @@ -168,6 +173,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::End(); } + // Demonstrate the various window flags. Typically you would just use the default! static bool no_titlebar = false; static bool no_scrollbar = false; static bool no_menu = false; @@ -177,7 +183,6 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool no_close = false; static bool no_nav = false; - // Demonstrate the various window flags. Typically you would just use the default. ImGuiWindowFlags window_flags = 0; if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar; if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar; @@ -188,19 +193,22 @@ void ImGui::ShowDemoWindow(bool* p_open) if (no_nav) window_flags |= ImGuiWindowFlags_NoNav; if (no_close) p_open = NULL; // Don't pass our bool* to Begin + // We specify a default size in case there's no data in the .ini file. Typically this isn't required! We only do it to make the Demo applications a little more welcoming. ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiCond_FirstUseEver); + + // Main body of the Demo window starts here. if (!ImGui::Begin("ImGui Demo", p_open, window_flags)) { // Early out if the window is collapsed, as an optimization. ImGui::End(); return; } - - //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels - ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels - ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION); + // Most "big" widgets share a common width settings by default. + //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // Use 2/3 of the space for widgets and 1/3 for labels (default) + ImGui::PushItemWidth(ImGui::GetFontSize() * -12); // Use fixed width for labels (by passing a negative value), the rest goes to widgets. We choose a width proportional to our font size. + // Menu if (ImGui::BeginMenuBar()) { @@ -302,10 +310,15 @@ void ImGui::ShowDemoWindow(bool* p_open) } // Arrow buttons + static int counter = 0; float spacing = ImGui::GetStyle().ItemInnerSpacing.x; - if (ImGui::ArrowButton("##left", ImGuiDir_Left)) {} + ImGui::PushButtonRepeat(true); + if (ImGui::ArrowButton("##left", ImGuiDir_Left)) { counter--; } ImGui::SameLine(0.0f, spacing); - if (ImGui::ArrowButton("##left", ImGuiDir_Right)) {} + if (ImGui::ArrowButton("##right", ImGuiDir_Right)) { counter++; } + ImGui::PopButtonRepeat(); + ImGui::SameLine(); + ImGui::Text("%d", counter); ImGui::Text("Hover over me"); if (ImGui::IsItemHovered()) diff --git a/imgui_internal.h b/imgui_internal.h index ec04672a..db4429e9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1154,6 +1154,7 @@ namespace ImGui IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); + IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags); IMGUI_API bool DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format, float power); IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags = 0); From 79153cf19f53726d556637c270fc0b11122835a0 Mon Sep 17 00:00:00 2001 From: omar <omarcornut@gmail.com> Date: Sat, 23 Jun 2018 20:08:19 +0200 Subject: [PATCH 8/8] Internals: Various renaming. e.g. NewFrameUpdateHoveredWindowAndCaptureFlags() to UpdateHoveredWindowAndCaptureFlags() + exposed UpdateMovingWindow() in imgui_internal.h. --- imgui.cpp | 13 ++++++------- imgui_internal.h | 5 +++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c33b53ae..77a66f64 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -441,7 +441,7 @@ Note: The 'io.WantCaptureMouse' is more accurate that any attempt to "check if the mouse is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs. Those flags are updated by ImGui::NewFrame(). Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also - perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you might find use for an early call to NewFrameUpdateHoveredWindowAndCaptureFlags(). + perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you might find use for an early call to UpdateHoveredWindowAndCaptureFlags(). Note: Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) @@ -855,7 +855,6 @@ static void NavUpdate(); static void NavUpdateWindowing(); static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id); -static void UpdateMovingWindow(); static void UpdateMouseInputs(); static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]); static void FocusFrontMostActiveWindow(ImGuiWindow* ignore_window); @@ -2070,7 +2069,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) CollapseToggleWanted = false; SkipItems = false; Appearing = false; - CloseButton = false; + HasCloseButton = false; BeginOrderWithinParent = -1; BeginOrderWithinContext = -1; BeginCount = 0; @@ -3503,7 +3502,7 @@ static void ImGui::NavUpdate() #endif } -static void ImGui::UpdateMovingWindow() +void ImGui::UpdateMovingWindow() { ImGuiContext& g = *GImGui; if (g.MovingWindow != NULL) @@ -3592,7 +3591,7 @@ static void ImGui::UpdateMouseInputs() } // The reason this is exposed in imgui_internal.h is: on touch-based system that don't have hovering, we want to dispatch inputs to the right target (imgui vs imgui+app) -void ImGui::NewFrameUpdateHoveredWindowAndCaptureFlags() +void ImGui::UpdateHoveredWindowAndCaptureFlags() { ImGuiContext& g = *GImGui; @@ -3763,7 +3762,7 @@ void ImGui::NewFrame() // Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering) UpdateMovingWindow(); - NewFrameUpdateHoveredWindowAndCaptureFlags(); + UpdateHoveredWindowAndCaptureFlags(); if (GetFrontMostPopupModal() != NULL) g.ModalWindowDarkeningRatio = ImMin(g.ModalWindowDarkeningRatio + g.IO.DeltaTime * 6.0f, 1.0f); @@ -6030,7 +6029,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window_just_activated_by_user |= (window != popup_ref.Window); } window->Appearing = (window_just_activated_by_user || window_just_appearing_after_hidden_for_resize); - window->CloseButton = (p_open != NULL); + window->HasCloseButton = (p_open != NULL); if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); diff --git a/imgui_internal.h b/imgui_internal.h index db4429e9..16674ee2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -966,7 +966,7 @@ struct IMGUI_API ImGuiWindow bool CollapseToggleWanted; bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) bool Appearing; // Set during the frame where the window is appearing (or re-appearing) - bool CloseButton; // Set when the window has a close button (p_open != NULL) + bool HasCloseButton; // Set when the window has a close button (p_open != NULL) int BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. int BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues. int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) @@ -1070,7 +1070,8 @@ namespace ImGui IMGUI_API void Initialize(ImGuiContext* context); IMGUI_API void Shutdown(ImGuiContext* context); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext(). - IMGUI_API void NewFrameUpdateHoveredWindowAndCaptureFlags(); + IMGUI_API void UpdateHoveredWindowAndCaptureFlags(); + IMGUI_API void UpdateMovingWindow(); IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window);