diff options
Diffstat (limited to 'scene/gui/scroll_container.cpp')
-rw-r--r-- | scene/gui/scroll_container.cpp | 57 |
1 files changed, 18 insertions, 39 deletions
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 4712f4cb9d..05645d0263 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -214,25 +214,6 @@ 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(); - - 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->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); - - h_scroll->raise(); - v_scroll->raise(); -} - void ScrollContainer::_ensure_focused_visible(Control *p_control) { if (!follow_focus) { @@ -262,7 +243,8 @@ void ScrollContainer::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - call_deferred("_update_scrollbar_position"); + h_scroll->call_deferred("raise"); + v_scroll->call_deferred("raise"); }; if (p_what == NOTIFICATION_READY) { @@ -317,6 +299,7 @@ void ScrollContainer::_notification(int p_what) { r.position += ofs; fit_child_in_rect(c, r); } + update(); }; @@ -408,21 +391,22 @@ void ScrollContainer::update_scrollbars() { Size2 hmin; Size2 vmin; - if (scroll_h) hmin = h_scroll->get_combined_minimum_size(); - if (scroll_v) vmin = v_scroll->get_combined_minimum_size(); + if (scroll_h) { + hmin = h_scroll->get_combined_minimum_size(); + } + if (scroll_v) { + vmin = v_scroll->get_combined_minimum_size(); + } Size2 min = child_max_size; - bool hide_scroll_v = !scroll_v || min.height <= size.height - hmin.height; - bool hide_scroll_h = !scroll_h || min.width <= size.width - vmin.width; + bool hide_scroll_v = !scroll_v || min.height <= size.height; + bool hide_scroll_h = !scroll_h || min.width <= size.width; if (hide_scroll_v) { v_scroll->hide(); scroll.y = 0; - - // modify the horizontal scrollbar's right anchor to fill the container's width - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); } else { v_scroll->show(); @@ -434,18 +418,12 @@ void ScrollContainer::update_scrollbars() { } scroll.y = v_scroll->get_value(); - - // modify the horizontal scrollbar's right anchor to stop at the left of the vertical scrollbar - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -vmin.width); } if (hide_scroll_h) { h_scroll->hide(); scroll.x = 0; - - // modify the vertical scrollbar's bottom anchor to fill the container's height - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); } else { h_scroll->show(); @@ -457,10 +435,11 @@ void ScrollContainer::update_scrollbars() { } scroll.x = h_scroll->get_value(); - - // modify the vertical scrollbar's bottom anchor to stop at the top of the horizontal scrollbar - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -hmin.height); } + + // Avoid scrollbar overlapping. + h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, hide_scroll_v ? 0 : -vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, hide_scroll_h ? 0 : -hmin.height); } void ScrollContainer::_scroll_moved(float) { @@ -571,7 +550,6 @@ 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); @@ -605,13 +583,14 @@ ScrollContainer::ScrollContainer() { h_scroll = memnew(HScrollBar); 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); - - h_scroll->connect("value_changed", this, "_scroll_moved"); v_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); drag_speed = Vector2(); drag_touching = false; |