You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Minimap scroll now acts similar to scrollbar
This commit is contained in:
@@ -559,7 +559,7 @@ void TextEdit::_update_selection_mode_line() {
|
|||||||
click_select_held->start();
|
click_select_held->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::_update_minimap_scroll() {
|
void TextEdit::_update_minimap_click() {
|
||||||
Point2 mp = get_local_mouse_position();
|
Point2 mp = get_local_mouse_position();
|
||||||
|
|
||||||
int xmargin_end = get_size().width - cache.style_normal->get_margin(MARGIN_RIGHT);
|
int xmargin_end = get_size().width - cache.style_normal->get_margin(MARGIN_RIGHT);
|
||||||
@@ -573,6 +573,13 @@ void TextEdit::_update_minimap_scroll() {
|
|||||||
int row;
|
int row;
|
||||||
_get_minimap_mouse_row(Point2i(mp.x, mp.y), row);
|
_get_minimap_mouse_row(Point2i(mp.x, mp.y), row);
|
||||||
|
|
||||||
|
if (row >= get_first_visible_line() && (row < get_last_visible_line() || row >= (text.size() - 1))) {
|
||||||
|
minimap_scroll_ratio = v_scroll->get_as_ratio();
|
||||||
|
minimap_scroll_click_pos = mp.y;
|
||||||
|
can_drag_minimap = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int wi;
|
int wi;
|
||||||
int first_line = row - num_lines_from_rows(row, 0, -get_visible_rows() / 2, wi) + 1;
|
int first_line = row - num_lines_from_rows(row, 0, -get_visible_rows() / 2, wi) + 1;
|
||||||
double delta = get_scroll_pos_for_line(first_line, wi) - get_v_scroll();
|
double delta = get_scroll_pos_for_line(first_line, wi) - get_v_scroll();
|
||||||
@@ -583,6 +590,23 @@ void TextEdit::_update_minimap_scroll() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEdit::_update_minimap_drag() {
|
||||||
|
|
||||||
|
if (!can_drag_minimap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int control_height = get_size().height;
|
||||||
|
control_height -= cache.style_normal->get_minimum_size().height;
|
||||||
|
if (h_scroll->is_visible_in_tree()) {
|
||||||
|
control_height -= h_scroll->get_size().height;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point2 mp = get_local_mouse_position();
|
||||||
|
double diff = (mp.y - minimap_scroll_click_pos) / control_height;
|
||||||
|
v_scroll->set_as_ratio(minimap_scroll_ratio + diff);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEdit::_notification(int p_what) {
|
void TextEdit::_notification(int p_what) {
|
||||||
|
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
@@ -2239,7 +2263,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
|
|
||||||
// minimap
|
// minimap
|
||||||
if (draw_minimap) {
|
if (draw_minimap) {
|
||||||
_update_minimap_scroll();
|
_update_minimap_click();
|
||||||
if (dragging_minimap) {
|
if (dragging_minimap) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2362,6 +2386,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
if (mb->get_button_index() == BUTTON_LEFT) {
|
if (mb->get_button_index() == BUTTON_LEFT) {
|
||||||
dragging_minimap = false;
|
dragging_minimap = false;
|
||||||
dragging_selection = false;
|
dragging_selection = false;
|
||||||
|
can_drag_minimap = false;
|
||||||
click_select_held->stop();
|
click_select_held->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2410,7 +2435,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
_reset_caret_blink_timer();
|
_reset_caret_blink_timer();
|
||||||
|
|
||||||
if (draw_minimap && !dragging_selection) {
|
if (draw_minimap && !dragging_selection) {
|
||||||
_update_minimap_scroll();
|
_update_minimap_drag();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dragging_minimap) {
|
if (!dragging_minimap) {
|
||||||
@@ -7018,6 +7043,9 @@ TextEdit::TextEdit() {
|
|||||||
scrolling = false;
|
scrolling = false;
|
||||||
minimap_clicked = false;
|
minimap_clicked = false;
|
||||||
dragging_minimap = false;
|
dragging_minimap = false;
|
||||||
|
can_drag_minimap = false;
|
||||||
|
minimap_scroll_ratio = 0;
|
||||||
|
minimap_scroll_click_pos = 0;
|
||||||
dragging_selection = false;
|
dragging_selection = false;
|
||||||
target_v_scroll = 0;
|
target_v_scroll = 0;
|
||||||
v_scroll_speed = 80;
|
v_scroll_speed = 80;
|
||||||
|
|||||||
@@ -334,7 +334,10 @@ private:
|
|||||||
bool scrolling;
|
bool scrolling;
|
||||||
bool dragging_selection;
|
bool dragging_selection;
|
||||||
bool dragging_minimap;
|
bool dragging_minimap;
|
||||||
|
bool can_drag_minimap;
|
||||||
bool minimap_clicked;
|
bool minimap_clicked;
|
||||||
|
double minimap_scroll_ratio;
|
||||||
|
double minimap_scroll_click_pos;
|
||||||
float target_v_scroll;
|
float target_v_scroll;
|
||||||
float v_scroll_speed;
|
float v_scroll_speed;
|
||||||
|
|
||||||
@@ -406,7 +409,8 @@ private:
|
|||||||
void _update_selection_mode_word();
|
void _update_selection_mode_word();
|
||||||
void _update_selection_mode_line();
|
void _update_selection_mode_line();
|
||||||
|
|
||||||
void _update_minimap_scroll();
|
void _update_minimap_click();
|
||||||
|
void _update_minimap_drag();
|
||||||
void _scroll_up(real_t p_delta);
|
void _scroll_up(real_t p_delta);
|
||||||
void _scroll_down(real_t p_delta);
|
void _scroll_down(real_t p_delta);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user