From 4ee5a792ff6148def9e5ca159ac4030fca0a6066 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 27 Mar 2015 15:18:45 +0000 Subject: [PATCH 1/6] Fixed new collapsed auto-resizing window with saved .ini settings not calculating their initial width #176 --- imgui.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index b6119acfc..120e60309 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2915,7 +2915,12 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl window->Size = window->SizeFull = size; } - if (ImLengthSqr(window->Size) < 0.00001f) + if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) + { + window->AutoFitFrames = 2; + window->AutoFitOnlyGrows = false; + } + else if (ImLengthSqr(window->Size) < 0.00001f) { window->AutoFitFrames = 2; window->AutoFitOnlyGrows = true; From ff35d24bcc110b8a698b18d35bbc282811d4006c Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 27 Mar 2015 19:34:01 +0000 Subject: [PATCH 2/6] Comments --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 120e60309..03c052ddb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10246,9 +10246,9 @@ static void ShowExampleAppManipulatingWindowTitle(bool* opened) ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique."); ImGui::End(); - // Using "###" to display a changing title but keep a static identifier "MyWindow" + // Using "###" to display a changing title but keep a static identifier "AnimatedTitle" char buf[128]; - ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###MyWindow", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand()); + ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d##AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand()); ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver); ImGui::Begin(buf); ImGui::Text("This window has a changing title."); From 3abfb8561358634fa4254e8ee6a24cb876859c3a Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 28 Mar 2015 11:48:42 +0000 Subject: [PATCH 3/6] Comments on font loading, fixed commented out paths and added DroidSans in the list --- examples/directx11_example/main.cpp | 10 +++++----- examples/directx9_example/main.cpp | 10 +++++----- examples/opengl3_example/main.cpp | 9 +++++---- examples/opengl_example/main.cpp | 9 +++++---- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 0064a93a1..80e20fb9b 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -149,11 +149,11 @@ int main(int, char**) // Setup ImGui binding ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); - //ImGuiIO& io = ImGui::GetIO(); - //ImFont* my_font1 = io.Fonts->AddFontDefault(); - //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f); - //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; - //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; + //ImFont* my_font0 = io.Fonts->AddFontDefault(); + //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f); + //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; + //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index ce8ca4774..b564dbc31 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -73,11 +73,11 @@ int main(int, char**) // Setup ImGui binding ImGui_ImplDX9_Init(hwnd, g_pd3dDevice); - //ImGuiIO& io = ImGui::GetIO(); - //ImFont* my_font1 = io.Fonts->AddFontDefault(); - //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f); - //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; - //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; + //ImFont* my_font0 = io.Fonts->AddFontDefault(); + //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f); + //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; + //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese()); ShowWindow(hwnd, SW_SHOWDEFAULT); diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 9f0207aaa..0e7187413 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -27,10 +27,11 @@ int main(int, char**) // Setup ImGui binding ImGui_ImplGlfwGL3_Init(window, true); //ImGuiIO& io = ImGui::GetIO(); - //ImFont* my_font1 = io.Fonts->AddFontDefault(); - //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f); - //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; - //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; + //ImFont* my_font0 = io.Fonts->AddFontDefault(); + //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f); + //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; + //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 92bf842cd..3ff10fe36 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -22,10 +22,11 @@ int main(int, char**) // Setup ImGui binding ImGui_ImplGlfw_Init(window, true); //ImGuiIO& io = ImGui::GetIO(); - //ImFont* my_font1 = io.Fonts->AddFontDefault(); - //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f); - //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; - //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; + //ImFont* my_font0 = io.Fonts->AddFontDefault(); + //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f); + //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; + //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; From e16f2e898a3053346356449cf7d80669002e569e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 29 Mar 2015 10:09:14 +0100 Subject: [PATCH 4/6] Version number 1.38 WIP --- imgui.cpp | 2 +- imgui.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 03c052ddb..92c024f74 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.37 +// ImGui library v1.38 WIP // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui diff --git a/imgui.h b/imgui.h index d914b6f6c..283960a26 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.37 +// ImGui library v1.38 WIP // See .cpp file for documentation. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. @@ -13,7 +13,7 @@ #include // NULL, malloc, free, qsort, atoi #include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp -#define IMGUI_VERSION "1.37" +#define IMGUI_VERSION "1.38 WIP" // Define assertion handler. #ifndef IM_ASSERT From 9d16b85ed2f72c0644889825d28f6c56e0abf79b Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 29 Mar 2015 19:45:03 +0100 Subject: [PATCH 5/6] Caching current Font, FontSize into state for quicker/simpler access. --- imgui.cpp | 101 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 92c024f74..48211ffdc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1088,7 +1088,8 @@ struct ImGuiState ImGuiIO IO; ImGuiStyle Style; ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() - float FontSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. + float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize() + float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite float Time; @@ -1157,7 +1158,7 @@ struct ImGuiState { Initialized = false; Font = NULL; - FontSize = 0.0f; + FontBaseSize = FontSize = 0.0f; FontTexUvWhitePixel = ImVec2(0.0f, 0.0f); Time = 0.0f; @@ -1261,10 +1262,8 @@ public: void FocusItemUnregister(); ImRect Rect() const { return ImRect(Pos, Pos+Size); } - ImFont* Font() const { return GImGui->Font; } - float FontSize() const { return GImGui->FontSize * FontWindowScale; } - ImVec2 CursorPos() const { return DC.CursorPos; } - float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; } + float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } + float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } ImRect TitleBarRect() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; } ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); } @@ -1279,6 +1278,14 @@ static inline ImGuiWindow* GetCurrentWindow() return g.CurrentWindow; } +static inline void SetCurrentWindow(ImGuiWindow* window) +{ + ImGuiState& g = *GImGui; + g.CurrentWindow = window; + if (window) + g.FontSize = window->CalcFontSize(); +} + static inline ImGuiWindow* GetParentWindow() { ImGuiState& g = *GImGui; @@ -1961,6 +1968,7 @@ void ImGui::NewFrame() float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); float scale = new_font_scale / window->FontWindowScale; window->FontWindowScale = new_font_scale; + g.FontSize = window->CalcFontSize(); const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; window->Pos += offset; @@ -1975,7 +1983,7 @@ void ImGui::NewFrame() if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse)) { const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; - window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; + window->NextScrollY -= g.IO.MouseWheel * g.FontSize * scroll_lines; } } } @@ -2351,7 +2359,7 @@ static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool if (text_len > 0) { // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end); + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end); // Log as text if (g.LogEnabled) @@ -2371,7 +2379,7 @@ static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end if (text_len > 0) { // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width); + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width); // Log as text if (g.LogEnabled) @@ -2395,7 +2403,7 @@ static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end const bool need_clipping = (pos.x + text_size.x >= clip_max.x) || (pos.y + text_size.y >= clip_max.y); // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? &clip_max : NULL); + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? &clip_max : NULL); // Log as text if (g.LogEnabled) @@ -2420,9 +2428,10 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, // Render a triangle to denote expanded/collapsed state static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow) { + ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - const float h = window->FontSize() * 1.00f; + const float h = g.FontSize * 1.00f; const float r = h * 0.40f * scale; ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale); @@ -2450,7 +2459,7 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool // CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize) ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = *GImGui; const char* text_display_end; if (hide_text_after_double_hash) @@ -2458,8 +2467,8 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex else text_display_end = text_end; - ImFont* font = window->Font(); - const float font_size = window->FontSize(); + ImFont* font = g.Font; + const float font_size = g.FontSize; ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL); // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field) @@ -2963,7 +2972,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ // Add to stack g.CurrentWindowStack.push_back(window); - g.CurrentWindow = window; + SetCurrentWindow(window); // Process SetNextWindow***() calls bool window_pos_set_by_api = false; @@ -3331,7 +3340,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ if (!(window->Flags & ImGuiWindowFlags_NoCollapse)) { RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); - text_min.x += window->FontSize() + style.ItemInnerSpacing.x; + text_min.x += g.FontSize + style.ItemInnerSpacing.x; } const ImVec2 text_size = CalcTextSize(name, NULL, true); @@ -3418,7 +3427,7 @@ void ImGui::End() // Pop // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin(). g.CurrentWindowStack.pop_back(); - g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); + SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back()); } // Vertical scrollbar @@ -3549,7 +3558,8 @@ static void SetFont(ImFont* font) IM_ASSERT(font && font->IsLoaded()); IM_ASSERT(font->Scale > 0.0f); g.Font = font; - g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; + g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; + g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f; g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel; } @@ -3948,15 +3958,14 @@ ImVec2 ImGui::GetWindowContentRegionMax() float ImGui::GetTextLineHeight() { - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize(); + ImGuiState& g = *GImGui; + return g.FontSize; } float ImGui::GetTextLineHeightWithSpacing() { ImGuiState& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize() + g.Style.ItemSpacing.y; + return g.FontSize + g.Style.ItemSpacing.y; } ImDrawList* ImGui::GetWindowDrawList() @@ -3967,20 +3976,22 @@ ImDrawList* ImGui::GetWindowDrawList() ImFont* ImGui::GetWindowFont() { - ImGuiWindow* window = GetCurrentWindow(); - return window->Font(); + ImGuiState& g = *GImGui; + return g.Font; } float ImGui::GetWindowFontSize() { - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize(); + ImGuiState& g = *GImGui; + return g.FontSize; } void ImGui::SetWindowFontScale(float scale) { + ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); window->FontWindowScale = scale; + g.FontSize = window->CalcFontSize(); } // NB: internally we store CursorPos in absolute screen coordinates because it is more convenient. @@ -4235,7 +4246,7 @@ void ImGui::AlignFirstTextHeightToWidgets() return; // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height. - ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2), g.Style.FramePadding.y); + ItemSize(ImVec2(0, g.FontSize + g.Style.FramePadding.y*2), g.Style.FramePadding.y); ImGui::SameLine(0, 0); } @@ -4697,7 +4708,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display } // FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize - const ImRect text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size); + const ImRect text_bb(bb.Min, bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2*2,0) + label_size); ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f); // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior). @@ -4729,7 +4740,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display const char log_prefix[] = "\n##"; LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3); } - RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + RenderText(bb.Min + style.FramePadding + ImVec2(g.FontSize + style.FramePadding.x*2,0), label); if (g.LogEnabled) { const char log_suffix[] = "##"; @@ -4741,10 +4752,10 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display // Unframed typed for tree nodes if ((held && hovered) || hovered) RenderFrame(bb.Min, bb.Max, col, false); - RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false); + RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false); if (g.LogEnabled) LogText(bb.Min, ">"); - RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2,0), label); } return opened; @@ -4758,7 +4769,7 @@ void ImGui::Bullet() return; const ImGuiStyle& style = g.Style; - const float line_height = window->FontSize(); + const float line_height = g.FontSize; const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height)); ItemSize(bb); if (!ItemAdd(bb, NULL)) @@ -4784,7 +4795,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); const ImGuiStyle& style = g.Style; - const float line_height = window->FontSize(); + const float line_height = g.FontSize; const ImVec2 label_size = CalcTextSize(text_begin, text_end, true); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding ItemSize(bb); @@ -4794,7 +4805,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // Render const float bullet_size = line_height*0.15f; window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); - RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end); + RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2,0), text_begin, text_end); } void ImGui::BulletText(const char* fmt, ...) @@ -5856,7 +5867,7 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, ImGui::BeginGroup(); ImGui::PushID(label); - const ImVec2 button_sz = ImVec2(window->FontSize(), window->FontSize()) + style.FramePadding * 2; + const ImVec2 button_sz = ImVec2(g.FontSize, g.FontSize) + style.FramePadding * 2; if (step > 0.0f) ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2)); @@ -6101,15 +6112,15 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT // Update some data if we are active or last active edit_state.Width = w + style.FramePadding.x; edit_state.BufSizeA = buf_size; - edit_state.Font = window->Font(); - edit_state.FontSize = window->FontSize(); + edit_state.Font = g.Font; + edit_state.FontSize = g.FontSize; edit_state.UpdateScrollOffset(); } if (g.ActiveId == id) { // Edit in progress const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x; - const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit + const float my = g.FontSize*0.5f; // Flatten mouse because we are doing a single-line edit if (select_all || (hovered && io.MouseDoubleClicked[0])) { @@ -6294,8 +6305,8 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); - const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API - const ImVec2 font_off_dn = ImVec2(0.0f,2.0f); + const ImVec2 font_off_up = ImVec2(0.0f, g.FontSize+1.0f); // FIXME: those offsets are part of the style or font API + const ImVec2 font_off_dn = ImVec2(0.0f, 2.0f); if (g.ActiveId == id) { @@ -6312,7 +6323,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT //const float render_scroll_x = (g.ActiveId == id) ? edit_state.ScrollX : 0.0f; const float render_scroll_x = (edit_state.Id == id) ? edit_state.ScrollX : 0.0f; - ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w + style.FramePadding.x, render_scroll_x); + ImGuiTextEditState::RenderTextScrolledClipped(g.Font, g.FontSize, buf, frame_bb.Min + style.FramePadding, w + style.FramePadding.x, render_scroll_x); if (g.ActiveId == id) { @@ -6324,7 +6335,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT // Notify OS of text input position for advanced IME if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f) - io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. + io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - g.FontSize)); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. edit_state.InputCursorScreenPos = cursor_pos; } @@ -6511,7 +6522,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi if (!ItemAdd(total_bb, &id)) return false; - const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); + const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f); const bool hovered = IsHovered(frame_bb, id); bool value_changed = false; @@ -6757,7 +6768,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID("#colorbutton"); - const float square_size = window->FontSize(); + const float square_size = g.FontSize; const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); ItemSize(bb, small_height ? 0.0f : style.FramePadding.y); if (!ItemAdd(bb, &id)) @@ -6805,7 +6816,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); const float w_full = ImGui::CalcItemWidth(); - const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f); + const float square_sz = (g.FontSize + style.FramePadding.x * 2.0f); ImGuiColorEditMode edit_mode = window->DC.ColorEditMode; if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton) From 0a31531f44717e265646aa1d47949303d45c2d69 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 30 Mar 2015 21:16:24 +0100 Subject: [PATCH 6/6] Warning fix in demo code --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 48211ffdc..83d5b41f6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9502,7 +9502,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::BeginPopup(&popup_open); ImGui::Text("Aquarium"); ImGui::Separator(); - for (size_t i = 0; i < IM_ARRAYSIZE(fishes); i++) + for (int i = 0; i < IM_ARRAYSIZE(fishes); i++) { if (ImGui::Selectable(fishes[i], false)) {