Allow ScrollBar params of a ScrollContainer to be modified in _ready()

Initializes the sizes of the ScrollContainer and its associated
ScrollBars in _ready() to allow scroll values to be set in GDScript
initially.
This commit is contained in:
Maganty Rushyendra 2020-12-29 10:51:38 +08:00
parent 6cebb8c117
commit b8610dbd31
2 changed files with 64 additions and 58 deletions

View File

@ -264,17 +264,7 @@ void ScrollContainer::_ensure_focused_visible(Control *p_control) {
}
}
void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
_updating_scrollbars = true;
call_deferred("_update_scrollbar_position");
};
if (p_what == NOTIFICATION_READY) {
get_viewport()->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_ensure_focused_visible));
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
void ScrollContainer::_update_dimensions() {
child_max_size = Size2(0, 0);
Size2 size = get_size();
Point2 ofs;
@ -333,6 +323,21 @@ void ScrollContainer::_notification(int p_what) {
}
update();
}
void ScrollContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
_updating_scrollbars = true;
call_deferred("_update_scrollbar_position");
};
if (p_what == NOTIFICATION_READY) {
get_viewport()->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_ensure_focused_visible));
_update_dimensions();
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
_update_dimensions();
};
if (p_what == NOTIFICATION_DRAW) {

View File

@ -69,6 +69,7 @@ protected:
Size2 get_minimum_size() const override;
void _gui_input(const Ref<InputEvent> &p_gui_input);
void _update_dimensions();
void _notification(int p_what);
void _scroll_moved(float);