Merge pull request #35859 from Calinou/minimap-add-hover-pressed-feedback

Add visual feedback when hovering or dragging the code minimap grabber
This commit is contained in:
Gilles Roudière 2021-09-06 16:22:36 +02:00 committed by GitHub
commit 1f97d57384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 2 deletions

View File

@ -557,13 +557,25 @@ void TextEdit::_notification(int p_what) {
} }
int minimap_draw_amount = minimap_visible_lines + get_line_wrap_count(minimap_line + 1); int minimap_draw_amount = minimap_visible_lines + get_line_wrap_count(minimap_line + 1);
// draw the minimap // Draw the minimap.
Color viewport_color = (background_color.get_v() < 0.5) ? Color(1, 1, 1, 0.1) : Color(0, 0, 0, 0.1);
// Add visual feedback when dragging or hovering the the visible area rectangle.
float viewport_alpha;
if (dragging_minimap) {
viewport_alpha = 0.25;
} else if (hovering_minimap) {
viewport_alpha = 0.175;
} else {
viewport_alpha = 0.1;
}
const Color viewport_color = (background_color.get_v() < 0.5) ? Color(1, 1, 1, viewport_alpha) : Color(0, 0, 0, viewport_alpha);
if (rtl) { if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - minimap_width, viewport_offset_y, minimap_width, viewport_height), viewport_color); RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - minimap_width, viewport_offset_y, minimap_width, viewport_height), viewport_color);
} else { } else {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, minimap_width, viewport_height), viewport_color); RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, minimap_width, viewport_height), viewport_color);
} }
for (int i = 0; i < minimap_draw_amount; i++) { for (int i = 0; i < minimap_draw_amount; i++) {
minimap_line++; minimap_line++;
@ -1549,6 +1561,10 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
} }
} }
if (draw_minimap && !dragging_selection) {
_update_minimap_hover();
}
if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) { if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed. accept_event(); // Accept event if scroll changed.
} }
@ -5644,6 +5660,33 @@ void TextEdit::_scroll_lines_down() {
} }
// Minimap // Minimap
void TextEdit::_update_minimap_hover() {
const Point2 mp = get_local_mouse_pos();
const int xmargin_end = get_size().width - style_normal->get_margin(SIDE_RIGHT);
const bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end;
if (!hovering_sidebar) {
if (hovering_minimap) {
// Only redraw if the hovering status changed.
hovering_minimap = false;
update();
}
// Return early to avoid running the operations below when not needed.
return;
}
const int row = get_minimap_line_at_pos(Point2i(mp.x, mp.y));
const bool new_hovering_minimap = row >= get_first_visible_line() && row <= get_last_full_visible_line();
if (new_hovering_minimap != hovering_minimap) {
// Only redraw if the hovering status changed.
hovering_minimap = new_hovering_minimap;
update();
}
}
void TextEdit::_update_minimap_click() { void TextEdit::_update_minimap_click() {
Point2 mp = get_local_mouse_pos(); Point2 mp = get_local_mouse_pos();

View File

@ -446,12 +446,14 @@ private:
// minimap scroll // minimap scroll
bool minimap_clicked = false; bool minimap_clicked = false;
bool hovering_minimap = false;
bool dragging_minimap = false; bool dragging_minimap = false;
bool can_drag_minimap = false; bool can_drag_minimap = false;
double minimap_scroll_ratio = 0.0; double minimap_scroll_ratio = 0.0;
double minimap_scroll_click_pos = 0.0; double minimap_scroll_click_pos = 0.0;
void _update_minimap_hover();
void _update_minimap_click(); void _update_minimap_click();
void _update_minimap_drag(); void _update_minimap_drag();