How to make scrolling for window

Started by
2 comments, last by Thaumaturge 1 year, 9 months ago

I make simple immediate mode gui for myself and I don't know how to make right scrolling for window content. I

tried to use two 2 ways. First I add scrolling delta to window content. Second I try to use simple formula (scroll y / scroll height) * window content size. But I get the same probleem when I move mouse to fast I get window content

in wrong place when I move slowe I get right result. I watched in Dear ImGUI library but it is hard for me to understand for what code do.

Advertisement

I don't know imgui, but I am guessing that with a slow move it is also wrong but much less visible to the point that you don't see it anymore.

What I am missing in your formula is display height. When I have 500 length window content, and I can see 100 of that, you can only scroll 500-100=400 length. If you scroll more, then either the bottom of the content moves above the bottom of the displayed area, or the top of the content moves below the top of the displayed area.

What might work here is “print" debugging. Whenever you have a non-zero scroll, print all the relevant numbers to the screen or to a file. Then you can see what is happening and possibly find the error.

Could it be that when you move your mouse quickly the cursor ends up beyond the end of the scroll-bar, and thus you end up with a value for “scroll y” that is outside of the intended bounds?

This would result in a value for “scroll y / scroll height” that is either too large or too small (depending on which end of the scroll-bar the mouse passed beyond), causing your window to be scrolled by more than the size of the window-content.

If so, perhaps your issue might be corrected by clamping the value of “scroll y” to its intended bounds--those presumably being the range from 0 to “scroll height”.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement