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

Question: fine-tuning the window scrollbar #7709

Closed
ElectroidDes opened this issue Jun 18, 2024 · 5 comments
Closed

Question: fine-tuning the window scrollbar #7709

ElectroidDes opened this issue Jun 18, 2024 · 5 comments

Comments

@ElectroidDes
Copy link

ElectroidDes commented Jun 18, 2024

Version/Branch of Dear ImGui:

1.90.6

Back-ends:

imgui_impl_XXX.cpp + imgui_impl_XXX.cpp

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

Can you please tell me if Imgui has a function for adding “arrows” to fine-tune window scrolling?
It’s just that when there is a lot of “content” in the window, scrolling with the slider is very inaccurate - it’s difficult to position and find the desired element in the window, it constantly skips.

Of course, I completely made my own scrollbar by drawing them using ImGui::GetWindowDrawList() and setting up the logic, but this is not very convenient to use; it would be much more convenient and easier to use an already existing scrollbar with fine tuning.

@ocornut
Copy link
Owner

ocornut commented Jun 18, 2024

Since 1.90.8 scrollbar have been changed to scroll page by page when clicking outside the grab. (#7328)
Would that help?

@ElectroidDes
Copy link
Author

Since 1.90.8 scrollbar have been changed to scroll page by page when clicking outside the grab. (#7328) Would that help?

Thanks, I checked it and it definitely improves the positioning accuracy of the scrollbar :)

@ElectroidDes
Copy link
Author

ElectroidDes commented Jun 20, 2024

scroll page works with this simple example:

   static int size = 10000;

    ImGui::Begin("Window text 1");

    for (int i = 0; i < size; ++i) 
    {
        ImGui::Text("This is line number %d", i);
    }
    ImGui::End();

However, when I try to use the same code with the ImGuiListClipper class, scrolling across the page doesn't seem to work - it scrolls more than one page:

    ImGui::Begin("Window text 2");

    ImGuiListClipper clipper;

    clipper.Begin(size, ImGui::GetTextLineHeight());

    while (clipper.Step())
    {
        for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
        {
            ImGui::Text("This is line number %d", i);
        }
    }

    clipper.End();

    ImGui::End();

Perhaps I misunderstand something.

@GamingMinds-DanielC
Copy link
Contributor

Perhaps I misunderstand something.

You are giving the clipper an explicit height that is too small, therefore it thinks that more lines will fit. GetTextLineHeight() will give you only the height of a line itself without the spacing to the next line, try GetTextLineHeightWithSpacing() instead.

@ElectroidDes
Copy link
Author

ElectroidDes commented Jun 21, 2024

Возможно, я что-то неправильно понимаю.

Вы задаете клипперу слишком маленькую высоту, поэтому он думает, что поместится больше линий. даст вам только высоту самой строки без интервала до следующей строки, попробуйте вместо этого.GetTextLineHeight()``GetTextLineHeightWithSpacing()

It works. Thank you very much!

@ocornut ocornut closed this as completed Jun 21, 2024
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