From 68df09cf4755f2d5ee4c015f1f8fc8f2bb122645 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 1 Jan 2017 20:11:40 +0100 Subject: [PATCH 1/4] Fixed word-wrapping which would never wrap after a 1 character word. (thanks @sronsse) --- imgui_demo.cpp | 4 ++-- imgui_draw.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index d42d1486..e9b5da51 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -362,7 +362,7 @@ void ImGui::ShowTestWindow(bool* p_open) ImVec2 pos = ImGui::GetCursorScreenPos(); ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255)); ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); - ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width); + ImGui::Text("The lazy dog is a good dog. This paragraph is made to fit within %.0f pixels. Testing a 1 character word. The quick brown fox jumps over the lazy dog.", wrap_width); ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255)); ImGui::PopTextWrapPos(); @@ -370,7 +370,7 @@ void ImGui::ShowTestWindow(bool* p_open) pos = ImGui::GetCursorScreenPos(); ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255)); ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); - ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh"); + ImGui::Text("aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh"); ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255)); ImGui::PopTextWrapPos(); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a660e30c..a1d58c0e 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1851,6 +1851,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c { line_width += blank_width; blank_width = 0.0f; + word_end = s; } blank_width += char_width; inside_word = false; From 714beb217cc12b27fe42ae6c5539f1488aa66d45 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 7 Jan 2017 20:18:45 +0100 Subject: [PATCH 2/4] Demo: Console: Fixed a completion bug when multiple candidates are equals and match until the end. --- imgui_demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e9b5da51..dda0a53d 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2316,7 +2316,7 @@ struct ExampleAppConsole for (int i = 0; i < candidates.Size && all_candidates_matches; i++) if (i == 0) c = toupper(candidates[i][match_len]); - else if (c != toupper(candidates[i][match_len])) + else if (c == 0 || c != toupper(candidates[i][match_len])) all_candidates_matches = false; if (!all_candidates_matches) break; From cffdbfe01b476b1be4f3ba825b5ff823e06f6e8e Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 10 Jan 2017 10:36:07 +0100 Subject: [PATCH 3/4] Comments (#972) --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 38ce2d2d..9d84a94f 100644 --- a/imgui.h +++ b/imgui.h @@ -372,7 +372,7 @@ namespace ImGui // Popups IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). IMGUI_API bool BeginPopup(const char* str_id); // return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returned true! - IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (can't close them by clicking outside) + IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (block interactions behind the modal window, can't close the modal window by clicking outside) IMGUI_API bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // helper to open and begin popup when clicked on last item. read comments in .cpp! IMGUI_API bool BeginPopupContextWindow(bool also_over_items = true, const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked on current window. IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (no window). From 6257b5814a936617741a14fa11c98af15d53ca49 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 11 Jan 2017 20:56:55 +0100 Subject: [PATCH 4/4] Added an explicit (internal) ClearActiveID() helper and removed the default NULL window parameter to internal SetActiveID(), --- imgui.cpp | 37 +++++++++++++++++++++---------------- imgui_internal.h | 1 + 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c60c1d9c..c7b16b26 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1858,7 +1858,7 @@ ImGuiWindow* ImGui::GetParentWindow() return g.CurrentWindowStack[(unsigned int)g.CurrentWindowStack.Size - 2]; } -void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL) +void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; g.ActiveId = id; @@ -1869,6 +1869,11 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL) g.ActiveIdWindow = window; } +void ImGui::ClearActiveID() +{ + SetActiveID(0, NULL); +} + void ImGui::SetHoveredID(ImGuiID id) { ImGuiContext& g = *GImGui; @@ -2204,7 +2209,7 @@ void ImGui::NewFrame() g.HoveredId = 0; g.HoveredIdAllowOverlap = false; if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) - SetActiveID(0); + ClearActiveID(); g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; g.ActiveIdIsJustActivated = false; @@ -2227,7 +2232,7 @@ void ImGui::NewFrame() } else { - SetActiveID(0); + ClearActiveID(); g.MovedWindow = NULL; g.MovedWindowMoveId = 0; } @@ -4214,7 +4219,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us ApplySizeFullWithConstraint(window, size_auto_fit); if (!(flags & ImGuiWindowFlags_NoSavedSettings)) MarkIniSettingsDirty(); - SetActiveID(0); + ClearActiveID(); } else if (held) { @@ -4563,7 +4568,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Steal focus on active widgets if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window) - SetActiveID(0); + ClearActiveID(); // Bring to front if ((window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) || g.Windows.back() == window) @@ -5536,7 +5541,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool { if (out_hovered) *out_hovered = false; if (out_held) *out_held = false; - if (g.ActiveId == id) SetActiveID(0); + if (g.ActiveId == id) ClearActiveID(); return false; } @@ -5564,14 +5569,14 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) { pressed = true; - SetActiveID(0); + ClearActiveID(); FocusWindow(window); } if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) { if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). @@ -5593,7 +5598,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease)) if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } } @@ -6558,7 +6563,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v } else { - SetActiveID(0); + ClearActiveID(); } } @@ -6874,7 +6879,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s } else { - SetActiveID(0); + ClearActiveID(); } } @@ -7777,7 +7782,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 { // Release focus when we click outside if (g.ActiveId == id) - SetActiveID(0); + ClearActiveID(); } bool value_changed = false; @@ -7879,7 +7884,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) { - SetActiveID(0); + ClearActiveID(); enter_pressed = true; } else if (is_editable) @@ -7895,7 +7900,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 if (InputTextFilterCharacter(&c, flags, callback, user_data)) edit_state.OnKeyPressed((int)c); } - else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveID(0); cancel_edit = true; } + else if (IsKeyPressedMap(ImGuiKey_Escape)) { ClearActiveID(); cancel_edit = true; } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Z) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Y) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); edit_state.CursorFollow = true; } @@ -8490,7 +8495,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi SetHoveredID(id); if (g.IO.MouseClicked[0]) { - SetActiveID(0); + ClearActiveID(); if (IsPopupOpen(id)) { ClosePopup(id); @@ -8539,7 +8544,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi item_text = "*Unknown item*"; if (Selectable(item_text, item_selected)) { - SetActiveID(0); + ClearActiveID(); value_changed = true; *current_item = i; } diff --git a/imgui_internal.h b/imgui_internal.h index ff188b0f..5e189846 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -710,6 +710,7 @@ namespace ImGui IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead! IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); + IMGUI_API void ClearActiveID(); IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id);