[Add] Nice, scrolling/scrollbar pretty much works in lists now.

This commit is contained in:
Allanis 2014-03-08 21:36:08 +00:00
parent 2f5ca43840
commit 1d175199f4

View File

@ -287,7 +287,7 @@ void window_addList(const unsigned int wid, const int x, const int y,
/* Position/Size. */
wgt->w = (double) w;
wgt->h = (double) h - ((h % (gl_defFont.h+2)) + 2);
wgt->h = (double) h - ((h % (gl_defFont.h+2)) - 2);
toolkit_setPos(wdw, wgt, x, y);
/* Check if needs scrollbar. */
@ -1165,7 +1165,8 @@ static void toolkit_renderList(Widget* lst, double bx, double by) {
/* We need to make room for list. */
w -= 10.;
scroll_pos = (double)lst->dat.lst.pos / ((double)lst->dat.lst.height - lst->h);
scroll_pos = (double)(lst->dat.lst.pos * (2 + gl_defFont.h));
scroll_pos /= ((double)lst->dat.lst.height - lst->h);
toolkit_drawScrollbar(x + lst->w - 10., y, 10., lst->h, scroll_pos);
}
@ -1179,7 +1180,7 @@ static void toolkit_renderList(Widget* lst, double bx, double by) {
/* Draw content. */
tx = (double)SCREEN_W/2. + x+2.;
ty = (double)SCREEN_H/2. + y+lst->h - 2. - gl_defFont.h;
miny = ty - lst->h;
miny = ty - lst->h + 2 + gl_defFont.h;
y = ty-2.;
w -= 4;
@ -1507,10 +1508,8 @@ static void toolkit_mouseEvent(SDL_Event* event) {
if(toolkit_isFocusable(wgt))
w->focus = i;
if(wgt->type == WIDGET_LIST) {
if(wgt->type == WIDGET_LIST)
toolkit_listFocus(wgt, x-wgt->x, y-wgt->y);
//input_key = 0; /* Hack to avoid weird bug with permascroll. */
}
else if(wgt->type == WIDGET_IMAGEARRAY)
toolkit_imgarrFocus(wgt, x-wgt->x, y-wgt->y);
@ -1729,6 +1728,7 @@ static void toolkit_listScroll(Widget* wgt, int direction) {
int xelem, yelem;
double hmax;
Window* wdw;
int pos;
if(wgt == NULL) return;
@ -1737,9 +1737,25 @@ static void toolkit_listScroll(Widget* wgt, int direction) {
switch(wgt->type) {
case WIDGET_LIST:
wgt->dat.lst.selected -= direction;
/* Boundary check. */
wgt->dat.lst.selected = MAX(0, wgt->dat.lst.selected);
wgt->dat.lst.selected = MIN(wgt->dat.lst.selected, wgt->dat.lst.noptions-1);
if(wgt->dat.lst.fptr) (*wgt->dat.lst.fptr)(wdw->id, wgt->name);
/* See if we have to scroll. */
pos = (wgt->dat.lst.selected - wgt->dat.lst.pos);
if(pos < 0) {
wgt->dat.lst.pos += pos;
if(wgt->dat.lst.pos < 0)
wgt->dat.lst.pos = 0;
}
else if(2 + (pos+1) * (gl_defFont.h + 2) > wgt->h) {
wgt->dat.lst.pos += (2 + (pos+1) * (gl_defFont.h + 2) - wgt->h) / (gl_defFont.h + 2);
}
if(wgt->dat.lst.fptr)
(*wgt->dat.lst.fptr)(wdw->id, wgt->name);
break;
case WIDGET_IMAGEARRAY: