From 1f6ad7a894d11c2956c1cd0ade978efb15cba1c8 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 10 Mar 2018 10:33:12 +0100 Subject: [PATCH 1/8] ImFont: Added FindGlyphNoFallback. Fixed MergeMode broken by 1ef1acbd8d7d46ac6fe083b331dadf9324dc7e07 --- imgui.h | 1 + imgui_demo.cpp | 7 ++----- imgui_draw.cpp | 28 ++++++++++++++++++---------- misc/freetype/imgui_freetype.cpp | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/imgui.h b/imgui.h index 708e6296..9b4cf2c9 100644 --- a/imgui.h +++ b/imgui.h @@ -1784,6 +1784,7 @@ struct ImFont IMGUI_API void ClearOutputData(); IMGUI_API void BuildLookupTable(); IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const; + IMGUI_API const ImFontGlyph*FindGlyphNoFallback(ImWchar c) const; IMGUI_API void SetFallbackChar(ImWchar c); float GetCharAdvance(ImWchar c) const { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; } bool IsLoaded() const { return ContainerAtlas != NULL; } diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 713a929d..2a94de4e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2222,13 +2222,11 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) { // Display all glyphs of the fonts in separate pages of 256 characters - const ImFontGlyph* glyph_fallback = font->FallbackGlyph; // Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior. - font->FallbackGlyph = NULL; for (int base = 0; base < 0x10000; base += 256) { int count = 0; for (int n = 0; n < 256; n++) - count += font->FindGlyph((ImWchar)(base + n)) ? 1 : 0; + count += font->FindGlyphNoFallback((ImWchar)(base + n)) ? 1 : 0; if (count > 0 && ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base+255, count, count > 1 ? "glyphs" : "glyph")) { float cell_spacing = style.ItemSpacing.y; @@ -2239,7 +2237,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) { ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size.x + cell_spacing), base_pos.y + (n / 16) * (cell_size.y + cell_spacing)); ImVec2 cell_p2(cell_p1.x + cell_size.x, cell_p1.y + cell_size.y); - const ImFontGlyph* glyph = font->FindGlyph((ImWchar)(base+n)); + const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base+n)); draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255,255,255,100) : IM_COL32(255,255,255,50)); font->RenderChar(draw_list, cell_size.x, cell_p1, ImGui::GetColorU32(ImGuiCol_Text), (ImWchar)(base+n)); // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string. if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2)) @@ -2257,7 +2255,6 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::TreePop(); } } - font->FallbackGlyph = glyph_fallback; ImGui::TreePop(); } ImGui::TreePop(); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 027283dd..dd445781 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1841,7 +1841,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) continue; const int codepoint = range.first_unicode_codepoint_in_range + char_idx; - if (cfg.MergeMode && dst_font->FindGlyph((unsigned short)codepoint)) + if (cfg.MergeMode && dst_font->FindGlyphNoFallback((unsigned short)codepoint)) continue; stbtt_aligned_quad q; @@ -2205,8 +2205,7 @@ void ImFont::BuildLookupTable() IndexLookup[(int)tab_glyph.Codepoint] = (unsigned short)(Glyphs.Size-1); } - FallbackGlyph = NULL; - FallbackGlyph = FindGlyph(FallbackChar); + FallbackGlyph = FindGlyphNoFallback(FallbackChar); FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f; for (int i = 0; i < max_codepoint + 1; i++) if (IndexAdvanceX[i] < 0.0f) @@ -2268,13 +2267,22 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst) const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const { - if (c < IndexLookup.Size) - { - const unsigned short i = IndexLookup[c]; - if (i != (unsigned short)-1) - return &Glyphs.Data[i]; - } - return FallbackGlyph; + if (c >= IndexLookup.Size) + return FallbackGlyph; + const unsigned short i = IndexLookup[c]; + if (i == (unsigned short)-1) + return FallbackGlyph; + return &Glyphs.Data[i]; +} + +const ImFontGlyph* ImFont::FindGlyphNoFallback(ImWchar c) const +{ + if (c >= IndexLookup.Size) + return NULL; + const unsigned short i = IndexLookup[c]; + if (i == (unsigned short)-1) + return NULL; + return &Glyphs.Data[i]; } const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 54957112..37526d78 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -333,7 +333,7 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags) { for (uint32_t codepoint = in_range[0]; codepoint <= in_range[1]; ++codepoint) { - if (cfg.MergeMode && dst_font->FindGlyph((unsigned short)codepoint)) + if (cfg.MergeMode && dst_font->FindGlyphNoFallback((unsigned short)codepoint)) continue; FT_Glyph ft_glyph = NULL; From b9ac127b0b272147f2e63b61ecb479bae8acab0b Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 11:03:27 +0100 Subject: [PATCH 2/8] Internals: Columns renaming fields --- imgui.cpp | 19 ++++++++++--------- imgui_internal.h | 8 ++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6890fac3..0913819c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1807,13 +1807,14 @@ float ImGuiMenuColumns::CalcExtraSpace(float avail_w) static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height) { // Set cursor position and a few other things so that SetScrollHere() and Columns() can work when seeking cursor. - // FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue. Consider moving within SetCursorXXX functions? + // FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue. + // The clipper should probably have a 4th step to display the last item in a regular manner. ImGui::SetCursorPosY(pos_y); ImGuiWindow* window = ImGui::GetCurrentWindow(); window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHere() can properly function after the end of our clipper usage. window->DC.PrevLineHeight = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list. if (window->DC.ColumnsSet) - window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly + window->DC.ColumnsSet->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly } // Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1 @@ -12103,7 +12104,7 @@ void ImGui::Separator() if (window->DC.ColumnsSet) { PushColumnClipRect(); - window->DC.ColumnsSet->CellMinY = window->DC.CursorPos.y; + window->DC.ColumnsSet->LineMinY = window->DC.CursorPos.y; } } @@ -12322,7 +12323,7 @@ void ImGui::NextColumn() PopClipRect(); ImGuiColumnsSet* columns = window->DC.ColumnsSet; - columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y); + columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y); if (++columns->Current < columns->Count) { // Columns 1+ cancel out IndentX @@ -12334,10 +12335,10 @@ void ImGui::NextColumn() window->DC.ColumnsOffsetX = 0.0f; window->DrawList->ChannelsSetCurrent(0); columns->Current = 0; - columns->CellMinY = columns->CellMaxY; + columns->LineMinY = columns->LineMaxY; } window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); - window->DC.CursorPos.y = columns->CellMinY; + window->DC.CursorPos.y = columns->LineMinY; window->DC.CurrentLineHeight = 0.0f; window->DC.CurrentLineTextBaseOffset = 0.0f; @@ -12508,7 +12509,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag columns->MaxX = ImMax(content_region_width - window->Scroll.x, columns->MinX + 1.0f); columns->StartPosY = window->DC.CursorPos.y; columns->StartMaxPosX = window->DC.CursorMaxPos.x; - columns->CellMinY = columns->CellMaxY = window->DC.CursorPos.y; + columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y; window->DC.ColumnsOffsetX = 0.0f; window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); @@ -12555,8 +12556,8 @@ void ImGui::EndColumns() PopClipRect(); window->DrawList->ChannelsMerge(); - columns->CellMaxY = ImMax(columns->CellMaxY, window->DC.CursorPos.y); - window->DC.CursorPos.y = columns->CellMaxY; + columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y); + window->DC.CursorPos.y = columns->LineMaxY; if (!(columns->Flags & ImGuiColumnsFlags_GrowParentContentsSize)) window->DC.CursorMaxPos.x = ImMax(columns->StartMaxPosX, columns->MaxX); // Restore cursor max pos, as columns don't grow parent diff --git a/imgui_internal.h b/imgui_internal.h index 1ffa1600..d9247367 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -462,9 +462,9 @@ struct ImGuiColumnsSet int Current; int Count; float MinX, MaxX; - float StartPosY; - float StartMaxPosX; // Backup of CursorMaxPos - float CellMinY, CellMaxY; + float LineMinY, LineMaxY; + float StartPosY; // Copy of CursorPos + float StartMaxPosX; // Copy of CursorMaxPos ImVector Columns; ImGuiColumnsSet() { Clear(); } @@ -477,9 +477,9 @@ struct ImGuiColumnsSet Current = 0; Count = 1; MinX = MaxX = 0.0f; + LineMinY = LineMaxY = 0.0f; StartPosY = 0.0f; StartMaxPosX = 0.0f; - CellMinY = CellMaxY = 0.0f; Columns.clear(); } }; From e7670c0bcc447392b56f6648fc3df50e9726b40c Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 11:48:04 +0100 Subject: [PATCH 3/8] Style: CloseButton() now display a proper cross. Using Button colors for background. Removed ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered as the closing cross uses regular button colors now. (#707) --- CHANGELOG.txt | 2 ++ imgui.cpp | 27 ++++++++++++--------------- imgui.h | 3 --- imgui_draw.cpp | 9 --------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2d703959..ac672e74 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -60,6 +60,7 @@ Breaking Changes: - Renamed ImGuiStyleVar_Count_ to ImGuiStyleVar_COUNT and ImGuiMouseCursor_Count_ to ImGuiMouseCursor_COUNT for consistency with other public enums. - Obsoleted IsAnyWindowHovered() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow). Kept redirection function (will obsolete). - Obsoleted IsAnyWindowFocused() in favor of IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Kept redirection function (will obsolete). + - Removed ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered style colors as the closing cross uses regular button colors now. - Renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData. - Removed CalcItemRectClosestPoint() which was weird and not really used by anyone except demo code. If you need it it's easy to replicate on your side. @@ -101,6 +102,7 @@ Other Changes: - Style: Enable window border by default. (#707) - Style: Exposed ImGuiStyleVar_WindowTitleAlign, ImGuiStyleVar_ScrollbarSize, ImGuiStyleVar_ScrollbarRounding, ImGuiStyleVar_GrabRounding + added an assert to reduce accidental breakage. (#1181) - Style: Added style.MouseCursorScale help when using the software mouse cursor facility. (#939). +- Style: Close button nows display a cross before hovering. Uses button colors for highlight when hovering. (#707) - Popup: OpenPopup() Always reopen existing popup. (Removed imgui_internal.h's OpenPopupEx() which was used for this.) (#1497, #1533). - Popup: BeginPopupContextItem(), BeginPopupContextWindow(), BeginPopupContextVoid(), OpenPopupOnItemClick() all react on mouse release instead of mouse press. (~#439) - Popup: Better handling of user mistakenly calling OpenPopup() every frame (with reopen_existing option). The error will now be more visible and easier to understand. (#1497) diff --git a/imgui.cpp b/imgui.cpp index 0913819c..a0bd7478 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -251,6 +251,7 @@ Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. Also read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2018/03/12 (1.60) - Removed ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered as the closing cross uses regular button colors now. - 2018/03/08 (1.60) - Changed ImFont::DisplayOffset.y to default to 0 instead of +1. Fixed rounding of Ascent/Descent to match TrueType renderer. If you were adding or subtracting to ImFont::DisplayOffset check if your fonts are correctly aligned vertically. - 2018/03/03 (1.60) - Renamed ImGuiStyleVar_Count_ to ImGuiStyleVar_COUNT and ImGuiMouseCursor_Count_ to ImGuiMouseCursor_COUNT for consistency with other public enums. - 2018/02/18 (1.60) - BeginDragDropSource(): temporarily removed the optional mouse_button=0 parameter because it is not really usable in many situations at the moment. @@ -6079,9 +6080,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Close button if (p_open != NULL) { - const float PAD = 2.0f; - const float rad = (window->TitleBarHeight() - PAD*2.0f) * 0.5f; - if (CloseButton(window->GetID("#CLOSE"), window->Rect().GetTR() + ImVec2(-PAD - rad, PAD + rad), rad)) + const float pad = style.FramePadding.y; + const float rad = g.FontSize * 0.5f; + if (CloseButton(window->GetID("#CLOSE"), window->Rect().GetTR() + ImVec2(-pad - rad, pad + rad), rad + 1)) *p_open = false; } @@ -6676,9 +6677,6 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx) case ImGuiCol_ResizeGrip: return "ResizeGrip"; case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; - case ImGuiCol_CloseButton: return "CloseButton"; - case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered"; - case ImGuiCol_CloseButtonActive: return "CloseButtonActive"; case ImGuiCol_PlotLines: return "PlotLines"; case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; case ImGuiCol_PlotHistogram: return "PlotHistogram"; @@ -7720,17 +7718,16 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos, float radius) return pressed; // Render - const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); ImVec2 center = bb.GetCenter(); - window->DrawList->AddCircleFilled(center, ImMax(2.0f, radius), col, 12); - - const float cross_extent = (radius * 0.7071f) - 1.0f; if (hovered) - { - center -= ImVec2(0.5f, 0.5f); - window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), GetColorU32(ImGuiCol_Text)); - window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), GetColorU32(ImGuiCol_Text)); - } + window->DrawList->AddCircleFilled(center, ImMax(2.0f, radius), GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered), 9); + + float cross_extent = (radius * 0.7071f) - 1.0f; + ImU32 cross_col = GetColorU32(ImGuiCol_Text); + center -= ImVec2(0.5f, 0.5f); + window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), cross_col, 1.0f); + window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), cross_col, 1.0f); + return pressed; } diff --git a/imgui.h b/imgui.h index 9b4cf2c9..f8400233 100644 --- a/imgui.h +++ b/imgui.h @@ -812,9 +812,6 @@ enum ImGuiCol_ ImGuiCol_ResizeGrip, ImGuiCol_ResizeGripHovered, ImGuiCol_ResizeGripActive, - ImGuiCol_CloseButton, - ImGuiCol_CloseButtonHovered, - ImGuiCol_CloseButtonActive, ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, ImGuiCol_PlotHistogram, diff --git a/imgui_draw.cpp b/imgui_draw.cpp index dd445781..b86ee869 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -165,9 +165,6 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst) colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); - colors[ImGuiCol_CloseButton] = ImVec4(0.41f, 0.41f, 0.41f, 0.50f); - colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); - colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); @@ -217,9 +214,6 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst) colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.16f); colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f); - colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f); - colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f); - colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); @@ -272,9 +266,6 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) colors[ImGuiCol_ResizeGrip] = ImVec4(0.80f, 0.80f, 0.80f, 0.56f); colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); - colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f); - colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); - colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); From 887712a6f14140808b877f7e60b5d1a901959e86 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 14:20:39 +0100 Subject: [PATCH 4/8] Updated templates, added pull request template. --- .github/CONTRIBUTING.md | 4 ++++ .github/issue_template.md | 9 +++++++-- .github/pull_request_template.md | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 984ea521..b4079e0a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -22,3 +22,7 @@ You may use the Issue tracker to submit bug reports, feature requests or suggest If you have been using dear imgui for a while and/or have been using C/C++ for several years and/or have demonstrated good behavior here, it is ok to not fullfill every item to the letter. Those are guidelines and experienced users of dear imgui will know what information are useful in a given context. +## How to create an Pull Request + +- If you are adding a feature, please explain the context of the change: what do you need the feature for? +- Make sure you create a branch for the pull request. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR. diff --git a/.github/issue_template.md b/.github/issue_template.md index e47ef9e8..958aa165 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -1,7 +1,12 @@ -(Please carefully read guidelines in [CONTRIBUTING.md](https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md) then delete this line) +You may use the Issue tracker to ask for help, submit bug reports, feature requests or suggestions. +Please carefully read this document before doing so: +[CONTRIBUTING.md](https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md). -You can include code this way: +You can include code snippets using `Begin()` for short in-line snippets, or: ```cpp ImGui::Begin("Hello"); ImGui::ThisIsMoreCode(); ``` +For multiline snippets. + +(Clear this form before submitting your issue) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..66308e48 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,5 @@ +- If you are adding a feature, please explain the context of the change: what do you need the feature for? +- Make sure you create a branch for the pull request. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR. +- You can read [CONTRIBUTING.md](https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md) for more details. + +(Clear this form before submitting your PR) From b2453d7e8f790b2a74cb7fc6b0e46ce26c425c3a Mon Sep 17 00:00:00 2001 From: Peter Particle Date: Sat, 10 Mar 2018 20:49:06 +0100 Subject: [PATCH 5/8] Fixed resize window validation errors with removing frame prerender once and present last but one frame functionality. Frame rate is still similar. --- examples/vulkan_example/main.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index ca647926..1631c8df 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -12,9 +12,9 @@ #define IMGUI_MAX_POSSIBLE_BACK_BUFFERS 16 #define IMGUI_UNLIMITED_FRAME_RATE -//#ifdef _DEBUG -//#define IMGUI_VULKAN_DEBUG_REPORT -//#endif +#ifdef _DEBUG +#define IMGUI_VULKAN_DEBUG_REPORT +#endif static VkAllocationCallbacks* g_Allocator = NULL; static VkInstance g_Instance = VK_NULL_HANDLE; @@ -568,19 +568,12 @@ static void frame_end() static void frame_present() { VkResult err; - // If IMGUI_UNLIMITED_FRAME_RATE is defined we present the latest but one frame. Otherwise we present the latest rendered frame -#ifdef IMGUI_UNLIMITED_FRAME_RATE - uint32_t PresentIndex = (g_FrameIndex + IMGUI_VK_QUEUED_FRAMES - 1) % IMGUI_VK_QUEUED_FRAMES; -#else - uint32_t PresentIndex = g_FrameIndex; -#endif // IMGUI_UNLIMITED_FRAME_RATE - VkSwapchainKHR swapchains[1] = {g_Swapchain}; - uint32_t indices[1] = {g_BackbufferIndices[PresentIndex]}; + uint32_t indices[1] = {g_BackbufferIndices[g_FrameIndex]}; VkPresentInfoKHR info = {}; info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; info.waitSemaphoreCount = 1; - info.pWaitSemaphores = &g_RenderCompleteSemaphore[PresentIndex]; + info.pWaitSemaphores = &g_RenderCompleteSemaphore[g_FrameIndex]; info.swapchainCount = 1; info.pSwapchains = swapchains; info.pImageIndices = indices; @@ -678,16 +671,6 @@ int main(int, char**) bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before. - // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop. - // This is also the reason why frame_end() is split into frame_end() and frame_present(), the later one not being called here. -#ifdef IMGUI_UNLIMITED_FRAME_RATE - ImGui_ImplGlfwVulkan_NewFrame(); - frame_begin(); - ImGui_ImplGlfwVulkan_Render(g_CommandBuffer[g_FrameIndex]); - frame_end(); - g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; -#endif // IMGUI_UNLIMITED_FRAME_RATE // Main loop while (!glfwWindowShouldClose(window)) From 1c18d653134e1eb7e3e039d8b055334dba25f2cf Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 14:43:37 +0100 Subject: [PATCH 6/8] Examples: Renamed glfw error callback for clarity. --- examples/opengl2_example/main.cpp | 4 ++-- examples/opengl3_example/main.cpp | 4 ++-- examples/vulkan_example/main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/opengl2_example/main.cpp b/examples/opengl2_example/main.cpp index 37060688..6728347c 100644 --- a/examples/opengl2_example/main.cpp +++ b/examples/opengl2_example/main.cpp @@ -11,7 +11,7 @@ #include #include -static void error_callback(int error, const char* description) +static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Error %d: %s\n", error, description); } @@ -19,7 +19,7 @@ static void error_callback(int error, const char* description) int main(int, char**) { // Setup window - glfwSetErrorCallback(error_callback); + glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return 1; GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL); diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 143dcc59..ce2f1156 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -9,7 +9,7 @@ #include // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. #include -static void error_callback(int error, const char* description) +static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Error %d: %s\n", error, description); } @@ -17,7 +17,7 @@ static void error_callback(int error, const char* description) int main(int, char**) { // Setup window - glfwSetErrorCallback(error_callback); + glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return 1; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 1631c8df..79ceb8b2 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -583,7 +583,7 @@ static void frame_present() g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; } -static void error_callback(int error, const char* description) +static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Error %d: %s\n", error, description); } @@ -591,7 +591,7 @@ static void error_callback(int error, const char* description) int main(int, char**) { // Setup window - glfwSetErrorCallback(error_callback); + glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return 1; From 37cb177745daa9b19c102a86958d514beae8eacb Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 14:46:24 +0100 Subject: [PATCH 7/8] Examples: Vulkan: Only resize swap chain and framebuffer once. (#1042) --- examples/vulkan_example/main.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 79ceb8b2..a197515f 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -34,7 +34,9 @@ static VkPresentModeKHR g_PresentMode; static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE; static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE; -static int fb_width, fb_height; +static int fb_width = 0, fb_height = 0; +static bool g_ResizeWanted = false; +static int g_ResizeWidth = 0, g_ResizeHeight = 0; static uint32_t g_BackbufferIndices[IMGUI_VK_QUEUED_FRAMES]; // keep track of recently rendered swapchain frame indices static uint32_t g_BackBufferCount = 0; static VkImage g_BackBuffer[IMGUI_MAX_POSSIBLE_BACK_BUFFERS] = {}; @@ -58,7 +60,7 @@ static void check_vk_result(VkResult err) abort(); } -static void resize_vulkan(GLFWwindow* /*window*/, int w, int h) +static void resize_vulkan(int w, int h) { VkResult err; VkSwapchainKHR old_swapchain = g_Swapchain; @@ -355,7 +357,7 @@ static void setup_vulkan(GLFWwindow* window) // Get Present Mode { - // Requst a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory + // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory #ifdef IMGUI_UNLIMITED_FRAME_RATE g_PresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; #else @@ -406,8 +408,7 @@ static void setup_vulkan(GLFWwindow* window) { int w, h; glfwGetFramebufferSize(window, &w, &h); - resize_vulkan(window, w, h); - glfwSetFramebufferSizeCallback(window, resize_vulkan); + resize_vulkan(w, h); } // Create Command Buffers @@ -588,6 +589,13 @@ static void glfw_error_callback(int error, const char* description) fprintf(stderr, "Error %d: %s\n", error, description); } +static void glfw_resize_callback(GLFWwindow*, int w, int h) +{ + g_ResizeWanted = true; + g_ResizeWidth = w; + g_ResizeHeight = h; +} + int main(int, char**) { // Setup window @@ -605,6 +613,7 @@ int main(int, char**) return 1; } setup_vulkan(window); + glfwSetFramebufferSizeCallback(window, glfw_resize_callback); // Setup ImGui binding ImGui::CreateContext(); @@ -680,6 +689,11 @@ int main(int, char**) // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. glfwPollEvents(); + + if (g_ResizeWanted) + resize_vulkan(g_ResizeWidth, g_ResizeHeight); + g_ResizeWanted = false; + ImGui_ImplGlfwVulkan_NewFrame(); // 1. Show a simple window. From 111ea7af77bf82ccfb2d014593d8760013a44974 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 12 Mar 2018 17:24:15 +0100 Subject: [PATCH 8/8] Misc comments, todos + reintroduced removed ImGuiCol defines under !IMGUI_DISABLE_OBSOLETE_FUNCTIONS wrap. --- TODO.txt | 1 + imgui.h | 9 ++++++--- imgui_demo.cpp | 10 +++++----- misc/freetype/README.md | 3 ++- misc/freetype/imgui_freetype.cpp | 3 ++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5c58f63f..6da01e73 100644 --- a/TODO.txt +++ b/TODO.txt @@ -30,6 +30,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i !- scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. - scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro) + - drawdata: make it easy to clone (or swap?) a ImDrawData so user can easily save that data if they use threaded renderering. - drawlist: end-user probably can't call Clear() directly because we expect a texture to be pushed in the stack. - drawlist: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command). - drawlist: primtiives/helpers to manipulate vertices post submission, so e.g. a quad/rect can be resized to fit later submitted content, _without_ using the ChannelSplit api diff --git a/imgui.h b/imgui.h index f8400233..715f5415 100644 --- a/imgui.h +++ b/imgui.h @@ -821,12 +821,15 @@ enum ImGuiCol_ ImGuiCol_DragDropTarget, ImGuiCol_NavHighlight, // gamepad/keyboard: current highlighted item ImGuiCol_NavWindowingHighlight, // gamepad/keyboard: when holding NavMenu to focus/move/resize windows - ImGuiCol_COUNT // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //, ImGuiCol_ComboBg = ImGuiCol_PopupBg // ComboBg has been merged with PopupBg, so a redirect isn't accurate. - , ImGuiCol_ChildWindowBg = ImGuiCol_ChildBg, ImGuiCol_Column = ImGuiCol_Separator, ImGuiCol_ColumnHovered = ImGuiCol_SeparatorHovered, ImGuiCol_ColumnActive = ImGuiCol_SeparatorActive + ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered, // [unused since 1.60+] the close button now uses regular button colors. + ImGuiCol_ComboBg, // [unused since 1.53+] ComboBg has been merged with PopupBg, so a redirect isn't accurate. + ImGuiCol_COUNT, + ImGuiCol_ChildWindowBg = ImGuiCol_ChildBg, ImGuiCol_Column = ImGuiCol_Separator, ImGuiCol_ColumnHovered = ImGuiCol_SeparatorHovered, ImGuiCol_ColumnActive = ImGuiCol_SeparatorActive +#else + ImGuiCol_COUNT #endif }; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 2a94de4e..b36205b1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2229,17 +2229,17 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) count += font->FindGlyphNoFallback((ImWchar)(base + n)) ? 1 : 0; if (count > 0 && ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base+255, count, count > 1 ? "glyphs" : "glyph")) { + float cell_size = font->FontSize * 1; float cell_spacing = style.ItemSpacing.y; - ImVec2 cell_size(font->FontSize * 1, font->FontSize * 1); ImVec2 base_pos = ImGui::GetCursorScreenPos(); ImDrawList* draw_list = ImGui::GetWindowDrawList(); for (int n = 0; n < 256; n++) { - ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size.x + cell_spacing), base_pos.y + (n / 16) * (cell_size.y + cell_spacing)); - ImVec2 cell_p2(cell_p1.x + cell_size.x, cell_p1.y + cell_size.y); + ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size + cell_spacing), base_pos.y + (n / 16) * (cell_size + cell_spacing)); + ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size); const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base+n)); draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255,255,255,100) : IM_COL32(255,255,255,50)); - font->RenderChar(draw_list, cell_size.x, cell_p1, ImGui::GetColorU32(ImGuiCol_Text), (ImWchar)(base+n)); // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string. + font->RenderChar(draw_list, cell_size, cell_p1, ImGui::GetColorU32(ImGuiCol_Text), (ImWchar)(base+n)); // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string. if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2)) { ImGui::BeginTooltip(); @@ -2251,7 +2251,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::EndTooltip(); } } - ImGui::Dummy(ImVec2((cell_size.x + cell_spacing) * 16, (cell_size.y + cell_spacing) * 16)); + ImGui::Dummy(ImVec2((cell_size + cell_spacing) * 16, (cell_size + cell_spacing) * 16)); ImGui::TreePop(); } } diff --git a/misc/freetype/README.md b/misc/freetype/README.md index ad0e4d3b..4038dbcd 100644 --- a/misc/freetype/README.md +++ b/misc/freetype/README.md @@ -121,8 +121,9 @@ struct FreeTypeTest ``` **Known issues** -- Output texture has excessive resolution (lots of vertical waste) +- Output texture has excessive resolution (lots of vertical waste). - FreeType's memory allocator is not overridden. +- `cfg.OversampleH`, `OversampleV` are ignored (but perhaps not so necessary with this rasterizer). **Obligatory comparison screenshots** diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 37526d78..8235ac5f 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -17,8 +17,9 @@ // The default imgui styles will be impacted by this change (alpha values will need tweaking). // TODO: -// - Output texture has excessive resolution (lots of vertical waste) +// - Output texture has excessive resolution (lots of vertical waste). // - FreeType's memory allocator is not overridden. +// - cfg.OversampleH, OversampleV are ignored (but perhaps not so necessary with this rasterizer). #include "imgui_freetype.h" #include "imgui_internal.h" // ImMin,ImMax,ImFontAtlasBuild*,