diff options
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 102 |
1 files changed, 63 insertions, 39 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 21842d4d58..69dc7b21fe 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1777,46 +1777,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->is_pressed()) { if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) { - float scroll_factor = 3 * mb->get_factor(); - if (scrolling) { - target_v_scroll = (target_v_scroll - scroll_factor); - } else { - target_v_scroll = (v_scroll->get_value() - scroll_factor); - } - - if (smooth_scroll_enabled) { - if (target_v_scroll <= 0) { - target_v_scroll = 0; - } - scrolling = true; - set_physics_process(true); - } else { - v_scroll->set_value(target_v_scroll); - } + _scroll_up(3 * mb->get_factor()); } if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) { - float scroll_factor = 3 * mb->get_factor(); - if (scrolling) { - target_v_scroll = (target_v_scroll + scroll_factor); - } else { - target_v_scroll = (v_scroll->get_value() + scroll_factor); - } - - if (smooth_scroll_enabled) { - int max_v_scroll = get_total_unhidden_rows(); - if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows(); - max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); - } - - if (target_v_scroll > max_v_scroll) { - target_v_scroll = max_v_scroll; - } - scrolling = true; - set_physics_process(true); - } else { - v_scroll->set_value(target_v_scroll); - } + _scroll_down(3 * mb->get_factor()); } if (mb->get_button_index() == BUTTON_WHEEL_LEFT) { h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor())); @@ -1973,6 +1937,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } + const Ref<InputEventPanGesture> pan_gesture = p_gui_input; + if (pan_gesture.is_valid()) { + + const real_t delta = pan_gesture->get_delta().y; + if (delta < 0) { + _scroll_up(-delta); + } else { + _scroll_down(delta); + } + h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100); + return; + } + Ref<InputEventMouseMotion> mm = p_gui_input; if (mm.is_valid()) { @@ -3066,6 +3043,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } +void TextEdit::_scroll_up(real_t p_delta) { + + if (scrolling) { + target_v_scroll = (target_v_scroll - p_delta); + } else { + target_v_scroll = (v_scroll->get_value() - p_delta); + } + + if (smooth_scroll_enabled) { + if (target_v_scroll <= 0) { + target_v_scroll = 0; + } + scrolling = true; + set_physics_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } +} + +void TextEdit::_scroll_down(real_t p_delta) { + + if (scrolling) { + target_v_scroll = (target_v_scroll + p_delta); + } else { + target_v_scroll = (v_scroll->get_value() + p_delta); + } + + if (smooth_scroll_enabled) { + int max_v_scroll = get_total_unhidden_rows(); + if (!scroll_past_end_of_file_enabled) { + max_v_scroll -= get_visible_rows(); + max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); + } + + if (target_v_scroll > max_v_scroll) { + target_v_scroll = max_v_scroll; + } + scrolling = true; + set_physics_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } +} + void TextEdit::_pre_shift_selection() { if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) { @@ -3467,7 +3488,10 @@ void TextEdit::adjust_viewport_to_cursor() { cursor.x_ofs = cursor_x; update_line_scroll_pos(); - v_scroll->set_value(get_line_scroll_pos() + 1); + if (get_line_scroll_pos() == 0) + v_scroll->set_value(0); + else + v_scroll->set_value(get_line_scroll_pos() + 1); update(); /* get_range()->set_max(text.size()); |