Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

simplify scrolling in windows using the `cata_imgui::window` class

Open db48x opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Currently every window that we write using this class has to handle scrolling for itself. Of course each one has its own input context, so part of that is expected.

First we draw the window, then check for input, then store the scroll direction as a member variable, then go back around the loop. The next time around we see the scroll direction, act on it, and clear the variable. This would be less clumsy if we got rid of the member variable. We should simplify this sort of thing, because if we repeat it over a few more windows it will get annoying.

Solution you would like.

What we want to be able to do is check for input, compute the scroll amount, call ImGui::SetNextWindowScroll() (or any other code that we want to write), then draw our window (and all the others). But because we’re about to cause all the ImGui windows to be redrawn a call to ImGui::SetNextWindowScroll() here would end up scrolling the wrong window. Instead we want to inject some code into cata_imgui::window::draw(). But a callback seems really awkward for that, I think.

So maybe what we want is for the window class to have an ImVec2 scroll_amount; (or whatever) that we can set. window::draw() would then call ImGui::SetNextWindowPos( scroll_amount ) for us, then reset it to { -1.0f, -1.0f } so that nothing happens next frame. It’s still setting and resetting a member variable, but at least it’s hidden away in the base class and we don’t have to reimplement it again and again for every window.

Describe alternatives you have considered.

No response

Additional context

No response

db48x avatar Aug 28 '24 10:08 db48x

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

github-actions[bot] avatar Jan 15 '25 22:01 github-actions[bot]