Skip to content

A Selectable is Selected on right clicked when ImGuiMultiSelectFlags_SelectOnClickRelease is enable #8200

Closed

Description

@shinji12345

Version/Branch of Dear ImGui:

Version 1.91.6 WIP (19151), Branch: docking

Back-ends:

imgui_impl_dx12.cpp + imgui_impl_win32.cpp

Compiler, OS:

Windows11 + msvc2022

Full config/build information:

Dear ImGui 1.91.6 WIP (19151)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1938
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx12
io.ConfigFlags: 0x00000483
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1264.00,761.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

When ImGuiMultiSelectFlags_SelectOnClickRelease is enabled, a selectable is selected on mouse released for the left botton, but on mouse clicked for the right button.

Screenshots/Video:

Animation

Minimal, Complete and Verifiable Example code:

const int ITEMS_COUNT = 50;
static ImGuiSelectionBasicStorage selection;
static ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d;

if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnClickRelease", &flags, ImGuiMultiSelectFlags_SelectOnClickRelease) && (flags & ImGuiMultiSelectFlags_SelectOnClickRelease))
    flags &= ~ImGuiMultiSelectFlags_SelectOnClick;

static char* message = "";
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { message = "Left clicked"; }
else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { message = "Right clicked"; }
else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { message = "Left Released"; }
else if (ImGui::IsMouseReleased(ImGuiMouseButton_Right)) { message = "Right Released"; }
ImGui::Text(message);

if (ImGui::BeginChild("##Basket", ImVec2(-FLT_MIN, ImGui::GetFontSize() * 20), ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY))
{
    ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT);
    selection.ApplyRequests(ms_io);
    for (int n = 0; n < ITEMS_COUNT; n++)
    {
        char label[64];
        bool item_is_selected = selection.Contains((ImGuiID)n);
        const char* selected = item_is_selected ? "Selected" : "Unselected";
        sprintf(label, "Object %05d: Item (%s)", n, selected);
        ImGui::SetNextItemSelectionUserData(n);
        ImGui::Selectable(label, item_is_selected);
    }
    ms_io = ImGui::EndMultiSelect();
    selection.ApplyRequests(ms_io);
}
ImGui::EndChild();

Activity

  1. ocornut commented on Dec 4, 2024

    @ocornut
    Owner

    That's indeed the case. I forgot why right now but it was intended and seemed desirable at the time (I'll try to check my notes and tests).
    Why it is a problem for you?

  2. ocornut commented on Dec 4, 2024

    @ocornut
    Owner

    To clarify, that processing is automatically only enabled for Selectable in a multi-select context.
    Application like Visual Studio or Windows Explorer also seems to process the right-click selection on mouse down (and menus appears on menu up).
    There was another question related to similar code in #5816, but it's different from your question.

  3. ocornut commented on Oct 20, 2025

    @ocornut
    Owner

    As per #9015, added ImGuiMultiSelectFlags_NoSelectOnRightClick in 63bfad4. If that doesn't work for you please comment in #9015.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址