slightly better scroll bar

master
Allen Webster 2016-05-09 12:20:39 -04:00
parent 3821b46a71
commit 375a9883c0
1 changed files with 38 additions and 46 deletions

View File

@ -3643,6 +3643,28 @@ view_get_scroll_y(View *view){
return(v); return(v);
} }
internal b32
scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input,
GUI_id id, b32 *is_animating){
b32 result = 0;
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
if (hit_check(mx, my, session->rect)){
target->hover = id;
if (user_input->mouse.l){
target->mouse_hot = id;
gui_activate_scrolling(target);
*is_animating = 1;
result = 1;
}
}
else if (gui_id_eq(target->hover, id)){
target->hover = {0};
}
return(result);
}
internal b32 internal b32
do_input_file_view(System_Functions *system, Exchange *exchange, do_input_file_view(System_Functions *system, Exchange *exchange,
View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input){ View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input){
@ -3784,33 +3806,6 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
}break; }break;
case guicom_scrollable_top:
{
GUI_id id = gui_id_scrollbar_top();
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
if (hit_check(mx, my, gui_session.rect)){
target->hover = id;
if (user_input->mouse.press_l){
target->mouse_hot = id;
is_animating = 1;
}
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, id)){
target->mouse_hot = {0};
target->scroll_updated.target_y -= target->delta;
if (target->scroll_updated.target_y < target->scroll_updated.min_y){
target->scroll_updated.target_y = target->scroll_updated.min_y;
}
gui_activate_scrolling(target);
is_animating = 1;
}
}
else if (gui_id_eq(target->hover, id)){
target->hover = {0};
}
}break;
case guicom_scrollable_slider: case guicom_scrollable_slider:
{ {
GUI_id id = gui_id_scrollbar_slider(); GUI_id id = gui_id_scrollbar_slider();
@ -3852,30 +3847,27 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
}break; }break;
case guicom_scrollable_top:
{
GUI_id id = gui_id_scrollbar_top();
if (scroll_button_input(target, &gui_session, user_input, id, &is_animating)){
target->scroll_updated.target_y -= target->delta * 0.25f;
if (target->scroll_updated.target_y < target->scroll_updated.min_y){
target->scroll_updated.target_y = target->scroll_updated.min_y;
}
}
}break;
case guicom_scrollable_bottom: case guicom_scrollable_bottom:
{ {
GUI_id id = gui_id_scrollbar_bottom(); GUI_id id = gui_id_scrollbar_bottom();
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
if (hit_check(mx, my, gui_session.rect)){ if (scroll_button_input(target, &gui_session, user_input, id, &is_animating)){
target->hover = id; target->scroll_updated.target_y += target->delta * 0.25f;
if (user_input->mouse.press_l){
target->mouse_hot = id;
is_animating = 1;
}
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, id)){
target->mouse_hot = {0};
target->scroll_updated.target_y += target->delta;
if (target->scroll_updated.target_y > target->scroll_updated.max_y){ if (target->scroll_updated.target_y > target->scroll_updated.max_y){
target->scroll_updated.target_y = target->scroll_updated.max_y; target->scroll_updated.target_y = target->scroll_updated.max_y;
} }
gui_activate_scrolling(target);
is_animating = 1;
}
}
else if (gui_id_eq(target->hover, id)){
target->hover = {0};
} }
}break; }break;