rudimentary invisible scrollbar

This commit is contained in:
Allen Webster 2016-05-19 17:31:11 -04:00
parent 8bf8e36723
commit 2800352ee6
5 changed files with 181 additions and 125 deletions

View File

@ -3396,6 +3396,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
f32 min_target_y = view->recent->scroll.min_y; f32 min_target_y = view->recent->scroll.min_y;
b32 show_scrollbar = 0;
view->current_scroll = 0; view->current_scroll = 0;
gui_begin_top_level(target, input); gui_begin_top_level(target, input);
@ -3418,7 +3420,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
f32 target_y = 0; f32 target_y = 0;
view->current_scroll = &view->recent->scroll; view->current_scroll = &view->recent->scroll;
if (gui_get_scroll_vars(target, view->showing_ui, &view->recent->scroll, &view->scroll_region)){ if (gui_get_scroll_vars(target, view->showing_ui,
&view->recent->scroll, &view->scroll_region)){
target_y = view->recent->scroll.target_y; target_y = view->recent->scroll.target_y;
if (cursor_y > target_y + cursor_max_y){ if (cursor_y > target_y + cursor_max_y){
cursor_y = target_y + cursor_max_y; cursor_y = target_y + cursor_max_y;
@ -3434,11 +3437,13 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
else{ else{
cursor_y -= view->font_height; cursor_y -= view->font_height;
} }
view->file_data.cursor = view_compute_cursor_from_xy(view, view->file_data.preferred_x, cursor_y); view->file_data.cursor =
view_compute_cursor_from_xy(view, view->file_data.preferred_x, cursor_y);
} }
} }
gui_begin_scrollable(target, view->showing_ui, view->recent->scroll, delta); gui_begin_scrollable(target, view->showing_ui, view->recent->scroll,
delta, show_scrollbar);
gui_do_file(target); gui_do_file(target);
gui_end_scrollable(target); gui_end_scrollable(target);
} }
@ -3519,7 +3524,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region); gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region);
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll,
9.f * view->font_height, show_scrollbar);
{ {
i32 count = models->styles.count; i32 count = models->styles.count;
@ -3592,7 +3598,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region); gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region);
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll,
9.f * view->font_height, show_scrollbar);
i32 next_color_editing = view->current_color_editing; i32 next_color_editing = view->current_color_editing;
@ -3722,8 +3729,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
if (gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region)){ if (gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region)){
snap_into_view = 1; snap_into_view = 1;
} }
gui_begin_scrollable(target, view->showing_ui, gui_begin_scrollable(target, view->showing_ui, view->gui_scroll,
view->gui_scroll, 9.f * view->font_height); 9.f * view->font_height, show_scrollbar);
id.id[0] = (u64)(hdir) + 1; id.id[0] = (u64)(hdir) + 1;
@ -3803,10 +3810,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_do_text_field(target, message, view->dest); gui_do_text_field(target, message, view->dest);
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
if (gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region)){ if (gui_get_scroll_vars(target, view->showing_ui,
&view->gui_scroll, &view->scroll_region)){
snap_into_view = 1; snap_into_view = 1;
} }
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll,
9.f * view->font_height, show_scrollbar);
id.id[0] = (u64)(working_set) + 1; id.id[0] = (u64)(working_set) + 1;
if (gui_begin_list(target, id, view->list_i, if (gui_begin_list(target, id, view->list_i,
@ -3959,7 +3968,7 @@ view_get_scroll_y(View *view){
internal void internal void
click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input, click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input,
GUI_Interactive *b, b32 *is_animating){ GUI_Interactive *b, b32 *is_animating){
i32 mx = user_input->mouse.x; i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y; i32 my = user_input->mouse.y;
@ -4134,14 +4143,22 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
if (gui_id_eq(target->mouse_hot, id)){ if (gui_id_eq(target->mouse_hot, id)){
v = unlerp(gui_session.scroll_top, (f32)my, gui_session.scroll_bottom); v = unlerp(gui_session.scroll_top, (f32)my,
gui_session.scroll_bottom);
if (v < 0) v = 0; if (v < 0) v = 0;
if (v > 1.f) v = 1.f; if (v > 1.f) v = 1.f;
target->scroll_updated.target_y = lerp(target->scroll_updated.min_y, v, target->scroll_updated.max_y); target->scroll_updated.target_y =
lerp(target->scroll_updated.min_y, v,
target->scroll_updated.max_y);
gui_activate_scrolling(target); gui_activate_scrolling(target);
is_animating = 1; is_animating = 1;
} }
}
// NOTE(allen): NO BREAK HERE!!
case guicom_scrollable_invisible:
{
if (user_input->mouse.wheel != 0){ if (user_input->mouse.wheel != 0){
target->scroll_updated.target_y += user_input->mouse.wheel*target->delta; target->scroll_updated.target_y += user_input->mouse.wheel*target->delta;
@ -4852,7 +4869,7 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
draw_button(gui_target, target, view, gui_session.rect, b->id, t); draw_button(gui_target, target, view, gui_session.rect, b->id, t);
}break; }break;
case guicom_scrollable: case guicom_scrollable_bar:
{ {
Models *models = view->models; Models *models = view->models;
Style *style = main_style(models); Style *style = main_style(models);
@ -4914,13 +4931,12 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
}break; }break;
case guicom_begin_scrollable_section: case guicom_begin_scrollable_section:
clip_rect.x1 -= gui_session.scroll_bar_w; clip_rect = gui_target->region_updated;
draw_push_clip(target, clip_rect); draw_push_clip(target, clip_rect);
break; break;
case guicom_end_scrollable_section: case guicom_end_scrollable_section:
clip_rect.x1 += gui_session.scroll_bar_w; clip_rect = draw_pop_clip(target);
draw_pop_clip(target);
break; break;
} }
} }

View File

@ -208,9 +208,11 @@ enum GUI_Command_Type{
guicom_fixed_option_checkbox, guicom_fixed_option_checkbox,
guicom_style_preview, guicom_style_preview,
guicom_scrollable, guicom_scrollable,
guicom_scrollable_bar,
guicom_scrollable_top, guicom_scrollable_top,
guicom_scrollable_slider, guicom_scrollable_slider,
guicom_scrollable_bottom, guicom_scrollable_bottom,
guicom_scrollable_invisible,
guicom_begin_scrollable_section, guicom_begin_scrollable_section,
guicom_end_scrollable_section, guicom_end_scrollable_section,
}; };
@ -706,7 +708,8 @@ gui_post_scroll_vars(GUI_Target *target, GUI_Scroll_Vars *vars_in){
} }
internal void internal void
gui_begin_scrollable(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars scroll_vars, f32 delta){ gui_begin_scrollable(GUI_Target *target, u32 scroll_id,
GUI_Scroll_Vars scroll_vars, f32 delta, b32 show_bar){
GUI_Header *h; GUI_Header *h;
gui_begin_serial_section(target); gui_begin_serial_section(target);
@ -718,9 +721,15 @@ gui_begin_scrollable(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars scroll_v
target->scroll_updated = scroll_vars; target->scroll_updated = scroll_vars;
target->scroll_id = scroll_id; target->scroll_id = scroll_id;
gui_push_simple_command(target, guicom_scrollable_top); if (show_bar){
gui_push_simple_command(target, guicom_scrollable_slider); gui_push_simple_command(target, guicom_scrollable_bar);
gui_push_simple_command(target, guicom_scrollable_bottom); gui_push_simple_command(target, guicom_scrollable_top);
gui_push_simple_command(target, guicom_scrollable_slider);
gui_push_simple_command(target, guicom_scrollable_bottom);
}
else{
gui_push_simple_command(target, guicom_scrollable_invisible);
}
gui_push_simple_command(target, guicom_begin_scrollable_section); gui_push_simple_command(target, guicom_begin_scrollable_section);
} }
@ -756,10 +765,10 @@ struct GUI_Session{
i32 clip_y; i32 clip_y;
i32 line_height; i32 line_height;
i32 scroll_bar_w;
b32 is_scrollable; b32 is_scrollable;
i32 scrollable_items_bottom; i32 scrollable_items_bottom;
i32_Rect scroll_region;
i32_Rect scroll_rect; i32_Rect scroll_rect;
f32 scroll_top, scroll_bottom; f32 scroll_top, scroll_bottom;
@ -805,7 +814,6 @@ gui_session_init(GUI_Session *session, GUI_Target *target,
*session = gui_session_zero(); *session = gui_session_zero();
session->full_rect = full_rect; session->full_rect = full_rect;
session->line_height = line_height; session->line_height = line_height;
session->scroll_bar_w = GUIScrollbarWidth;
section = &session->sections[0]; section = &session->sections[0];
section->v = full_rect.y0; section->v = full_rect.y0;
@ -827,15 +835,18 @@ gui_section_end_item(GUI_Section *section, i32 v){
inline i32_Rect inline i32_Rect
gui_layout_top_bottom(GUI_Session *session, i32 y0, i32 y1){ gui_layout_top_bottom(GUI_Session *session, i32 y0, i32 y1){
i32_Rect rect; i32_Rect rect = {0};
i32_Rect full_rect = session->full_rect;
rect.y0 = y0; rect.y0 = y0;
rect.y1 = y1; rect.y1 = y1;
rect.x0 = full_rect.x0; rect.x0 = session->full_rect.x0;
rect.x1 = full_rect.x1; rect.x1 = session->full_rect.x1;
if (session->is_scrollable){ if (session->is_scrollable){
rect.x1 -= session->scroll_bar_w; rect.x0 = session->scroll_region.x0;
rect.x1 = session->scroll_region.x1;
} }
return(rect); return(rect);
} }
@ -1117,22 +1128,40 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
case guicom_scrollable: case guicom_scrollable:
Assert(session->is_scrollable == 0); Assert(session->is_scrollable == 0);
Assert(!section->overlapped); Assert(!section->overlapped);
session->is_scrollable = 1;
always_give_to_user = 1;
{
i32_Rect scrollable_rect = {0};
scrollable_rect.x0 = session->full_rect.x0;
scrollable_rect.x1 = session->full_rect.x1;
scrollable_rect.y0 = y;
scrollable_rect.y1 = session->full_rect.y1;
target->region_updated = scrollable_rect;
session->scroll_region = scrollable_rect;
}
break;
case guicom_scrollable_bar:
Assert(session->is_scrollable);
Assert(!section->overlapped);
give_to_user = 1; give_to_user = 1;
rect.x1 = session->full_rect.x1; rect.x1 = session->full_rect.x1;
rect.x0 = rect.x1 - session->scroll_bar_w; rect.x0 = rect.x1 - GUIScrollbarWidth;
rect.y0 = y; rect.y0 = y;
rect.y1 = session->full_rect.y1; rect.y1 = session->full_rect.y1;
session->scroll_rect = rect; session->scroll_rect = rect;
session->is_scrollable = 1;
{ {
i32_Rect scrollable_rect; i32_Rect scrollable_rect = {0};
scrollable_rect.x0 = session->full_rect.x0; scrollable_rect.x0 = session->full_rect.x0;
scrollable_rect.x1 = rect.x0; scrollable_rect.x1 = rect.x0;
scrollable_rect.y0 = rect.y0; scrollable_rect.y0 = y;
scrollable_rect.y1 = rect.y1; scrollable_rect.y1 = session->full_rect.y1;
target->region_updated = scrollable_rect; target->region_updated = scrollable_rect;
session->scroll_region = scrollable_rect;
} }
scroll_v = 0;
break; break;
case guicom_scrollable_top: case guicom_scrollable_top:
@ -1159,6 +1188,12 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
scroll_v = 0; scroll_v = 0;
break; break;
case guicom_scrollable_invisible:
Assert(session->is_scrollable);
Assert(!section->overlapped);
always_give_to_user = 1;
break;
case guicom_scrollable_bottom: case guicom_scrollable_bottom:
Assert(session->is_scrollable); Assert(session->is_scrollable);
Assert(!section->overlapped); Assert(!section->overlapped);

View File

@ -86,14 +86,18 @@ draw_push_clip(Render_Target *target, i32_Rect clip_box){
draw_push_piece_clip(target, clip_box); draw_push_piece_clip(target, clip_box);
} }
internal void internal i32_Rect
draw_pop_clip(Render_Target *target){ draw_pop_clip(Render_Target *target){
i32_Rect clip_box; i32_Rect result = {0};
i32_Rect clip_box = {0};
Assert(target->clip_top > 0); Assert(target->clip_top > 0);
result = target->clip_boxes[target->clip_top];
--target->clip_top; --target->clip_top;
clip_box = target->clip_boxes[target->clip_top]; clip_box = target->clip_boxes[target->clip_top];
draw_push_piece_clip(target, clip_box); draw_push_piece_clip(target, clip_box);
return(result);
} }
#define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s) #define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s)

View File

@ -105,7 +105,7 @@ struct Render_Target;
#define Draw_Push_Clip_Sig(name) void name(Render_Target *target, i32_Rect clip_box) #define Draw_Push_Clip_Sig(name) void name(Render_Target *target, i32_Rect clip_box)
typedef Draw_Push_Clip_Sig(Draw_Push_Clip); typedef Draw_Push_Clip_Sig(Draw_Push_Clip);
#define Draw_Pop_Clip_Sig(name) void name(Render_Target *target) #define Draw_Pop_Clip_Sig(name) i32_Rect name(Render_Target *target)
typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip); typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip);
#define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece) #define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece)

View File

@ -14,9 +14,10 @@ draw_push_clip(Render_Target *target, i32_Rect clip_box){
target->push_clip(target, clip_box); target->push_clip(target, clip_box);
} }
inline void inline i32_Rect
draw_pop_clip(Render_Target *target){ draw_pop_clip(Render_Target *target){
target->pop_clip(target); i32_Rect result = target->pop_clip(target);
return(result);
} }
inline void inline void