diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-08-23 08:09:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-23 08:09:13 +0200 |
commit | 916fd473431f4672262ae1eb84f1aa6b68e25915 (patch) | |
tree | 8470e5637048fa37dc6a1caf71fe0e738c4138b3 | |
parent | 5c6be4ddb8bd2f3454020ed22e198f304d76a643 (diff) | |
parent | 24c6c097f360c4bdaf20e9057177995c76784f6c (diff) |
Merge pull request #10561 from Paulb23/smooth_scroll_input_override
Stops scrolling when the user issues another command
-rw-r--r-- | scene/gui/scroll_bar.cpp | 9 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 13 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
3 files changed, 21 insertions, 2 deletions
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 6519cde6d3..4242ee4523 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -40,6 +40,11 @@ void ScrollBar::set_can_focus_by_default(bool p_can_focus) { void ScrollBar::_gui_input(Ref<InputEvent> p_event) { + Ref<InputEventMouseMotion> m = p_event; + if (!m.is_valid() || drag.active) { + emit_signal("scrolling"); + } + Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { @@ -143,8 +148,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } } - Ref<InputEventMouseMotion> m = p_event; - if (m.is_valid()) { accept_event(); @@ -823,6 +826,8 @@ void ScrollBar::_bind_methods() { ClassDB::bind_method(D_METHOD("_drag_slave_input"), &ScrollBar::_drag_slave_input); ClassDB::bind_method(D_METHOD("_drag_slave_exit"), &ScrollBar::_drag_slave_exit); + ADD_SIGNAL(MethodInfo("scrolling")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "custom_step", PROPERTY_HINT_RANGE, "-1,4096"), "set_custom_step", "get_custom_step"); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 68529ae255..245e7e04be 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2880,6 +2880,8 @@ void TextEdit::_post_shift_selection() { } void TextEdit::_scroll_lines_up() { + scrolling = false; + // adjust the vertical scroll if (get_v_scroll() > 0) { set_v_scroll(get_v_scroll() - 1); @@ -2892,6 +2894,8 @@ void TextEdit::_scroll_lines_up() { } void TextEdit::_scroll_lines_down() { + scrolling = false; + // calculate the maximum vertical scroll position int max_v_scroll = get_line_count() - 1; if (!scroll_past_end_of_file_enabled) { @@ -3156,6 +3160,7 @@ int TextEdit::get_visible_rows() const { return total; } void TextEdit::adjust_viewport_to_cursor() { + scrolling = false; if (cursor.line_ofs > cursor.line) cursor.line_ofs = cursor.line; @@ -3195,6 +3200,7 @@ void TextEdit::adjust_viewport_to_cursor() { } void TextEdit::center_viewport_to_cursor() { + scrolling = false; if (cursor.line_ofs > cursor.line) cursor.line_ofs = cursor.line; @@ -3313,6 +3319,10 @@ bool TextEdit::cursor_is_block_mode() const { return block_caret; } +void TextEdit::_v_scroll_input() { + scrolling = false; +} + void TextEdit::_scroll_moved(double p_to_val) { if (updating_scrolls) @@ -4706,6 +4716,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_push_current_op"), &TextEdit::_push_current_op); ClassDB::bind_method(D_METHOD("_click_selection_held"), &TextEdit::_click_selection_held); ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &TextEdit::_toggle_draw_caret); + ClassDB::bind_method(D_METHOD("_v_scroll_input"), &TextEdit::_v_scroll_input); BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE); BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS); @@ -4843,6 +4854,8 @@ TextEdit::TextEdit() { h_scroll->connect("value_changed", this, "_scroll_moved"); v_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->connect("scrolling", this, "_v_scroll_input"); + cursor_changed_dirty = false; text_changed_dirty = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 1abfe368dd..6321cad2da 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -299,6 +299,7 @@ class TextEdit : public Control { void adjust_viewport_to_cursor(); void _scroll_moved(double); void _update_scrollbars(); + void _v_scroll_input(); void _click_selection_held(); void _pre_shift_selection(); |