-
Notifications
You must be signed in to change notification settings - Fork 595
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
What is the correct/easiest way to get the max y scroll value? #770
Comments
Based on v4.12.3, the
The minimum value of The vertical scrollbar limit is determined based on the panel height of the
In the above described case, where the panel vertical space is not determined accurately as expected by the list view widget, the given formula could be caused for misalignments:
I did not look into the mouse scroll event handling part of the code and could not determine why y offset max becomes what it does. If you can figure that out I am also interested in it. As a design alternative, could it happen that injecting |
I'm pretty sure I'm already taking that into account. I based my code on this from nk_list_view_begin():
This means that you can't just put in your font size (or even more conveniently 0 as you can for most other common functions), but you also can't include spacing since they do it for you, clearly. You can see in my original code snippet that I use the nk_list_view total height which is exactly the calculation you're talking about. But logically the max scroll value should not be that unless the list panel were 1 pixel thick. The scrollbar should have have a travel equal to the total height of all the elements minus the height visible in the pane (ie the visible clipping rectangle) because you only have to scroll till the bottom of the list view hits the end of the list, not the top. Clearly I'm close but missing some aspect.
This is the same problem as above. Whether it's manual or internal based on scroll events, I am not grokking the calculation or how to get it in my own code.
This is worth looking into as it might sidestep the issue to some extent but then you have to know how big a delta to inject which might just mean a different but equally close-but-not-quite calculation. Regardless, I'd still rather know and how to do it right should be documented and understood. This discussion would be much easier with real world code to look at. I have it already, as part of a larger project, but give me a few days and I'll have a smaller project and/or hopefully a pull request we can experiment with and discuss specifically. |
Ok I've managed to cleanup/organize the code a bit more, enough to separate it out into a library for demo/discussion purposes at least: Long term it would be cool to get this into the repo as one of the common demos commented out in all. The current file_browser demo is nice (and I took inspiration from it for the breadcrumb buttons) but a bit unwieldy and I think my list based approach modeled on standard file selection dialogs is more practical. You can see the scrolling code we were discussing before here. There are actually 3 reasonable ways I can think of to handle scrolling via keyboard:
In either case 1 or 2, we need a reliable convenient way of getting the max scroll value and calculating an offset based on that, or an API function that does exactly what we need directly somehow. Something that throws a wrench in the works of all of these to some extent is when the list panel shows partial elements. If you have space to show 10.5 list elements, you don't want to not scroll because item 11 is technically already shown and I think it also might be a source of my inconsistent results as well. You can see I have a hacky hybrid 1+2 approach in my larger project here and 3 other places in that file. I'm not happy with it, I would definitely prefer 2 on its own but there's little point till I understand how to do the calculation correctly. Any help/advice from anyone is appreciated, not just about this specific issue but about the nuklear file_browser code in general and ways to improve it and make it more plug n' play. Of course SDL3 just made it obsolete since they added standard Dialogs not to mention some convenient file system functions but SDL3 is still a long way from make it into the majority of distros, let alone as the default, and all the other Nuklear backends could still benefit from an easy to use file browser/selection dialog. |
I went through
After several hours of trial and error I could not figure out any ways via using public API to set |
This is what I get for developing it in parallel, sometimes I fix things in sdl_img and don't mirror them back or vice versa. I had this fixed in sdl_img but not here. It changes things a little but things still don't look like I expect them to.
This is just an observation right? Nothing wrong here, though I'll get back to your numbers later
I don't know why I'm solving it that way in the first place (which I also have in sdl_img) instead of the way I changed line 550. It may still be incorrect but if at all possible we should be abl eto get the correct height directly without having to do annoying calculations like this. I've changed it to get bound.y like I did for the other one.
This is where we get back to those numbers and you lose me. I dug into this before for determining min window dimensions for a single row and came up with +16 from
text.padding.y is 0 and min_row_height_padding is 8 so I do FONT_SIZE+16 for nk_list_view_begin().
I'm not sure I'm parsing this correctly but it sounds like you might have beat your head against one of the same thing I did a while ago till I just said "good enough, doesn't seem to make much visual difference". To sum up we have at least a few distinct but related issues:
|
My question could apply to any window/group etc. though I'm specifically dealing with list views.
I have code that lets the user navigate through the list with the keyboard and I need to update the scroll position manually based on that as appropriate. I've mostly gotten by with code like this:
With a few variants. Sometimes it seems to work perfectly, but often it's off a little at the end. Also sometimes list views let you scroll past the last element by a whole row or two and I don't know why.
Digging through the code has been less than helpful and I'd really rather not waste more time trying to figure it out if someone already knows. I've seen some old issues that are adjacent to this issue. Some about a flashing screen when setting to some arbitrary high number to get to the end. I have seen that flashing before when unnecessarily adjusting the scroll position but that's not really the issue.
Thanks in advance for any help/advice.
The text was updated successfully, but these errors were encountered: