Skip to content

Button not working when placed on the same line of a Selectable #5692

@MirrasHue

Description

@MirrasHue
Dear ImGui 1.89 WIP (18808)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: _WIN32
define: _WIN64
define: __MINGW32__
define: __MINGW64__
define: __GNUC__=12
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
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,128
io.DisplaySize: 800.00,600.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

Version/Branch of Dear ImGui:

Version: 1.89
Branch: Docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp
Compiler: GCC 12.1
Operating System: Windows 10

My Issue/Question:

I'm trying to place a selectable and a small button on the same line, but only the first button works and the others don't.

The problem doesn't seem to be the ListBox, given that when I try whithout it, the second up to the last button don't work.

I tried looking for this issue, but couldn't find it anywhere, is there a solution?

Screenshots/Video

image

Standalone, minimal, complete and verifiable example: (see #2261)

ImGui::Begin("Viewport");
{
    static const char* items[] = {"0", "1", "2", "3", "4", "5"};
    static int selectedIdx = -1;
    
    if(ImGui::BeginListBox("##listbox", ImVec2(-FLT_MIN, ImGui::GetContentRegionAvail().y * 0.5f)))
    {
        for(int i = 0; i < 6; ++i)
        {
            bool bIsSelected = (selectedIdx == i);

            if(ImGui::Selectable(items[i], bIsSelected, ImGuiSelectableFlags_AllowItemOverlap))
            {
                if(bIsSelected) // Clicking on the same object twice to deselect
                    selectedIdx = -1;
                else
                    selectedIdx = i;
            }
            ImGui::SameLine();

            if(ImGui::SmallButton("delete"))
            {
                printf("Index of item to be deleted = %i\n", i);
            }
        }
        ImGui::EndListBox();
    }
}
ImGui::End();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions