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);
} }
@ -3455,77 +3460,78 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
String empty_string = {0}; String empty_string = {0};
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Menu; id.id[1] = VUI_Menu;
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
id.id[0] = 0; id.id[0] = 0;
message = make_lit_string("Theme"); message = make_lit_string("Theme");
if (gui_do_fixed_option(target, id, message, 0)){ if (gui_do_fixed_option(target, id, message, 0)){
view_show_theme(view, view->map); view_show_theme(view, view->map);
} }
id.id[0] = 1; id.id[0] = 1;
message = make_lit_string("Config"); message = make_lit_string("Config");
if (gui_do_fixed_option(target, id, message, 0)){ if (gui_do_fixed_option(target, id, message, 0)){
view_show_config(view, view->map); view_show_config(view, view->map);
} }
}break; }break;
case VUI_Config: case VUI_Config:
{ {
String message = make_lit_string("Config"); String message = make_lit_string("Config");
String empty_string = {0}; String empty_string = {0};
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Config; id.id[1] = VUI_Config;
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
id.id[0] = 0; id.id[0] = 0;
message = make_lit_string("Left Ctrl + Left Alt = AltGr"); message = make_lit_string("Left Ctrl + Left Alt = AltGr");
if (gui_do_fixed_option_checkbox(target, id, message, 0, (b8)models->settings.lctrl_lalt_is_altgr)){ if (gui_do_fixed_option_checkbox(target, id, message, 0, (b8)models->settings.lctrl_lalt_is_altgr)){
models->settings.lctrl_lalt_is_altgr = !models->settings.lctrl_lalt_is_altgr; models->settings.lctrl_lalt_is_altgr = !models->settings.lctrl_lalt_is_altgr;
} }
}break; }break;
case VUI_Theme: case VUI_Theme:
{ {
if (view != active_view){ if (view != active_view){
view->hot_file_view = active_view; view->hot_file_view = active_view;
} }
String message = {0}; String message = {0};
String empty_string = {0}; String empty_string = {0};
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Theme + ((u64)view->color_mode << 32); id.id[1] = VUI_Theme + ((u64)view->color_mode << 32);
switch (view->color_mode){ switch (view->color_mode){
case CV_Mode_Library: case CV_Mode_Library:
message = make_lit_string("Current Theme - Click to Edit"); message = make_lit_string("Current Theme - Click to Edit");
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
id.id[0] = (u64)(main_style(models)); id.id[0] = (u64)(main_style(models));
if (gui_do_style_preview(target, id, 0)){ if (gui_do_style_preview(target, id, 0)){
view->color_mode = CV_Mode_Adjusting; view->color_mode = CV_Mode_Adjusting;
} }
message = make_lit_string("Set Font"); message = make_lit_string("Set Font");
id.id[0] = (u64)(&models->global_font); id.id[0] = (u64)(&models->global_font);
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Font; view->color_mode = CV_Mode_Font;
} }
message = make_lit_string("Theme Library - Click to Select"); message = make_lit_string("Theme Library - Click to Select");
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
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;
Style *style; Style *style;
i32 i; i32 i;
for (i = 1; i < count; ++i, ++style){ for (i = 1; i < count; ++i, ++style){
style = get_style(models, i); style = get_style(models, i);
id.id[0] = (u64)(style); id.id[0] = (u64)(style);
@ -3534,7 +3540,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
gui_end_scrollable(target); gui_end_scrollable(target);
break; break;
@ -3542,20 +3548,20 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
{ {
Font_Set *font_set = models->font_set; Font_Set *font_set = models->font_set;
Font_Info *info = 0; Font_Info *info = 0;
i16 i = 1, count = (i16)models->font_set->count + 1; i16 i = 1, count = (i16)models->font_set->count + 1;
i16 font_id = 0, new_font_id = 0; i16 font_id = 0, new_font_id = 0;
String message = make_lit_string("Back"); String message = make_lit_string("Back");
id.id[0] = 0; id.id[0] = 0;
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
} }
font_id = models->global_font.font_id; font_id = models->global_font.font_id;
new_font_id = font_id; new_font_id = font_id;
for (i = 1; i < count; ++i){ for (i = 1; i < count; ++i){
info = get_font_info(font_set, i); info = get_font_info(font_set, i);
id.id[0] = (u64)i; id.id[0] = (u64)i;
@ -3575,16 +3581,16 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
models->global_font.font_id = (i16)(new_font_id); models->global_font.font_id = (i16)(new_font_id);
}break; }break;
case CV_Mode_Adjusting: case CV_Mode_Adjusting:
{ {
Style *style = main_style(models); Style *style = main_style(models);
u32 *edit_color = 0; u32 *edit_color = 0;
u32 *fore = 0, *back = 0; u32 *fore = 0, *back = 0;
i32 i = 0; i32 i = 0;
String message = make_lit_string("Back"); String message = make_lit_string("Back");
id.id[0] = 0; id.id[0] = 0;
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
@ -3592,50 +3598,51 @@ 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;
for (i = 0; i < ArrayCount(colors_to_edit); ++i){ for (i = 0; i < ArrayCount(colors_to_edit); ++i){
edit_color = style_index_by_tag(&style->main, colors_to_edit[i].target); edit_color = style_index_by_tag(&style->main, colors_to_edit[i].target);
id.id[0] = (u64)(edit_color); id.id[0] = (u64)(edit_color);
fore = style_index_by_tag(&style->main, colors_to_edit[i].fore); fore = style_index_by_tag(&style->main, colors_to_edit[i].fore);
back = style_index_by_tag(&style->main, colors_to_edit[i].back); back = style_index_by_tag(&style->main, colors_to_edit[i].back);
if (gui_do_color_button(target, id, *fore, *back, colors_to_edit[i].text)){ if (gui_do_color_button(target, id, *fore, *back, colors_to_edit[i].text)){
next_color_editing = i; next_color_editing = i;
view->color_cursor = 0; view->color_cursor = 0;
} }
if (view->current_color_editing == i){ if (view->current_color_editing == i){
GUI_Item_Update update = {0}; GUI_Item_Update update = {0};
char text_space[7]; char text_space[7];
String text = make_fixed_width_string(text_space); String text = make_fixed_width_string(text_space);
color_to_hexstr(*edit_color, &text); color_to_hexstr(*edit_color, &text);
if (gui_do_text_with_cursor(target, view->color_cursor, text, &update)){ if (gui_do_text_with_cursor(target, view->color_cursor, text, &update)){
b32 r = 0; b32 r = 0;
i32 j = 0; i32 j = 0;
for (j = 0; j < keys.count; ++j){ for (j = 0; j < keys.count; ++j){
i16 key = keys.keys[j].keycode; i16 key = keys.keys[j].keycode;
switch (key){ switch (key){
case key_left: --view->color_cursor; r = 1; break; case key_left: --view->color_cursor; r = 1; break;
case key_right: ++view->color_cursor; r = 1; break; case key_right: ++view->color_cursor; r = 1; break;
case key_up: case key_up:
if (next_color_editing > 0){ if (next_color_editing > 0){
--next_color_editing; --next_color_editing;
} }
break; break;
case key_down: case key_down:
if (next_color_editing <= ArrayCount(colors_to_edit)-1){ if (next_color_editing <= ArrayCount(colors_to_edit)-1){
++next_color_editing; ++next_color_editing;
} }
break; break;
default: default:
if ((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f') || (key >= 'A' && key <= 'F')){ if ((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f') || (key >= 'A' && key <= 'F')){
text.str[view->color_cursor] = (char)key; text.str[view->color_cursor] = (char)key;
@ -3643,11 +3650,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
break; break;
} }
if (view->color_cursor < 0) view->color_cursor = 0; if (view->color_cursor < 0) view->color_cursor = 0;
if (view->color_cursor >= 6) view->color_cursor = 5; if (view->color_cursor >= 6) view->color_cursor = 5;
} }
if (r){ if (r){
hexstr_to_color(text, edit_color); hexstr_to_color(text, edit_color);
gui_rollback(target, &update); gui_rollback(target, &update);
@ -3656,28 +3663,28 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
if (view->current_color_editing != next_color_editing){ if (view->current_color_editing != next_color_editing){
view->current_color_editing = next_color_editing; view->current_color_editing = next_color_editing;
view->color_cursor = 0; view->color_cursor = 0;
} }
gui_end_scrollable(target); gui_end_scrollable(target);
}break; }break;
} }
}break; }break;
case VUI_Interactive: case VUI_Interactive:
{ {
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Interactive + ((u64)view->interaction << 32); id.id[1] = VUI_Interactive + ((u64)view->interaction << 32);
switch (view->interaction){ switch (view->interaction){
case IInt_Sys_File_List: case IInt_Sys_File_List:
{ {
b32 use_item_in_list = 1; b32 use_item_in_list = 1;
b32 activate_directly = 0; b32 activate_directly = 0;
if (view->action == IAct_Save_As || view->action == IAct_New){ if (view->action == IAct_Save_As || view->action == IAct_New){
use_item_in_list = 0; use_item_in_list = 0;
} }
@ -3702,7 +3709,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
Single_Line_Input_Step step = {0}; Single_Line_Input_Step step = {0};
Key_Event_Data key = {0}; Key_Event_Data key = {0};
i32 i; i32 i;
for (i = 0; i < keys.count; ++i){ for (i = 0; i < keys.count; ++i){
key = get_single_key(&keys, i); key = get_single_key(&keys, i);
step = app_single_file_input_step(system, &models->working_set, key, step = app_single_file_input_step(system, &models->working_set, key,
@ -3715,15 +3722,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;
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;
@ -3759,11 +3766,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
if (activate_directly){ if (activate_directly){
interactive_view_complete(view, hdir->string, 0); interactive_view_complete(view, hdir->string, 0);
} }
if (do_new_directory){ if (do_new_directory){
hot_directory_reload(system, hdir, &models->working_set); hot_directory_reload(system, hdir, &models->working_set);
} }
gui_end_scrollable(target); gui_end_scrollable(target);
}break; }break;
@ -3772,19 +3779,19 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
b32 snap_into_view = 0; b32 snap_into_view = 0;
persist String message_unsaved = make_lit_string(" *"); persist String message_unsaved = make_lit_string(" *");
persist String message_unsynced = make_lit_string(" !"); persist String message_unsynced = make_lit_string(" !");
String message = {0}; String message = {0};
switch (view->action){ switch (view->action){
case IAct_Switch: message = make_lit_string("Switch: "); break; case IAct_Switch: message = make_lit_string("Switch: "); break;
case IAct_Kill: message = make_lit_string("Kill: "); break; case IAct_Kill: message = make_lit_string("Kill: "); break;
} }
Absolutes absolutes; Absolutes absolutes;
Editing_File *file; Editing_File *file;
Working_Set *working_set = &models->working_set; Working_Set *working_set = &models->working_set;
Editing_Layout *layout = &models->layout; Editing_Layout *layout = &models->layout;
GUI_Item_Update update = {0}; GUI_Item_Update update = {0};
{ {
Single_Line_Input_Step step; Single_Line_Input_Step step;
Key_Event_Data key; Key_Event_Data key;
@ -3797,24 +3804,26 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
get_absolutes(view->dest, &absolutes, 1, 1); get_absolutes(view->dest, &absolutes, 1, 1);
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,
0, snap_into_view, &update)){ 0, snap_into_view, &update)){
gui_standard_list(target, id, view->scroll_region, gui_standard_list(target, id, view->scroll_region,
&keys, &view->list_i, &update); &keys, &view->list_i, &update);
} }
{ {
Partition *part = &models->mem.part; Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part); Temp_Memory temp = begin_temp_memory(part);
@ -3822,15 +3831,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
Editing_File **reserved_files = 0; Editing_File **reserved_files = 0;
i32 reserved_top = 0, i = 0; i32 reserved_top = 0, i = 0;
View_Iter iter = {0}; View_Iter iter = {0};
partition_align(part, sizeof(i32)); partition_align(part, sizeof(i32));
reserved_files = (Editing_File**)partition_current(part); reserved_files = (Editing_File**)partition_current(part);
used_nodes = &working_set->used_sentinel; used_nodes = &working_set->used_sentinel;
for (dll_items(node, used_nodes)){ for (dll_items(node, used_nodes)){
file = (Editing_File*)node; file = (Editing_File*)node;
Assert(!file->state.is_dummy); Assert(!file->state.is_dummy);
if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){ if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){
iter = file_view_iter_init(layout, file, 0); iter = file_view_iter_init(layout, file, 0);
if (file_view_iter_good(iter)){ if (file_view_iter_good(iter)){
@ -3846,7 +3855,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break; case SYNC_UNSAVED: message = message_unsaved; break;
} }
id.id[0] = (u64)(file); id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ if (gui_do_file_option(target, id, file->name.live_name, 0, message)){
interactive_view_complete(view, file->name.live_name, 0); interactive_view_complete(view, file->name.live_name, 0);
@ -3855,39 +3864,39 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
for (i = 0; i < reserved_top; ++i){ for (i = 0; i < reserved_top; ++i){
file = reserved_files[i]; file = reserved_files[i];
message = string_zero(); message = string_zero();
switch (buffer_get_sync(file)){ switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break; case SYNC_UNSAVED: message = message_unsaved; break;
} }
id.id[0] = (u64)(file); id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ if (gui_do_file_option(target, id, file->name.live_name, 0, message)){
interactive_view_complete(view, file->name.live_name, 0); interactive_view_complete(view, file->name.live_name, 0);
} }
} }
end_temp_memory(temp); end_temp_memory(temp);
} }
gui_end_list(target); gui_end_list(target);
gui_end_scrollable(target); gui_end_scrollable(target);
}break; }break;
case IInt_Sure_To_Close: case IInt_Sure_To_Close:
{ {
i32 action = -1; i32 action = -1;
String empty_str = {0}; String empty_str = {0};
String message = make_lit_string("There is one or more files unsaved changes, close anyway?"); String message = make_lit_string("There is one or more files unsaved changes, close anyway?");
gui_do_text_field(target, message, empty_str); gui_do_text_field(target, message, empty_str);
id.id[0] = (u64)('y'); id.id[0] = (u64)('y');
message = make_lit_string("(Y)es"); message = make_lit_string("(Y)es");
if (gui_do_fixed_option(target, id, message, 'y')){ if (gui_do_fixed_option(target, id, message, 'y')){
@ -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;
@ -4008,16 +4017,16 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
Input_Summary *user_input){ Input_Summary *user_input){
b32 is_animating = 0; b32 is_animating = 0;
b32 is_file_scroll = 0; b32 is_file_scroll = 0;
GUI_Session gui_session = {0}; GUI_Session gui_session = {0};
GUI_Header *h = 0; GUI_Header *h = 0;
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, target, rect, view->font_height); gui_session_init(&gui_session, target, rect, view->font_height);
target->active = gui_id_zero(); target->active = gui_id_zero();
for (h = (GUI_Header*)target->push.base; for (h = (GUI_Header*)target->push.base;
h->type; h->type;
h = NextHeader(h)){ h = NextHeader(h)){
@ -4029,7 +4038,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_fixed_option_checkbox: case guicom_fixed_option_checkbox:
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
if (interpret_result.auto_activate){ if (interpret_result.auto_activate){
target->auto_hot = gui_id_zero(); target->auto_hot = gui_id_zero();
target->active = b->id; target->active = b->id;
@ -4043,20 +4052,20 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
}break; }break;
} }
if (interpret_result.has_info){ if (interpret_result.has_info){
switch (h->type){ switch (h->type){
case guicom_top_bar: break; case guicom_top_bar: break;
case guicom_file: case guicom_file:
{ {
f32 new_min_y = -(f32)(gui_session_get_eclipsed_y(&gui_session) - f32 new_min_y = -(f32)(gui_session_get_eclipsed_y(&gui_session) -
gui_session.rect.y0); gui_session.rect.y0);
f32 new_max_y = view_compute_max_target_y(view); f32 new_max_y = view_compute_max_target_y(view);
view->gui_target.scroll_updated.min_y = new_min_y; view->gui_target.scroll_updated.min_y = new_min_y;
view->gui_target.scroll_updated.max_y = new_max_y; view->gui_target.scroll_updated.max_y = new_max_y;
if (view->reinit_scrolling){ if (view->reinit_scrolling){
view_reinit_scrolling(view); view_reinit_scrolling(view);
is_animating = 1; is_animating = 1;
@ -4066,7 +4075,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
is_file_scroll = 1; is_file_scroll = 1;
}break; }break;
case guicom_color_button: case guicom_color_button:
case guicom_font_button: case guicom_font_button:
case guicom_button: case guicom_button:
@ -4074,21 +4083,21 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_style_preview: case guicom_style_preview:
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &is_animating); click_button_input(target, &gui_session, user_input, b, &is_animating);
}break; }break;
case guicom_fixed_option: case guicom_fixed_option:
case guicom_fixed_option_checkbox: case guicom_fixed_option_checkbox:
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &is_animating); click_button_input(target, &gui_session, user_input, b, &is_animating);
{ {
Key_Event_Data key; Key_Event_Data key;
Key_Summary *keys = &user_input->keys; Key_Summary *keys = &user_input->keys;
void *ptr = (b + 1); void *ptr = (b + 1);
String string; String string;
char activation_key; char activation_key;
@ -4109,19 +4118,19 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
} }
}break; }break;
case guicom_scrollable: case guicom_scrollable:
{ {
view->scroll_region = target->region_updated; view->scroll_region = target->region_updated;
}break; }break;
case guicom_scrollable_slider: case guicom_scrollable_slider:
{ {
GUI_id id = gui_id_scrollbar_slider(); GUI_id id = gui_id_scrollbar_slider();
i32 mx = user_input->mouse.x; i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y; i32 my = user_input->mouse.y;
f32 v = 0; f32 v = 0;
if (hit_check(mx, my, gui_session.rect)){ if (hit_check(mx, my, gui_session.rect)){
target->hover = id; target->hover = id;
if (user_input->mouse.press_l){ if (user_input->mouse.press_l){
@ -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:
@ -1158,7 +1187,13 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
target->scroll_original.min_y, target->scroll_original.max_y); target->scroll_original.min_y, target->scroll_original.max_y);
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