X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftui_list.c;h=42551eaefedaee78ee79acd7e1a82f4c24b5d8a2;hb=8b4d2adf48213f2bf74ca1a423b1ac3dc8066f95;hp=c5f510c9f8d22bb4f6e8d89c33c5b6130a3f60bc;hpb=6120587cce15206faa7a38207961a89110de3bcd;p=oftp diff --git a/src/tui_list.c b/src/tui_list.c index c5f510c..42551ea 100644 --- a/src/tui_list.c +++ b/src/tui_list.c @@ -79,9 +79,11 @@ int tui_num_list_items(struct tui_widget *w) return darr_size(wl->entries); } +#define VISLINES(wl) ((wl)->height - 2) + int tui_list_select(struct tui_widget *w, int idx) { - int offs, nelem; + int offs, nelem, numvis; struct tui_list *wl = (struct tui_list*)w; assert(wl->type == TUI_LIST); @@ -89,6 +91,8 @@ int tui_list_select(struct tui_widget *w, int idx) return 0; /* no change */ } + numvis = VISLINES(wl); + if(idx < 0) { wl->sel = -1; return 0; @@ -98,10 +102,10 @@ int tui_list_select(struct tui_widget *w, int idx) } wl->sel = idx; - if(idx < wl->view_offs || idx >= wl->view_offs + wl->height) { - offs = idx - wl->height / 2; - if(offs + wl->height >= nelem) { - offs = nelem - wl->height; + if(idx < wl->view_offs || idx >= wl->view_offs + numvis) { + offs = idx - numvis / 2; + if(offs + numvis >= nelem) { + offs = nelem - numvis; } if(offs < 0) { offs = 0; @@ -123,18 +127,20 @@ int tui_get_list_sel(struct tui_widget *w) int tui_list_sel_next(struct tui_widget *w) { - int nelem; + int nelem, numvis; struct tui_list *wl = (struct tui_list*)w; assert(wl->type == TUI_LIST); nelem = darr_size(wl->entries); + numvis = VISLINES(wl); + if(wl->sel + 1 >= nelem) { return -1; } - if(++wl->sel - wl->view_offs >= wl->height) { - wl->view_offs = wl->sel - wl->height; + if(++wl->sel - wl->view_offs >= numvis) { + wl->view_offs = wl->sel - numvis + 1; } wl->dirty = 1; tui_call_callback(w, TUI_ONMODIFY); @@ -171,14 +177,15 @@ int tui_list_sel_start(struct tui_widget *w) int tui_list_sel_end(struct tui_widget *w) { - int nelem; + int nelem, numvis; struct tui_list *wl = (struct tui_list*)w; assert(wl->type == TUI_LIST); nelem = darr_size(wl->entries); + numvis = VISLINES(wl); wl->sel = nelem - 1; - wl->view_offs = nelem - wl->height; + wl->view_offs = nelem - numvis; if(wl->view_offs < 0) wl->view_offs = 0; wl->dirty = 1; tui_call_callback(w, TUI_ONMODIFY);