# HG changeset patch # User Michael Pavone # Date 1555988635 25200 # Node ID b6ad26acade4cba10f3dff608c56784f20617fe2 # Parent 7a9e6fd94d616cca04a79ef722f9dd1acde460ae Adjust scroll of parent layout object if widget newly selected by keyboard is offscreen diff -r 7a9e6fd94d61 -r b6ad26acade4 nuklear_ui/nuklear.h --- a/nuklear_ui/nuklear.h Mon Apr 22 09:36:10 2019 -0700 +++ b/nuklear_ui/nuklear.h Mon Apr 22 20:03:55 2019 -0700 @@ -20292,6 +20292,7 @@ c.y = (float)((int)c.y); c.w = (float)((int)c.w); c.h = (float)((int)c.h); + int newly_selected = nk_false; if (is_keynav) { ctx->input.widget_counter++; if ( @@ -20299,16 +20300,26 @@ ctx->input.keyboard.keys[NK_KEY_UP].clicked && ctx->input.keyboard.keys[NK_KEY_UP].down ) { ctx->input.selected_widget--; + newly_selected = nk_true; } else if ( ctx->input.selected_widget == (ctx->input.widget_counter - 1) && ctx->input.keyboard.keys[NK_KEY_DOWN].clicked && ctx->input.keyboard.keys[NK_KEY_DOWN].down ) { ctx->input.keyboard.keys[NK_KEY_DOWN].clicked = 0; ctx->input.selected_widget++; + newly_selected = nk_true; } } nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); + if (is_keynav && newly_selected) { + //ensure widget is fully on-screen if it was newly selected via a keyboard action + if ((bounds->y + bounds->h) > (c.y + c.h)) { + *layout->offset_y += bounds->y + bounds->h - (c.y + c.h); + } else if(c.y > bounds->y){ + *layout->offset_y -= c.y - bounds->y; + } + } if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) return NK_WIDGET_INVALID; if ((is_keynav && ctx->input.selected_widget == ctx->input.widget_counter ) || NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h))