summaryrefslogtreecommitdiff
path: root/scene/gui/scroll_container.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/scroll_container.cpp')
-rw-r--r--scene/gui/scroll_container.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 05645d0263..509e6d19f6 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -214,6 +214,25 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
accept_event(); //accept event if scroll changed
}
+void ScrollContainer::_update_scrollbar_position() {
+
+ Size2 hmin = h_scroll->get_combined_minimum_size();
+ Size2 vmin = v_scroll->get_combined_minimum_size();
+
+ h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0);
+ h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
+ h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height);
+ h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
+
+ v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width);
+ v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
+ v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0);
+ v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
+
+ h_scroll->raise();
+ v_scroll->raise();
+}
+
void ScrollContainer::_ensure_focused_visible(Control *p_control) {
if (!follow_focus) {
@@ -243,8 +262,7 @@ void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- h_scroll->call_deferred("raise");
- v_scroll->call_deferred("raise");
+ call_deferred("_update_scrollbar_position");
};
if (p_what == NOTIFICATION_READY) {
@@ -452,8 +470,12 @@ void ScrollContainer::_scroll_moved(float) {
};
void ScrollContainer::set_enable_h_scroll(bool p_enable) {
+ if (scroll_h == p_enable) {
+ return;
+ }
scroll_h = p_enable;
+ minimum_size_changed();
queue_sort();
}
@@ -463,8 +485,12 @@ bool ScrollContainer::is_h_scroll_enabled() const {
}
void ScrollContainer::set_enable_v_scroll(bool p_enable) {
+ if (scroll_v == p_enable) {
+ return;
+ }
scroll_v = p_enable;
+ minimum_size_changed();
queue_sort();
}
@@ -550,6 +576,7 @@ void ScrollContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled);
ClassDB::bind_method(D_METHOD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll);
ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled);
+ ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position);
ClassDB::bind_method(D_METHOD("_ensure_focused_visible"), &ScrollContainer::_ensure_focused_visible);
ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll);
ClassDB::bind_method(D_METHOD("get_h_scroll"), &ScrollContainer::get_h_scroll);
@@ -584,13 +611,11 @@ ScrollContainer::ScrollContainer() {
h_scroll->set_name("_h_scroll");
add_child(h_scroll);
h_scroll->connect("value_changed", this, "_scroll_moved");
- h_scroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE);
v_scroll = memnew(VScrollBar);
v_scroll->set_name("_v_scroll");
add_child(v_scroll);
v_scroll->connect("value_changed", this, "_scroll_moved");
- v_scroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE);
drag_speed = Vector2();
drag_touching = false;