list index position is now tied to view

master
Allen Webster 2016-05-18 23:13:21 -04:00
parent 6b6cb0b3ab
commit 7b30e60c0d
3 changed files with 139 additions and 86 deletions

View File

@ -3020,7 +3020,6 @@ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active)
f32 cursor_y = view_get_cursor_y(view); f32 cursor_y = view_get_cursor_y(view);
f32 cursor_x = view_get_cursor_x(view); f32 cursor_x = view_get_cursor_x(view);
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated; GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated;
f32 target_y = scroll_vars.target_y; f32 target_y = scroll_vars.target_y;
f32 target_x = scroll_vars.target_x; f32 target_x = scroll_vars.target_x;
@ -3669,6 +3668,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
GUI_Item_Update update = {0}; GUI_Item_Update update = {0};
Hot_Directory *hdir = &models->hot_directory; Hot_Directory *hdir = &models->hot_directory;
b32 do_new_directory = 0; b32 do_new_directory = 0;
b32 snap_into_view = 0;
i32 i = 0; i32 i = 0;
{ {
@ -3692,13 +3692,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_do_text_field(target, message, hdir->string); gui_do_text_field(target, message, hdir->string);
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll); if (gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll)){
snap_into_view = 1;
}
gui_begin_scrollable(target, view->showing_ui, gui_begin_scrollable(target, view->showing_ui,
view->gui_scroll, 9.f * view->font_height); view->gui_scroll, 9.f * view->font_height);
id.id[0] = (u64)(hdir) + 1; id.id[0] = (u64)(hdir) + 1;
if (gui_begin_list(target, id, view->list_i, 0, &update)){ if (gui_begin_list(target, id, view->list_i, 0, snap_into_view, &update)){
i32 *list_i = &view->list_i; i32 *list_i = &view->list_i;
if (update.has_adjustment){ if (update.has_adjustment){
@ -3737,7 +3739,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
gui_rollback(target, &update); gui_rollback(target, &update);
gui_begin_list(target, id, *list_i, indirectly_activate, 0); gui_begin_list(target, id, *list_i, indirectly_activate, 0, 0);
#if 0 #if 0
gui_standard_list(target, id, &keys, &view->list_i, &update); gui_standard_list(target, id, &keys, &view->list_i, &update);
@ -3817,7 +3819,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
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);
id.id[0] = (u64)(working_set) + 1; id.id[0] = (u64)(working_set) + 1;
if (gui_begin_list(target, id, view->list_i, 0, &update)){ if (gui_begin_list(target, id, view->list_i, 0, 0, &update)){
gui_standard_list(target, id, &keys, &view->list_i, &update); gui_standard_list(target, id, &keys, &view->list_i, &update);
} }
@ -3980,7 +3982,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
GUI_Target *target = &view->gui_target; GUI_Target *target = &view->gui_target;
GUI_Interpret_Result interpret_result = {0}; GUI_Interpret_Result interpret_result = {0};
gui_session_init(&gui_session, rect, view->font_height); gui_session_init(&gui_session, target, rect, view->font_height);
target->active = gui_id_zero(); target->active = gui_id_zero();
@ -4170,8 +4172,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = 1; if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = 1;
if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = 1; if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = 1;
if (view->models->scroll_rule( if (view->models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y,
scroll_vars.target_x, scroll_vars.target_y,
&scroll_vars.scroll_x, &scroll_vars.scroll_y, &scroll_vars.scroll_x, &scroll_vars.scroll_y,
(view->id) + 1, is_new_target)){ (view->id) + 1, is_new_target)){
is_animating = 1; is_animating = 1;
@ -4696,7 +4697,7 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
f32 v; f32 v;
gui_session_init(&gui_session, rect, view->font_height); gui_session_init(&gui_session, gui_target, rect, view->font_height);
v = view_get_scroll_y(view); v = view_get_scroll_y(view);

View File

@ -152,6 +152,8 @@ struct GUI_Target{
i32 list_max; i32 list_max;
b32 has_list_index_position; b32 has_list_index_position;
i32_Rect list_index_position; i32_Rect list_index_position;
i32 list_view_min;
i32 list_view_max;
f32 delta; f32 delta;
u32 scroll_id; u32 scroll_id;
@ -486,9 +488,14 @@ gui_do_font_button(GUI_Target *target, GUI_id id, i16 font_id, String text){
} }
internal b32 internal b32
gui_begin_list(GUI_Target *target, GUI_id id, i32 list_i, b32 activate_item, GUI_Item_Update *update){ gui_begin_list(GUI_Target *target, GUI_id id, i32 list_i,
b32 activate_item, b32 snap_into_view, GUI_Item_Update *update){
b32 result = 0; b32 result = 0;
b32 active = 0; b32 active = 0;
i32 list_min = 0;
i32 list_max = target->list_max;
GUI_Interactive *b = gui_push_button_command(target, guicom_begin_list, id); GUI_Interactive *b = gui_push_button_command(target, guicom_begin_list, id);
GUI_Header *h = (GUI_Header*)b; GUI_Header *h = (GUI_Header*)b;
gui_push_item(target, h, &list_i, sizeof(list_i)); gui_push_item(target, h, &list_i, sizeof(list_i));
@ -500,13 +507,26 @@ gui_begin_list(GUI_Target *target, GUI_id id, i32 list_i, b32 activate_item, GUI
result = 1; result = 1;
} }
if (snap_into_view){
if (target->list_view_min > list_min){
list_min = target->list_view_min;
}
if (target->list_view_max < list_max){
list_max = target->list_view_max;
}
}
if (list_i < list_min || list_i >= list_max){
result = 1;
}
if (result){ if (result){
gui_fill_update(update, target, h); gui_fill_update(update, target, h);
if (list_i < 0){ if (list_i < list_min){
gui_update_adjustment(update, 0); gui_update_adjustment(update, list_min);
} }
else if (list_i >= target->list_max){ else if (list_i >= list_max){
gui_update_adjustment(update, target->list_max - 1); gui_update_adjustment(update, list_max - 1);
} }
if (target->has_list_index_position){ if (target->has_list_index_position){
gui_update_position(update, target->list_index_position); gui_update_position(update, target->list_index_position);
@ -524,7 +544,8 @@ gui_end_list(GUI_Target *target){
} }
internal b32 internal b32
gui_do_file_option(GUI_Target *target, GUI_id id, String filename, b32 is_folder, String message){ gui_do_file_option(GUI_Target *target, GUI_id id, String filename,
b32 is_folder, String message){
b32 result = 0; b32 result = 0;
GUI_Interactive *b = gui_push_button_command(target, guicom_file_option, id); GUI_Interactive *b = gui_push_button_command(target, guicom_file_option, id);
GUI_Header *h = (GUI_Header*)b; GUI_Header *h = (GUI_Header*)b;
@ -668,7 +689,7 @@ gui_get_scroll_vars(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars *vars_out
} }
internal GUI_Scroll_Vars internal GUI_Scroll_Vars
gui_get_scroll_vars(GUI_Target *target){ gui_current_scroll_vars(GUI_Target *target){
GUI_Scroll_Vars vars = target->scroll_updated; GUI_Scroll_Vars vars = target->scroll_updated;
return(vars); return(vars);
} }
@ -775,7 +796,8 @@ gui_session_zero(){
} }
internal void internal void
gui_session_init(GUI_Session *session, i32_Rect full_rect, i32 line_height){ gui_session_init(GUI_Session *session, GUI_Target *target,
i32_Rect full_rect, i32 line_height){
GUI_Section *section; GUI_Section *section;
*session = gui_session_zero(); *session = gui_session_zero();
@ -786,6 +808,9 @@ gui_session_init(GUI_Session *session, i32_Rect full_rect, i32 line_height){
section = &session->sections[0]; section = &session->sections[0];
section->v = full_rect.y0; section->v = full_rect.y0;
section->max_v = full_rect.y0; section->max_v = full_rect.y0;
target->list_view_min = max_i32;
target->list_view_max = min_i32;
} }
internal void internal void
@ -940,11 +965,13 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
b32 give_to_user = 0; b32 give_to_user = 0;
b32 always_give_to_user = 0; b32 always_give_to_user = 0;
b32 do_layout = 1; b32 do_layout = 1;
b32 is_list_item = 0;
i32_Rect rect = {0}; i32_Rect rect = {0};
i32 y = 0; i32 y = 0;
i32 end_v = -1; i32 end_v = -1;
f32 lerp_space_scroll_v = 0; f32 lerp_space_scroll_v = 0;
i32 scroll_v = (i32)target->scroll_original.scroll_y; i32 scroll_v = (i32)target->scroll_original.scroll_y;
i32 target_v = (i32)target->scroll_updated.target_y;
Assert(session->t < ArrayCount(session->sections)); Assert(session->t < ArrayCount(session->sections));
section = session->sections + session->t; section = session->sections + session->t;
@ -1053,6 +1080,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
rect = gui_layout_fixed_h(session, y, session->line_height * 2); rect = gui_layout_fixed_h(session, y, session->line_height * 2);
end_v = rect.y1; end_v = rect.y1;
end_section = section; end_section = section;
is_list_item = 1;
if (session->list.in_list){ if (session->list.in_list){
if (session->list.auto_hot == session->list.index){ if (session->list.auto_hot == session->list.index){
@ -1118,13 +1146,14 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
Assert(!section->overlapped); Assert(!section->overlapped);
give_to_user = 1; give_to_user = 1;
lerp_space_scroll_v = unlerp( lerp_space_scroll_v =
(f32)target->scroll_original.min_y, unlerp((f32)target->scroll_original.min_y,
(f32)target->scroll_original.target_y, (f32)target->scroll_original.target_y,
(f32)target->scroll_original.max_y); (f32)target->scroll_original.max_y);
gui_scrollbar_slider(session->scroll_rect, &rect, lerp_space_scroll_v, gui_scrollbar_slider(session->scroll_rect, &rect, lerp_space_scroll_v,
&session->scroll_top, &session->scroll_bottom, target->scroll_original.min_y, target->scroll_original.max_y); &session->scroll_top, &session->scroll_bottom,
target->scroll_original.min_y, target->scroll_original.max_y);
scroll_v = 0; scroll_v = 0;
break; break;
@ -1145,8 +1174,12 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
case guicom_end_scrollable_section: case guicom_end_scrollable_section:
always_give_to_user = 1; always_give_to_user = 1;
session->suggested_min_y = -(f32)(gui_session_get_eclipsed_y(session) - gui_session_get_current_top(session)); session->suggested_min_y =
session->suggested_max_y = (f32)(session->scrollable_items_bottom - session->full_rect.y1 * .5f); -(f32)(gui_session_get_eclipsed_y(session) -
gui_session_get_current_top(session));
session->suggested_max_y =
(f32)(session->scrollable_items_bottom -
session->full_rect.y1 * .5f);
if (session->suggested_max_y < 0){ if (session->suggested_max_y < 0){
session->suggested_max_y = 0; session->suggested_max_y = 0;
} }
@ -1154,9 +1187,25 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
} }
if (do_layout){ if (do_layout){
if (session->list.in_list && is_list_item){
i32 list_i = session->list.index - 1;
i32_Rect region = target->scroll_updated.region;
if (rect.y0 - target_v >= region.y0 &&
rect.y1 - target_v <= region.y1){
if (list_i < target->list_view_min){
target->list_view_min = list_i;
}
if (list_i+1 > target->list_view_max){
target->list_view_max = list_i+1;
}
}
}
if (give_to_user){ if (give_to_user){
if (session->is_scrollable){ if (session->is_scrollable){
session->scrollable_items_bottom = Max(session->scrollable_items_bottom, rect.y1); session->scrollable_items_bottom =
Max(session->scrollable_items_bottom, rect.y1);
} }
rect.y0 -= scroll_v; rect.y0 -= scroll_v;
@ -1215,7 +1264,7 @@ gui_standard_list(GUI_Target *target, GUI_id id,
} }
gui_rollback(target, update); gui_rollback(target, update);
gui_begin_list(target, id, *list_i, indirectly_activate, 0); gui_begin_list(target, id, *list_i, indirectly_activate, 0, 0);
} }
struct GUI_View_Jump{ struct GUI_View_Jump{
@ -1234,7 +1283,7 @@ gui_compute_view_jump(GUI_Scroll_Vars scroll, i32_Rect position){
internal void internal void
gui_do_jump(GUI_Target *target, GUI_View_Jump jump){ gui_do_jump(GUI_Target *target, GUI_View_Jump jump){
GUI_Scroll_Vars vars = gui_get_scroll_vars(target); GUI_Scroll_Vars vars = gui_current_scroll_vars(target);
if (vars.target_y < jump.view_min){ if (vars.target_y < jump.view_min){
vars.target_y = jump.view_min; vars.target_y = jump.view_min;
gui_post_scroll_vars(target, &vars); gui_post_scroll_vars(target, &vars);

View File

@ -33,6 +33,9 @@ if %ERRORLEVEL% neq 0 (set FirstError=1)
cl %OPTS% %INCLUDES% %DEFINES% ..\code\win32_4ed.cpp %LIBS% %ICON% %* /Fe4ed cl %OPTS% %INCLUDES% %DEFINES% ..\code\win32_4ed.cpp %LIBS% %ICON% %* /Fe4ed
if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (set FirstError=1)
call "print_size.bat" 4ed_app.dll
call "print_size.bat" 4ed.exe
popd popd
call "ctime" -end 4ed_data.ctm %FirstError% call "ctime" -end 4ed_data.ctm %FirstError%