Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MirrasHue opened this issue Sep 19, 2022 · 2 comments
Closed

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

MirrasHue opened this issue Sep 19, 2022 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@MirrasHue
Copy link

MirrasHue commented Sep 19, 2022

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();
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Sep 19, 2022
@ocornut
Copy link
Owner

ocornut commented Sep 19, 2022

You have an ID collection and likely you use PushID(i) in your loop to make the ID on each line unique.
See FAQ https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-about-the-id-stack-system

@ocornut ocornut closed this as completed Sep 19, 2022
@MirrasHue
Copy link
Author

Oh man, thanks. The problem wasn't apparent to me at first, now I see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants