added scroll list
This commit is contained in:
45
src/scroll.c
Executable file
45
src/scroll.c
Executable file
@@ -0,0 +1,45 @@
|
||||
#include "tim.h"
|
||||
|
||||
void TimScrollState_selectNext(TimScrollState* l){
|
||||
l->cur = (l->cur + 1) % l->len;
|
||||
}
|
||||
|
||||
void TimScrollState_selectPrev(TimScrollState* l){
|
||||
l->cur = (l->len + l->cur - 1) % l->len;
|
||||
}
|
||||
|
||||
TimScrollItem* tim_scroll(TimScrollState* l, i32 x, i32 y, i32 w, i32 h, TimStyle style){
|
||||
// select with buttons and mouse wheel
|
||||
if(tim_is_key_press(TimKey_Down)
|
||||
|| (l->use_mouse_wheel && tim_is_mouse_scroll_down()))
|
||||
{
|
||||
TimScrollState_selectNext(l);
|
||||
}
|
||||
if(tim_is_key_press(TimKey_Up)
|
||||
|| (l->use_mouse_wheel && tim_is_mouse_scroll_up()))
|
||||
{
|
||||
TimScrollState_selectPrev(l);
|
||||
}
|
||||
|
||||
tim->focus = l->items[l->cur].focus_target;
|
||||
|
||||
tim_frame(x, y, w, h, style);
|
||||
|
||||
TimRect absolute = tim_scope_rect_to_absolute(x, y, w, h);
|
||||
TimRect place = { .x = x + 1, .y = y + 1, .w = absolute.w - 2, .h = absolute.h - 2 };
|
||||
for(u32 i = 0; i < l->len; i++){
|
||||
TimScrollItem* item = &l->items[i];
|
||||
place.h = item->h;
|
||||
|
||||
// select with mouse click
|
||||
if(tim_is_mouse_click_over(tim_scope_rect_to_absolute(place.x, place.y, place.w, place.h))){
|
||||
l->cur = i;
|
||||
tim->focus = item->focus_target;
|
||||
}
|
||||
|
||||
item->draw(i == l->cur, place, item->data);
|
||||
place.y += place.h;
|
||||
}
|
||||
|
||||
return &l->items[l->cur];
|
||||
}
|
||||
Reference in New Issue
Block a user