diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-12-30 19:00:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-30 19:00:57 +0100 |
commit | 97ebde45d58bf54ee4cc8fbbe56097c4b5cffec8 (patch) | |
tree | b5709c19f02c9cec7f4637ffa71aa1ebed6a0940 | |
parent | d53a297a6d8dd98bcfc863c6dd3faa59baf6f72e (diff) | |
parent | cc7288510792f805135ce78374e6e1d0b58c1ee3 (diff) |
Merge pull request #34572 from KoBeWi/I_give_up
Make new ScrollContainer focus behavior optional
-rw-r--r-- | doc/classes/ScrollContainer.xml | 3 | ||||
-rw-r--r-- | scene/gui/scroll_container.cpp | 17 | ||||
-rw-r--r-- | scene/gui/scroll_container.h | 4 |
3 files changed, 24 insertions, 0 deletions
diff --git a/doc/classes/ScrollContainer.xml b/doc/classes/ScrollContainer.xml index 5218b65886..f57730a591 100644 --- a/doc/classes/ScrollContainer.xml +++ b/doc/classes/ScrollContainer.xml @@ -24,6 +24,9 @@ </methods> <members> <member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" override="true" default="true" /> + <member name="follow_focus" type="bool" setter="set_follow_focus" getter="is_following_focus" default="false"> + If [code]true[/code], the ScrollContainer will automatically scroll to focused children (including indirect children) to make sure they are fully visible. + </member> <member name="scroll_deadzone" type="int" setter="set_deadzone" getter="get_deadzone" default="0"> </member> <member name="scroll_horizontal" type="int" setter="set_h_scroll" getter="get_h_scroll" default="0"> diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index cb9ae875b7..c44cebb84a 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -235,6 +235,10 @@ void ScrollContainer::_update_scrollbar_position() { void ScrollContainer::_ensure_focused_visible(Control *p_control) { + if (!follow_focus) { + return; + } + if (is_a_parent_of(p_control)) { Rect2 global_rect = get_global_rect(); Rect2 other_rect = p_control->get_global_rect(); @@ -506,6 +510,14 @@ void ScrollContainer::set_deadzone(int p_deadzone) { deadzone = p_deadzone; } +bool ScrollContainer::is_following_focus() const { + return follow_focus; +} + +void ScrollContainer::set_follow_focus(int p_follow) { + follow_focus = p_follow; +} + String ScrollContainer::get_configuration_warning() const { int found = 0; @@ -555,6 +567,8 @@ void ScrollContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_v_scroll"), &ScrollContainer::get_v_scroll); ClassDB::bind_method(D_METHOD("set_deadzone", "deadzone"), &ScrollContainer::set_deadzone); ClassDB::bind_method(D_METHOD("get_deadzone"), &ScrollContainer::get_deadzone); + ClassDB::bind_method(D_METHOD("set_follow_focus", "enabled"), &ScrollContainer::set_follow_focus); + ClassDB::bind_method(D_METHOD("is_following_focus"), &ScrollContainer::is_following_focus); ClassDB::bind_method(D_METHOD("get_h_scrollbar"), &ScrollContainer::get_h_scrollbar); ClassDB::bind_method(D_METHOD("get_v_scrollbar"), &ScrollContainer::get_v_scrollbar); @@ -562,6 +576,8 @@ void ScrollContainer::_bind_methods() { ADD_SIGNAL(MethodInfo("scroll_started")); ADD_SIGNAL(MethodInfo("scroll_ended")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_focus"), "set_follow_focus", "is_following_focus"); + ADD_GROUP("Scroll", "scroll_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_horizontal_enabled"), "set_enable_h_scroll", "is_h_scroll_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal"), "set_h_scroll", "get_h_scroll"); @@ -593,6 +609,7 @@ ScrollContainer::ScrollContainer() { scroll_v = true; deadzone = GLOBAL_GET("gui/common/default_scroll_deadzone"); + follow_focus = false; set_clip_contents(true); }; diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index 1d247f14c6..d4576372ac 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -62,6 +62,7 @@ class ScrollContainer : public Container { bool scroll_v; int deadzone; + bool follow_focus; void _cancel_drag(); @@ -93,6 +94,9 @@ public: int get_deadzone() const; void set_deadzone(int p_deadzone); + bool is_following_focus() const; + void set_follow_focus(int p_follow); + HScrollBar *get_h_scrollbar(); VScrollBar *get_v_scrollbar(); |