Add visual feedback when hovering or dragging the code minimap grabber
This makes it more obvious that the minimap grabber can be dragged to scroll.
This commit is contained in:
parent
98e1b730c8
commit
85ebe8e3f6
@ -528,6 +528,33 @@ void TextEdit::_update_selection_mode_line() {
|
|||||||
click_select_held->start();
|
click_select_held->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEdit::_update_minimap_hover() {
|
||||||
|
const Point2 mp = get_local_mouse_position();
|
||||||
|
const int xmargin_end = get_size().width - cache.style_normal->get_margin(MARGIN_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int row;
|
||||||
|
_get_minimap_mouse_row(Point2i(mp.x, mp.y), row);
|
||||||
|
|
||||||
|
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_position();
|
Point2 mp = get_local_mouse_position();
|
||||||
|
|
||||||
@ -916,8 +943,19 @@ void TextEdit::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
int minimap_draw_amount = minimap_visible_lines + times_line_wraps(minimap_line + 1);
|
int minimap_draw_amount = minimap_visible_lines + times_line_wraps(minimap_line + 1);
|
||||||
|
|
||||||
// draw the minimap
|
// Draw the minimap.
|
||||||
Color viewport_color = (cache.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 = (cache.background_color.get_v() < 0.5) ? Color(1, 1, 1, viewport_alpha) : Color(0, 0, 0, viewport_alpha);
|
||||||
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color);
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.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++;
|
||||||
@ -2586,6 +2624,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (draw_minimap && !dragging_selection) {
|
||||||
|
_update_minimap_hover();
|
||||||
|
}
|
||||||
|
|
||||||
if (mm->get_button_mask() & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { // Ignore if dragging.
|
if (mm->get_button_mask() & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { // Ignore if dragging.
|
||||||
_reset_caret_blink_timer();
|
_reset_caret_blink_timer();
|
||||||
|
|
||||||
@ -7352,6 +7394,7 @@ TextEdit::TextEdit() {
|
|||||||
smooth_scroll_enabled = false;
|
smooth_scroll_enabled = false;
|
||||||
scrolling = false;
|
scrolling = false;
|
||||||
minimap_clicked = false;
|
minimap_clicked = false;
|
||||||
|
hovering_minimap = false;
|
||||||
dragging_minimap = false;
|
dragging_minimap = false;
|
||||||
can_drag_minimap = false;
|
can_drag_minimap = false;
|
||||||
minimap_scroll_ratio = 0;
|
minimap_scroll_ratio = 0;
|
||||||
|
@ -392,6 +392,7 @@ private:
|
|||||||
bool smooth_scroll_enabled;
|
bool smooth_scroll_enabled;
|
||||||
bool scrolling;
|
bool scrolling;
|
||||||
bool dragging_selection;
|
bool dragging_selection;
|
||||||
|
bool hovering_minimap;
|
||||||
bool dragging_minimap;
|
bool dragging_minimap;
|
||||||
bool can_drag_minimap;
|
bool can_drag_minimap;
|
||||||
bool minimap_clicked;
|
bool minimap_clicked;
|
||||||
@ -476,6 +477,7 @@ private:
|
|||||||
void _update_selection_mode_word();
|
void _update_selection_mode_word();
|
||||||
void _update_selection_mode_line();
|
void _update_selection_mode_line();
|
||||||
|
|
||||||
|
void _update_minimap_hover();
|
||||||
void _update_minimap_click();
|
void _update_minimap_click();
|
||||||
void _update_minimap_drag();
|
void _update_minimap_drag();
|
||||||
void _scroll_up(real_t p_delta);
|
void _scroll_up(real_t p_delta);
|
||||||
|
Loading…
Reference in New Issue
Block a user