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

SelectableFlags_SpanAllColumns doesn't span all columns when horizontal scrolling #3187

Closed
PazerOP opened this issue May 2, 2020 · 2 comments

Comments

@PazerOP
Copy link
Contributor

PazerOP commented May 2, 2020

Dear ImGui version/build info:

Dear ImGui 1.77 WIP (17601)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201705
define: _WIN32
define: _WIN64
define: _MSC_VER=1925
--------------------------------
io.BackendPlatformName: imgui_impl_sdl
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000001
 NavEnableKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x00000006
 HasMouseCursors
 HasSetMousePos
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 800.00,600.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 0.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:

Lastest commit on master at the current time, a2454f2

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
Compiler: VS2019 16.5.0
Operating System: Windows 10 1909 (18363)

My Issue/Question:

When the current window is scrolled horizontally, ImGuiSelectableFlags_SpanAllColumns doesn't work properly. It appears to stop where the visible area would end if the window was not being scrolled horizontally. This is not just a cosmetic issue, it affects hit testing as well (moving the mouse to the right of the blue area in the selectable causes it to leave the hovered state).

I considered submitting a pull request that changed window->ContentRegionRect to window->DC.CurrentColumns->HostWorkRect on both lines of

imgui/imgui_widgets.cpp

Lines 5617 to 5618 in a2454f2

const float min_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? window->ContentRegionRect.Min.x : pos.x;
const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? window->ContentRegionRect.Max.x : GetContentRegionMaxAbs().x;
, which appears to fix the issue, but I have no idea if that is the "correct" way of fixing the issue.

Screenshots/Video

The minimal example code below produces the following window:
image

However, if we scroll to the right, we see the selectable in the first column is actually clamped to the initially visible region of the window:
image

Standalone, minimal, complete and verifiable example:

ImGui::SetNextWindowSize({ 300, 300 }, ImGuiCond_Always);
if (ImGui::Begin("TestWindow", nullptr, ImGuiWindowFlags_HorizontalScrollbar))
{
	ImGui::Columns(2);

	ImGui::Selectable("A Selectable In A Column", true, ImGuiSelectableFlags_SpanAllColumns); ImGui::NextColumn();
	ImGui::Text("Very long column 2 aaaaaaaaaaaaaaaaaaaaaaaa"); ImGui::NextColumn();
	ImGui::Columns();

	ImGui::Text("A very long string of text that forces the content width to be wide enough that horizontal scrollbars show up");
}
ImGui::End();
@zodiacon
Copy link

It doesn't seem to solve the issue completely with Tables. When scrolling horizontally (with SpanAllColumns), it does highlight the entire row BUT clicking at the area scrolled in is ignored.
(Probably a related bug)

@ocornut
Copy link
Owner

ocornut commented Aug 5, 2020

Thanks @PazerOP for reporting this.
This should now be fixed in master (by 8074b49).

Various tests for it:

if (ImGui::Begin("Test A", NULL, ImGuiWindowFlags_HorizontalScrollbar))
{
    ImGui::Button("Spacer", ImVec2(500, 0));
    ImGui::Selectable("Selectable");
    if (ImGui::TreeNodeEx("TreeNode", ImGuiTreeNodeFlags_SpanAvailWidth))
        ImGui::TreePop();
}
ImGui::End();

ImGui::SetNextWindowSize(ImVec2(300, 300), ImGuiCond_Once);
if (ImGui::Begin("Test B #3187", NULL, ImGuiWindowFlags_HorizontalScrollbar))
{
    ImGui::Columns(2);

    ImGui::Selectable("Selectable Col 0 Regular", false);
    ImGui::Selectable("Selectable Col 0 SpanAllColumns", false, ImGuiSelectableFlags_SpanAllColumns);
    ImGui::NextColumn();
    ImGui::Text("Very long column 2 aaaaaaaaaaaaaaaaaaaaaaaa");
    ImGui::NextColumn();

    ImGui::Text("Blah blah");
    ImGui::NextColumn();
    ImGui::Selectable("Selectable Col 1 Regular", false);
    ImGui::Selectable("Selectable Col 1 SpanAllColumns", false, ImGuiSelectableFlags_SpanAllColumns);
    ImGui::NextColumn();

    ImGui::Columns();

    ImGui::Text("A very long string of text that forces the content width to be wide enough that horizontal scrollbars show up");
}
ImGui::End();

#ifdef IMGUI_HAS_TABLE
if (ImGui::Begin("Test C #3386"))
{
    if (ImGui::BeginTable("Table", 2, ImGuiTableFlags_ScrollFreezeTopRow | ImGuiTableFlags_Scroll | ImGuiTableFlags_ScrollFreezeLeftColumn))
    {
        ImGui::TableSetupColumn("Col 1", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHide, 200);
        ImGui::TableSetupColumn("Col 2", ImGuiTableColumnFlags_WidthFixed, 200);
        ImGui::TableAutoHeaders();

        ImGui::TableNextRow();
        ImGui::TableSetColumnIndex(0);

        ImGui::Selectable("Selectable Col 0 Regular");
        ImGui::Selectable("Selectable Col 0 SpanAllColumns", false, ImGuiSelectableFlags_SpanAllColumns);
        if (ImGui::TableNextCell())
            ImGui::TextUnformatted("Blah blah");

        ImGui::TableNextRow();
        ImGui::TableSetColumnIndex(0);
        ImGui::TextUnformatted("Blah blah");

        ImGui::TableSetColumnIndex(1);
        ImGui::Selectable("Selectable Col 1 Regular");
        ImGui::Selectable("Selectable Col 1 SpanAllColumns", false, ImGuiSelectableFlags_SpanAllColumns);

        ImGui::EndTable();
    }
}
ImGui::End();
#endif

@ocornut ocornut closed this as completed Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants