Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func float ui_scroll_bar(char* text, s_v2 pos, s_v2 size, float current_scroll, float min_scroll, float max_scroll, s_ui_optional optional = zero)
- {
- max_scroll += c_world_size.y;
- float click_percent = ilerp_clamp(pos.y, pos.y + size.y, platform_shared->mouse.y);
- float scroll_percent = ilerp_clamp(min_scroll, max_scroll, current_scroll);
- float full_height = max_scroll - min_scroll;
- float view_height = size.y;
- {
- e_ui_interaction interaction = ui_rect_button(text, pos, {.flags = e_ui_no_dynamic, .layer_override = optional.layer_override, .button_size = size, .base_color = maybe(DARK)});
- if(interaction == e_ui_interaction_pressed)
- {
- // @TODO(tkap, 30/10/2022): repeat
- }
- else if(interaction == e_ui_interaction_active)
- {
- if(click_percent > scroll_percent)
- {
- current_scroll = at_most(max_scroll, current_scroll + view_height);
- }
- else
- {
- current_scroll = at_least(min_scroll, current_scroll - view_height);
- }
- }
- }
- {
- float percent = view_height / full_height;
- float handle_height = view_height * percent;
- s_v2 handle_pos = pos;
- handle_pos.y += current_scroll * percent;
- char* handle_text = format_text("%s_handle", text);
- e_ui_interaction interaction = ui_rect_button(handle_text, handle_pos, {.flags = e_ui_no_dynamic, .layer_override = optional.layer_override + 1, .button_size = v2(size.x, handle_height), .base_color = maybe(GRAY)});
- if(interaction == e_ui_interaction_pressed)
- {
- float movement = (platform_shared->mouse.y - platform_shared->last_mouse.y) * (full_height / view_height);
- current_scroll = clamp(current_scroll + movement, min_scroll, max_scroll);
- }
- }
- return current_scroll;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement