From b0cdfe0ece17b37fc8d2b4e54124c2e135bf1fd6 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Jul 2018 13:27:16 +0200 Subject: [PATCH 1/8] Generalized d11d211e so regular popups (without the AlwaysAutoResize flag) also have a smaller minimum size, but reduced it to an arbitrary 4.0f instead of 1.0f to ease debugging of faulty situations. (#1909) --- CHANGELOG.txt | 2 +- imgui.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b3471c38..beaafaa3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -42,7 +42,7 @@ 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. - - Window: Allow menu windows from ignoring the style.WindowMinSize values so short menus are not padded. (#1909) + - Window: Allow menu and popups windows from ignoring the style.WindowMinSize values so short menus/popups are not padded. (#1909) - Window: Added global io.OptResizeWindowsFromEdges option to enable resizing windows from their edges and from the lower-left corner. (#1495) - Drag and Drop: Fixed an incorrect assert when dropping a source that is submitted after the target (bug introduced with 1.62 changes related to the addition of IsItemDeactivated()). (#1875, #143) diff --git a/imgui.cpp b/imgui.cpp index 0915767f..e8e2290e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5831,11 +5831,11 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents) else { // When the window cannot fit all contents (either because of constraints, either because screen is too small): we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than DisplaySize-WindowPadding. - const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0 && (window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0; + const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0; const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0; - ImVec2 size_min(1.0f, 1.0f); - if (!is_popup && !is_menu) - size_min = style.WindowMinSize; + ImVec2 size_min = style.WindowMinSize; + if (is_popup || is_menu) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups) + size_min = ImMin(size_min, ImVec2(4.0f, 4.0f)); ImVec2 size_auto_fit = ImClamp(size_contents, size_min, ImMax(size_min, g.IO.DisplaySize - style.DisplaySafeAreaPadding * 2.0f)); ImVec2 size_auto_fit_after_constraint = CalcSizeAfterConstraint(window, size_auto_fit); if (size_auto_fit_after_constraint.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) From 3a42eb662026e793461d4ca31e0d3bba54cacb30 Mon Sep 17 00:00:00 2001 From: vby Date: Sun, 8 Jul 2018 21:24:12 +0800 Subject: [PATCH 2/8] Fix missing ImmReleaseContext in default Win32 IME handler (#1932) --- imgui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui.cpp b/imgui.cpp index e8e2290e..d18e1ac2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13826,6 +13826,7 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) cf.ptCurrentPos.y = y; cf.dwStyle = CFS_FORCE_POSITION; ::ImmSetCompositionWindow(himc, &cf); + ::ImmReleaseContext(hwnd, himc); } } From a33f0d1f7f757ff446825fee973687f78af9c600 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Jul 2018 16:38:46 +0200 Subject: [PATCH 3/8] Drag and Drop: Fixed ImGuiDragDropFlags_SourceNoDisableHover to affect hovering state prior to calling IsItemHovered() + fixed description. (#143) --- CHANGELOG.txt | 2 ++ imgui.cpp | 2 +- imgui.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index beaafaa3..3ada93d0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -46,9 +46,11 @@ Other Changes: - Window: Added global io.OptResizeWindowsFromEdges option to enable resizing windows from their edges and from the lower-left corner. (#1495) - Drag and Drop: Fixed an incorrect assert when dropping a source that is submitted after the target (bug introduced with 1.62 changes related to the addition of IsItemDeactivated()). (#1875, #143) + - Drag and Drop: Fixed ImGuiDragDropFlags_SourceNoDisableHover to affect hovering state prior to calling IsItemHovered() + fixed description. (#143) - Misc: Added ImGuiMouseCursor_Hand cursor enum + corresponding software cursor. (#1913, 1914) [@aiekick, @ocornut] - Misc: Tweaked software mouse cursor offset to match the offset of the corresponding Windows 10 cursors. - Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276) + - Windows: Fixed missing ImmReleaseContext() call in the default Win32 IME handler. (#1932) [@vby] - Examples: Metal: Added Metal rendering backend. (#1929, #1873) [@warrenm] - Examples: OSX: Added early raw OSX platform backend. (#1873) [@pagghiu, @itamago, @ocornut] - Examples: Added mac OSX & iOS + Metal example in example_apple_metal/. (#1929, #1873) [@warrenm] diff --git a/imgui.cpp b/imgui.cpp index d18e1ac2..4205d655 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7954,7 +7954,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool bool hovered = ItemHoverable(bb, id); // Drag source doesn't report as hovered - if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id) + if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover)) hovered = false; // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button diff --git a/imgui.h b/imgui.h index d4bba375..b9e3a6d2 100644 --- a/imgui.h +++ b/imgui.h @@ -728,7 +728,7 @@ enum ImGuiDragDropFlags_ ImGuiDragDropFlags_None = 0, // BeginDragDropSource() flags ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, // By default, a successful call to BeginDragDropSource opens a tooltip so you can display a preview or description of the source contents. This flag disable this behavior. - ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return true, to avoid subsequent user code submitting tooltips. This flag disable this behavior so you can still call IsItemHovered() on the source item. + ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return false, to avoid subsequent user code submitting tooltips. This flag disable this behavior so you can still call IsItemHovered() on the source item. ImGuiDragDropFlags_SourceNoHoldToOpenOthers = 1 << 2, // Disable the behavior that allows to open tree nodes and collapsing header by holding over them while dragging a source item. ImGuiDragDropFlags_SourceAllowNullID = 1 << 3, // Allow items such as Text(), Image() that have no unique identifier to be used as drag source, by manufacturing a temporary identifier based on their window-relative position. This is extremely unusual within the dear imgui ecosystem and so we made it explicit. ImGuiDragDropFlags_SourceExtern = 1 << 4, // External source (from outside of imgui), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously. From 64938178b726e68d008e3326b16a7da33db4cf3e Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Jul 2018 18:23:12 +0200 Subject: [PATCH 4/8] Internals: Moved selectable flags to avoid collision with public flags + rewrote some tests so we can consistently grep for (held && hovered) --- imgui.cpp | 6 +++--- imgui_internal.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4205d655..36d9ff41 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8107,7 +8107,7 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags MarkItemValueChanged(id); // Render - const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb); @@ -8156,7 +8156,7 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); // Render - const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, g.Style.FrameRounding); 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); @@ -8275,7 +8275,7 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I bool pressed = ButtonBehavior(bb, id, &hovered, &held); // Render - const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding)); if (bg_col.w > 0.0f) diff --git a/imgui_internal.h b/imgui_internal.h index d4737042..91661e04 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -237,11 +237,11 @@ enum ImGuiColumnsFlags_ enum ImGuiSelectableFlagsPrivate_ { // NB: need to be in sync with last value of ImGuiSelectableFlags_ - ImGuiSelectableFlags_NoHoldingActiveID = 1 << 3, - ImGuiSelectableFlags_PressedOnClick = 1 << 4, - ImGuiSelectableFlags_PressedOnRelease = 1 << 5, - ImGuiSelectableFlags_Disabled = 1 << 6, - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 7 + ImGuiSelectableFlags_NoHoldingActiveID = 1 << 10, + ImGuiSelectableFlags_PressedOnClick = 1 << 11, + ImGuiSelectableFlags_PressedOnRelease = 1 << 12, + ImGuiSelectableFlags_Disabled = 1 << 13, + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 14 }; enum ImGuiSeparatorFlags_ From bd6097ac6f1afaeb5267189e2f5c43578a1f48de Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Jul 2018 20:04:49 +0200 Subject: [PATCH 5/8] Drag and Drop: Calling BeginTooltip() between a BeginDragSource()/EndDragSource() or BeginDropTarget()/EndDropTarget() uses adjusted tooltip settings matching the one created when calling BeginDragSource() without the ImGuiDragDropFlags_SourceNoPreviewTooltip flag. (#143) + additional safety checks. --- CHANGELOG.txt | 2 ++ imgui.cpp | 55 +++++++++++++++++++++++++++--------------------- imgui_internal.h | 5 ++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3ada93d0..984bc4fa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -47,6 +47,8 @@ Other Changes: - Drag and Drop: Fixed an incorrect assert when dropping a source that is submitted after the target (bug introduced with 1.62 changes related to the addition of IsItemDeactivated()). (#1875, #143) - Drag and Drop: Fixed ImGuiDragDropFlags_SourceNoDisableHover to affect hovering state prior to calling IsItemHovered() + fixed description. (#143) + - Drag and Drop: Calling BeginTooltip() between a BeginDragSource()/EndDragSource() or BeginDropTarget()/EndDropTarget() uses adjusted tooltip + settings matching the one created when calling BeginDragSource() without the ImGuiDragDropFlags_SourceNoPreviewTooltip flag. (#143) - Misc: Added ImGuiMouseCursor_Hand cursor enum + corresponding software cursor. (#1913, 1914) [@aiekick, @ocornut] - Misc: Tweaked software mouse cursor offset to match the offset of the corresponding Windows 10 cursors. - Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276) diff --git a/imgui.cpp b/imgui.cpp index 36d9ff41..1f39af48 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3790,6 +3790,7 @@ void ImGui::NewFrame() g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr; g.DragDropAcceptIdCurr = 0; g.DragDropAcceptIdCurrRectSurface = FLT_MAX; + g.DragDropWithinSourceOrTarget = false; // Update keyboard input state memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); @@ -5158,7 +5159,23 @@ void ImGui::SetTooltip(const char* fmt, ...) void ImGui::BeginTooltip() { - BeginTooltipEx(0, false); + ImGuiContext& g = *GImGui; + if (g.DragDropWithinSourceOrTarget) + { + // The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor) + // In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor. + // Whatever we do we want to call SetNextWindowPos() to enforce a tooltip position and disable clipping the tooltip without our display area, like regular tooltip do. + //ImVec2 tooltip_pos = g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding; + ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale); + SetNextWindowPos(tooltip_pos); + SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f); + //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :( + BeginTooltipEx(0, true); + } + else + { + BeginTooltipEx(0, false); + } } void ImGui::EndTooltip() @@ -13521,12 +13538,13 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) g.DragDropSourceFlags = flags; g.DragDropMouseButton = mouse_button; } + g.DragDropWithinSourceOrTarget = true; if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) { // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit) // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents. - BeginDragDropTooltip(); + BeginTooltip(); if (g.DragDropActive && g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip)) { ImGuiWindow* tooltip_window = g.CurrentWindow; @@ -13547,32 +13565,15 @@ void ImGui::EndDragDropSource() { ImGuiContext& g = *GImGui; IM_ASSERT(g.DragDropActive); + IM_ASSERT(g.DragDropWithinSourceOrTarget && "Not after a BeginDragDropSource()?"); if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) - EndDragDropTooltip(); + EndTooltip(); // Discard the drag if have not called SetDragDropPayload() if (g.DragDropPayload.DataFrameCount == -1) ClearDragDrop(); -} - -void ImGui::BeginDragDropTooltip() -{ - // The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor) - // In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor. - // Whatever we do we want to call SetNextWindowPos() to enforce a tooltip position and disable clipping the tooltip without our display area, like regular tooltip do. - ImGuiContext& g = *GImGui; - //ImVec2 tooltip_pos = g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding; - ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale); - SetNextWindowPos(tooltip_pos); - SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f); - //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :( - BeginTooltipEx(0, true); -} - -void ImGui::EndDragDropTooltip() -{ - EndTooltip(); + g.DragDropWithinSourceOrTarget = false; } // Use 'cond' to choose to submit payload on drag start or every frame @@ -13632,8 +13633,10 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId)) return false; + IM_ASSERT(g.DragDropWithinSourceOrTarget == false); g.DragDropTargetRect = bb; g.DragDropTargetId = id; + g.DragDropWithinSourceOrTarget = true; return true; } @@ -13660,8 +13663,10 @@ bool ImGui::BeginDragDropTarget() if (g.DragDropPayload.SourceId == id) return false; + IM_ASSERT(g.DragDropWithinSourceOrTarget == false); g.DragDropTargetRect = display_rect; g.DragDropTargetId = id; + g.DragDropWithinSourceOrTarget = true; return true; } @@ -13717,8 +13722,10 @@ const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDrop // We don't really use/need this now, but added it for the sake of consistency and because we might need it later. void ImGui::EndDragDropTarget() { - ImGuiContext& g = *GImGui; (void)g; + ImGuiContext& g = *GImGui; IM_ASSERT(g.DragDropActive); + IM_ASSERT(g.DragDropWithinSourceOrTarget); + g.DragDropWithinSourceOrTarget = false; } //----------------------------------------------------------------------------- @@ -13944,7 +13951,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) (flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : ""); ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window)); - ImGui::BulletText("Active: %d, WriteAccessed: %d", window->Active, window->WriteAccessed); + ImGui::BulletText("Active: %d, WriteAccessed: %d", window->Active || window->WasActive, window->WriteAccessed); ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask); ImGui::BulletText("NavLastChildNavWindow: %s", window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL"); if (!window->NavRectRel[0].IsInverted()) diff --git a/imgui_internal.h b/imgui_internal.h index 91661e04..6cd259ef 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -692,6 +692,7 @@ struct ImGuiContext // Drag and Drop bool DragDropActive; + bool DragDropWithinSourceOrTarget; ImGuiDragDropFlags DragDropSourceFlags; int DragDropMouseButton; ImGuiPayload DragDropPayload; @@ -810,7 +811,7 @@ struct ImGuiContext OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging MouseCursor = ImGuiMouseCursor_Arrow; - DragDropActive = false; + DragDropActive = DragDropWithinSourceOrTarget = false; DragDropSourceFlags = 0; DragDropMouseButton = -1; DragDropTargetId = 0; @@ -1130,8 +1131,6 @@ namespace ImGui IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); IMGUI_API void ClearDragDrop(); IMGUI_API bool IsDragDropPayloadBeingAccepted(); - IMGUI_API void BeginDragDropTooltip(); - IMGUI_API void EndDragDropTooltip(); // FIXME-WIP: New Columns API IMGUI_API void BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns(). From 17efd7b3b025fa9351396b93ad8ea62fce60b3b1 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Jul 2018 19:55:57 +0200 Subject: [PATCH 6/8] Demo: Added basic Drag and Drop demo. (#143, #1931) --- CHANGELOG.txt | 1 + imgui_demo.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 984bc4fa..6c01be76 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -53,6 +53,7 @@ Other Changes: - Misc: Tweaked software mouse cursor offset to match the offset of the corresponding Windows 10 cursors. - Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276) - Windows: Fixed missing ImmReleaseContext() call in the default Win32 IME handler. (#1932) [@vby] + - Demo: Added basic Drag and Drop demo. (#143) - Examples: Metal: Added Metal rendering backend. (#1929, #1873) [@warrenm] - Examples: OSX: Added early raw OSX platform backend. (#1873) [@pagghiu, @itamago, @ocornut] - Examples: Added mac OSX & iOS + Metal example in example_apple_metal/. (#1929, #1873) [@warrenm] diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 04c6dcea..8cf6fd7e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -399,7 +399,7 @@ void ImGui::ShowDemoWindow(bool* p_open) static float col1[3] = { 1.0f,0.0f,0.2f }; static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; ImGui::ColorEdit3("color 1", col1); - ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n"); + ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nClick and hold to use drag and drop.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n"); ImGui::ColorEdit4("color 2", col2); } @@ -1186,6 +1186,83 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::TreePop(); } + if (ImGui::TreeNode("Drag and Drop")) + { + { + // ColorEdit widgets automatically act as drag source and drag target. + // They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets + // to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo. + ImGui::BulletText("Drag and drop in standard widgets"); + ImGui::Indent(); + static float col1[3] = { 1.0f,0.0f,0.2f }; + static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; + ImGui::ColorEdit3("color 1", col1); + ImGui::ColorEdit4("color 2", col2); + ImGui::Unindent(); + } + + { + ImGui::BulletText("Drag and drop to copy/swap items"); + ImGui::Indent(); + enum Mode + { + Mode_Copy, + Mode_Move, + Mode_Swap + }; + static int mode = 0; + if (ImGui::RadioButton("Copy", mode == Mode_Copy)) { mode = Mode_Copy; } ImGui::SameLine(); + if (ImGui::RadioButton("Move", mode == Mode_Move)) { mode = Mode_Move; } ImGui::SameLine(); + if (ImGui::RadioButton("Swap", mode == Mode_Swap)) { mode = Mode_Swap; } + static const char* names[9] = { "Bobby", "Beatrice", "Betty", "Brianna", "Barry", "Bernard", "Bibi", "Blaine", "Bryn" }; + for (int n = 0; n < IM_ARRAYSIZE(names); n++) + { + ImGui::PushID(n); + if ((n % 3) != 0) + ImGui::SameLine(); + ImGui::Button(names[n], ImVec2(60,60)); + + // Our buttons are both drag sources and drag targets here! + if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) + { + ImGui::SetDragDropPayload("DND_DEMO_CELL", &n, sizeof(int)); // Set payload to carry the index of our item (could be anything) + if (mode == Mode_Copy) { ImGui::Text("Copy %s", names[n]); } // Display preview (could be anything, e.g. when dragging an image we could decide to display the filename and a small preview of the image, etc.) + if (mode == Mode_Move) { ImGui::Text("Move %s", names[n]); } + if (mode == Mode_Swap) { ImGui::Text("Swap %s", names[n]); } + ImGui::EndDragDropSource(); + } + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_DEMO_CELL")) + { + IM_ASSERT(payload->DataSize == sizeof(int)); + int payload_n = *(const int*)payload->Data; + if (mode == Mode_Copy) + { + names[n] = names[payload_n]; + } + if (mode == Mode_Move) + { + names[n] = names[payload_n]; + names[payload_n] = ""; + } + if (mode == Mode_Swap) + { + const char* tmp = names[n]; + names[n] = names[payload_n]; + names[payload_n] = tmp; + } + } + ImGui::EndDragDropTarget(); + } + ImGui::PopID(); + } + ImGui::Unindent(); + } + + ImGui::TreePop(); + } + if (ImGui::TreeNode("Active, Focused, Hovered & Focused Tests")) { // Display the value of IsItemHovered() and other common item state functions. Note that the flags can be combined. From 6201cad2b4c34830c9da17833b359ee40ffcd1c6 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 9 Jul 2018 11:32:20 +0200 Subject: [PATCH 7/8] Examples: Comments, Demo: Log early out, TODO. (#1553) --- TODO.txt | 7 +++++-- examples/example_glfw_opengl3/main.cpp | 8 ++++++-- examples/example_sdl_opengl3/main.cpp | 7 +++++-- examples/imgui_impl_opengl3.cpp | 5 ++++- imgui_demo.cpp | 8 ++++++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index 513341ec..175687d4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -17,7 +17,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: background options for child windows, border option (disable rounding). - window: resizing from any sides? done. > need backends to honor mouse cursors properly. (#822) - window: resize from borders: support some form of outer padding to make it easier to grab borders. (#822) - - window: begin with *p_open == false should return false. + - window: fix resize glitch when collapsing an AlwaysAutoResize window. + - window: begin with *p_open == false could return false. - window: get size/pos helpers given names (see discussion in #249) - window: a collapsed window can be stuck behind the main menu bar? - window: when window is very small, prioritize resize button over close button. @@ -28,7 +29,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: using SetWindowPos() inside Begin() and moving the window with the mouse reacts a very ugly glitch. We should just defer the SetWindowPos() call. - window: GetWindowSize() returns (0,0) when not calculated? (#1045) - window: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. -!- scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. + - window: investigate better auto-positioning for new windows. + - 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 rendering. @@ -218,6 +220,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - drag and drop: add demo. (#143, #479) - drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov - drag and drop: allow using with other mouse buttons (where activeid won't be set). (#1637) + - drag and drop: make it easier and provide a demo to have tooltip both are source and target site, with a more detailed one on target site (tooltip ordering problem) - drag and drop: test with reordering nodes (in a list, or a tree node). (#143) - drag and drop: test integrating with os drag and drop. - drag and drop: make payload optional? (#143) diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 3cd6608d..b2dc5433 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -7,9 +7,13 @@ #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include -#include // This example is using gl3w to access OpenGL functions. You may freely use any other OpenGL loader such as: glew, glad, glLoadGen, etc. + +#include // This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc. //#include -#include +//#include +//#include + +#include // Include glfw3.h after our OpenGL definitions static void glfw_error_callback(int error, const char* description) { diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index ac20643f..798849d7 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -7,10 +7,13 @@ #include "imgui_impl_sdl.h" #include "imgui_impl_opengl3.h" #include -#include // This example is using gl3w to access OpenGL functions. You may freely use any other OpenGL loader such as: glew, glad, glLoadGen, etc. -//#include #include +#include // This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc. +//#include +//#include +//#include + int main(int, char**) { // Setup SDL diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 73c61477..9029ae5d 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -31,8 +31,11 @@ #include "imgui.h" #include "imgui_impl_opengl3.h" -#include // This example is using gl3w to access OpenGL functions. You may freely use any other OpenGL loader such as: glew, glad, glLoadGen, etc. + +#include // This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc. //#include +//#include +//#include // OpenGL Data static char g_GlslVersion[32] = ""; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8cf6fd7e..99d6ab14 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2905,7 +2905,7 @@ struct ExampleAppConsole // Here we create a context menu only available from the title bar. if (ImGui::BeginPopupContextItem()) { - if (ImGui::MenuItem("Close")) + if (ImGui::MenuItem("Close Console")) *p_open = false; ImGui::EndPopup(); } @@ -3172,7 +3172,11 @@ struct ExampleAppLog void Draw(const char* title, bool* p_open = NULL) { ImGui::SetNextWindowSize(ImVec2(500,400), ImGuiCond_FirstUseEver); - ImGui::Begin(title, p_open); + if (!ImGui::Begin(title, p_open)) + { + ImGui::End(); + return; + } if (ImGui::Button("Clear")) Clear(); ImGui::SameLine(); bool copy = ImGui::Button("Copy"); From 0708f916174d35a58087a978a37b0ff4f823cf1c Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 9 Jul 2018 15:04:27 +0200 Subject: [PATCH 8/8] Internals: Removed RootWindowForTabbing, won't be needed. Nav: Not starting NavWindowingTarget when a modal is active (was not noticeable). --- imgui.cpp | 19 +++++++++++++------ imgui_internal.h | 1 - 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1f39af48..79ba2619 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2135,7 +2135,6 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) ParentWindow = NULL; RootWindow = NULL; RootWindowForTitleBarHighlight = NULL; - RootWindowForTabbing = NULL; RootWindowForNav = NULL; NavLastIds[0] = NavLastIds[1] = 0; @@ -3063,12 +3062,19 @@ static void ImGui::NavUpdateWindowing() ImGuiWindow* apply_focus_window = NULL; bool apply_toggle_layer = false; + ImGuiWindow* modal_window = GetFrontMostPopupModal(); + if (modal_window != NULL) + { + g.NavWindowingTarget = NULL; + return; + } + bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed); bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard); if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavigable(g.Windows.Size - 1, -INT_MAX, -1)) { - g.NavWindowingTarget = window->RootWindowForTabbing; + g.NavWindowingTarget = window; g.NavWindowingHighlightTimer = g.NavWindowingHighlightAlpha = 0.0f; g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true; g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad; @@ -3137,7 +3143,7 @@ static void ImGui::NavUpdateWindowing() } // Apply final focus - if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindowForTabbing)) + if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindow)) { g.NavDisableHighlight = false; g.NavDisableMouseHover = true; @@ -3813,6 +3819,7 @@ void ImGui::NewFrame() UpdateMovingWindow(); UpdateHoveredWindowAndCaptureFlags(); + // Background darkening/whitening if (GetFrontMostPopupModal() != NULL) g.ModalWindowDarkeningRatio = ImMin(g.ModalWindowDarkeningRatio + g.IO.DeltaTime * 6.0f, 1.0f); else @@ -6181,11 +6188,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Initialize window->ParentWindow = parent_window; - window->RootWindow = window->RootWindowForTitleBarHighlight = window->RootWindowForTabbing = window->RootWindowForNav = window; + window->RootWindow = window->RootWindowForTitleBarHighlight = window->RootWindowForNav = window; if (parent_window && (flags & ImGuiWindowFlags_ChildWindow) && !window_is_child_tooltip) window->RootWindow = parent_window->RootWindow; if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) - window->RootWindowForTitleBarHighlight = window->RootWindowForTabbing = parent_window->RootWindowForTitleBarHighlight; // Same value in master branch, will differ for docking + window->RootWindowForTitleBarHighlight = parent_window->RootWindowForTitleBarHighlight; while (window->RootWindowForNav->Flags & ImGuiWindowFlags_NavFlattened) window->RootWindowForNav = window->RootWindowForNav->ParentWindow; @@ -7262,7 +7269,7 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags) bool ImGui::IsWindowNavFocusable(ImGuiWindow* window) { ImGuiContext& g = *GImGui; - return window->Active && window == window->RootWindowForTabbing && (!(window->Flags & ImGuiWindowFlags_NoNavFocus) || window == g.NavWindow); + return window->Active && window == window->RootWindow && (!(window->Flags & ImGuiWindowFlags_NoNavFocus) || window == g.NavWindow); } float ImGui::GetWindowWidth() diff --git a/imgui_internal.h b/imgui_internal.h index 6cd259ef..b7c7f07a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1002,7 +1002,6 @@ struct IMGUI_API ImGuiWindow ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. ImGuiWindow* RootWindow; // Point to ourself or first ancestor that is not a child window. ImGuiWindow* RootWindowForTitleBarHighlight; // Point to ourself or first ancestor which will display TitleBgActive color when this window is active. - ImGuiWindow* RootWindowForTabbing; // Point to ourself or first ancestor which can be CTRL-Tabbed into. ImGuiWindow* RootWindowForNav; // Point to ourself or first ancestor which doesn't have the NavFlattened flag. ImGuiWindow* NavLastChildNavWindow; // When going to the menu bar, we remember the child window we came from. (This could probably be made implicit if we kept g.Windows sorted by last focused including child window.)