Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
What is the correct/easiest way to get the max y scroll value?
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
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:
```
// list stuff here removed for brevity
list_height = ctx->current->layout->clip.h; // ->bounds.h?
nk_list_view_end(&rview);
}
if (do_adjust && rview.total_height > list_height) {
int scroll_limit = rview.total_height - list_height; // little off
nk_uint y = (selection/(float)(list.size-1) * scroll_limit) + 0.999f;
nk_group_set_scroll(ctx, "List", 0, y);
do_adjust = SDL_FALSE;
}
```
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the list-view code around nk_list_view_end and the scrolling behavior of nk_group_set_scroll. Reproduce the reported end-of-list overscroll and compare the calculated total height with the available clip height; done means the correct maximum scroll value and the cause of the extra-row behavior are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100