Skip to content

What is the correct/easiest way to get the max y scroll value? #770

@rswinkle

Description

@rswinkle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions