Skip to content

Issue with SetNextWindowScroll  #8196

Closed
@pozemka

Description

Version/Branch of Dear ImGui:

v1.91.5 docking-experimental

Back-ends:

imgui_impl_glfw.h + imgui_impl_opengl3.h

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

Dear ImGui 1.91.5 (19150)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1942
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
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: 1280.00,720.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:

Hello!

I am trying to scroll to the certain part of the table when window is just presented to user and let the user to scroll freely after that. I am using flag to call scroll function only on the first frame.

I found that using ImGui::SetScrollY will introduce 1 frame delay, which is visible in some situations.

Then I tried to use SetNextWindowScroll which should work on the same frame. But whatever I try it won't work on the first frame. Only on second. I found #6349 issue but adding SetNextWindowContentSize doesn't help.

In console I see that ContentSize was set but Scroll was not:

[00001] Inside window: Scroll=0.000/16269.000, ContentSize=17000.000

Here is my minimal code. Please note that not entire window is scrollable but only the table.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

const int   elements_count = 1000;
const float scroll_to_y = 200 * ImGui::GetTextLineHeightWithSpacing();
const float scroll_area_height = static_cast<float>(elements_count) * ImGui::GetTextLineHeightWithSpacing();

ImGui::SetNextWindowSize({400.f, 800.f}, ImGuiCond_Always);
ImGui::Begin("MyWindow", nullptr, ImGuiWindowFlags_NoSavedSettings);
ImGui::Text("This should be");
ImGui::Text("above scrollable table");

static int frame = 0;
// if (frame == 1) { //Work ok
if (frame == 0) { // Doesn't work
    ImGui::SetNextWindowContentSize(ImVec2(0, scroll_area_height));
    ImGui::SetNextWindowScroll(ImVec2(0.0f, scroll_to_y));
}
++frame;

static constexpr ImGuiTableFlags table_flags = ImGuiTableFlags_ScrollY;
if (ImGui::BeginTable("Table", 1, table_flags, ImGui::GetContentRegionAvail())) {
    for (int i = 0; i < elements_count; ++i) {
        ImGui::TableNextColumn();
        ImGui::Text("Element %d", i);
    }

    ImGuiWindow* window = GImGui->CurrentWindow;
    IMGUI_DEBUG_LOG("Inside window: Scroll=%.3f/%.3f, ContentSize=%.3f\n",
                    window->Scroll.y,
                    window->ScrollMax.y,
                    window->ContentSize.y);

    ImGui::EndTable();
}

ImGui::End();

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions