From 18fa8e1c7ea256ce518771aa9f56e8c752c94376 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 4 Jul 2015 16:46:30 -0600 Subject: [PATCH 1/5] Fixed IsMouseDragging() (fix #260) --- imgui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 2c3458b7..c902fbdc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2978,6 +2978,8 @@ bool ImGui::IsMouseDragging(int button, float lock_threshold) { ImGuiState& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (!g.IO.MouseDown[button]) + return false; if (lock_threshold < 0.0f) lock_threshold = g.IO.MouseDragThreshold; return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; From c9676554b934f98361f026bffa470081865792c2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 5 Jul 2015 20:27:06 -0600 Subject: [PATCH 2/5] MenuItem() can be activated on release (#245) --- imgui.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c902fbdc..3df06d2c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1003,19 +1003,21 @@ enum ImGuiLayoutType_ enum ImGuiButtonFlags_ { ImGuiButtonFlags_Repeat = 1 << 0, - ImGuiButtonFlags_PressedOnClick = 1 << 1, - ImGuiButtonFlags_FlattenChilds = 1 << 2, - ImGuiButtonFlags_DontClosePopups = 1 << 3, - ImGuiButtonFlags_Disabled = 1 << 4, - ImGuiButtonFlags_AlignTextBaseLine = 1 << 5 + ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release) + ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release) + ImGuiButtonFlags_FlattenChilds = 1 << 3, + ImGuiButtonFlags_DontClosePopups = 1 << 4, + ImGuiButtonFlags_Disabled = 1 << 5, + ImGuiButtonFlags_AlignTextBaseLine = 1 << 6 }; enum ImGuiSelectableFlagsPrivate_ { // NB: need to be in sync with last value of ImGuiSelectableFlags_ - ImGuiSelectableFlags_MenuItem = 1 << 2, - ImGuiSelectableFlags_Disabled = 1 << 3, - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 4 + ImGuiSelectableFlags_Menu = 1 << 2, + ImGuiSelectableFlags_MenuItem = 1 << 3, + ImGuiSelectableFlags_Disabled = 1 << 4, + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 5 }; @@ -5156,6 +5158,11 @@ static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } FocusWindow(window); } + else if (g.IO.MouseReleased[0] && (flags & ImGuiButtonFlags_PressedOnRelease)) + { + pressed = true; + SetActiveId(0); + } else if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && ImGui::IsMouseClicked(0, true)) { pressed = true; @@ -7878,8 +7885,12 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl return false; } + ImGuiButtonFlags button_flags = 0; + if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick; + if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnClick|ImGuiButtonFlags_PressedOnRelease; + if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; bool hovered, held; - bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, ((flags & ImGuiSelectableFlags_MenuItem) ? ImGuiButtonFlags_PressedOnClick : 0) | ((flags & ImGuiSelectableFlags_Disabled) ? ImGuiButtonFlags_Disabled : 0)); + bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, button_flags); if (flags & ImGuiSelectableFlags_Disabled) selected = false; @@ -8137,7 +8148,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f); float w = label_size.x; - pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); ImGui::PopStyleVar(); ImGui::SameLine(); window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); @@ -8147,7 +8158,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, (float)(int)(g.FontSize * 1.20f)); // Feedback to next frame float extra_w = ImMax(0.0f, window->Pos.x + ImGui::GetContentRegionMax().x - pos.x - w); - pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + pressed = ImGui::Selectable(label, opened, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); if (!enabled) ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); RenderCollapseTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), false); if (!enabled) ImGui::PopStyleColor(); From 1c160adbba5cac5491c1cfaa5d8d26d7d2b8593f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 5 Jul 2015 20:38:18 -0600 Subject: [PATCH 3/5] Comments --- imgui.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3df06d2c..5870dbc4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -373,7 +373,6 @@ - listbox: scrolling should track modified selection. - menus: local shortcuts, global shortcuts (#126) - menus: icons - - menus: see we can allow for click-menu-hold-release-on-item to work (like Windows does) - menus: menubars: some sort of priority / effect of main menu-bar on desktop size? - tabs - separator: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y) @@ -10995,7 +10994,7 @@ void ImGui::ShowTestWindow(bool* opened) if (ImGui::TreeNode("Clipping")) { static ImVec2 size(100, 100), offset(50, 20); - ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text if it won't fit in its frame. Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and CPU/GPU rendering cost."); + ImGui::TextWrapped("On a per-widget basis we are occasionally clipping text CPU-side if it won't fit in its frame. Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and CPU/GPU rendering cost."); ImGui::DragFloat2("size", (float*)&size, 0.5f, 0.0f, 200.0f, "%.0f"); ImGui::DragFloat2("offset", (float*)&offset, 0.5f, -200, 200.0f, "%.0f"); ImVec2 pos = ImGui::GetCursorScreenPos(); From 3fa44519367cd44facc3b02fd70f78ce66222e6c Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 5 Jul 2015 20:47:25 -0600 Subject: [PATCH 4/5] PlotLines(), PlotHistogram(): fixed incorrect hovering test (would trigger tooltip when menu is open) --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5870dbc4..6373b4ad 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5102,7 +5102,7 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window) { // An active popup disable hovering on other windows (apart from its own children) ImGuiState& g = *GImGui; - if (ImGuiWindow* focused_window = g.FocusedWindow) + if (ImGuiWindow* focused_window = g.FocusedWindow) if (ImGuiWindow* focused_root_window = focused_window->RootWindow) if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) != 0 && focused_root_window->WasActive && focused_root_window != window->RootWindow) return false; @@ -6572,7 +6572,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett // Tooltip on hover int v_hovered = -1; - if (IsMouseHoveringRect(inner_bb)) + if (IsHovered(inner_bb, 0)) { const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); From 562aecdaa5b15dac8fa2cdee2569a5ee5a453004 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 5 Jul 2015 20:56:01 -0600 Subject: [PATCH 5/5] Removed obsolete GetDefaultFontData() function that would assert anyway (obsoleted 2015/01/11) --- imgui.cpp | 13 ------------- imgui.h | 1 - 2 files changed, 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6373b4ad..380f4dc8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9414,19 +9414,6 @@ void ImFontAtlas::Clear() ClearFonts(); } -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS -void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size) -{ - printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n"); - printf("Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data.\n"); - if (fnt_data) *fnt_data = NULL; - if (fnt_size) *fnt_size = 0; - if (png_data) *png_data = NULL; - if (png_size) *png_size = 0; - IM_ASSERT(false); -} -#endif - void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) { // Lazily build diff --git a/imgui.h b/imgui.h index 46fc13b5..a278ea71 100644 --- a/imgui.h +++ b/imgui.h @@ -407,7 +407,6 @@ namespace ImGui // Obsolete (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); // OBSOLETE 1.30+ static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE 1.34+ static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE 1.36+ static inline bool GetWindowCollapsed() { return ImGui::IsWindowCollapsed(); } // OBSOLETE 1.39+