Fix scrollbar issues in ScrollContainer

This commit is contained in:
Michael Alexsander 2024-05-19 14:57:50 -03:00
parent daa81bbb7d
commit 9353081338
No known key found for this signature in database
GPG key ID: A9C91EE110F4EABA

View file

@ -31,7 +31,6 @@
#include "scroll_container.h" #include "scroll_container.h"
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/os/os.h"
#include "scene/main/window.h" #include "scene/main/window.h"
#include "scene/theme/theme_db.h" #include "scene/theme/theme_db.h"
@ -250,18 +249,21 @@ void ScrollContainer::_update_scrollbar_position() {
return; return;
} }
Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 hmin = h_scroll->is_visible() ? h_scroll->get_combined_minimum_size() : Size2();
Size2 vmin = v_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->is_visible() ? v_scroll->get_combined_minimum_size() : Size2();
h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0); int lmar = is_layout_rtl() ? theme_cache.panel_style->get_margin(SIDE_RIGHT) : theme_cache.panel_style->get_margin(SIDE_LEFT);
h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0); int rmar = is_layout_rtl() ? theme_cache.panel_style->get_margin(SIDE_LEFT) : theme_cache.panel_style->get_margin(SIDE_RIGHT);
h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height);
h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width); h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, lmar);
v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0); h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, -rmar - vmin.width);
v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0); h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height - theme_cache.panel_style->get_margin(SIDE_BOTTOM));
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0); h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -theme_cache.panel_style->get_margin(SIDE_BOTTOM));
v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width - rmar);
v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, -rmar);
v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, theme_cache.panel_style->get_margin(SIDE_TOP));
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -hmin.height - theme_cache.panel_style->get_margin(SIDE_BOTTOM));
_updating_scrollbars = false; _updating_scrollbars = false;
} }
@ -339,7 +341,7 @@ void ScrollContainer::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: { case NOTIFICATION_TRANSLATION_CHANGED: {
_updating_scrollbars = true; _updating_scrollbars = true;
callable_mp(this, &ScrollContainer::_update_scrollbar_position).call_deferred(); callable_mp(this, is_ready() ? &ScrollContainer::_reposition_children : &ScrollContainer::_update_scrollbar_position).call_deferred();
} break; } break;
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
@ -444,8 +446,8 @@ void ScrollContainer::update_scrollbars() {
v_scroll->set_page((h_scroll->is_visible() && h_scroll->get_parent() == this) ? size.height - hmin.height : size.height); v_scroll->set_page((h_scroll->is_visible() && h_scroll->get_parent() == this) ? size.height - hmin.height : size.height);
// Avoid scrollbar overlapping. // Avoid scrollbar overlapping.
h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, (v_scroll->is_visible() && v_scroll->get_parent() == this) ? -vmin.width : 0); _updating_scrollbars = true;
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, (h_scroll->is_visible() && h_scroll->get_parent() == this) ? -hmin.height : 0); callable_mp(this, &ScrollContainer::_update_scrollbar_position).call_deferred();
} }
void ScrollContainer::_scroll_moved(float) { void ScrollContainer::_scroll_moved(float) {