Skip to content

Commit

Permalink
Add ignore_scroll_bar_min_size to ScrollContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
WhalesState committed Jan 27, 2024
1 parent 426b6a3 commit ce3796b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
29 changes: 22 additions & 7 deletions scene/gui/scroll_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ Size2 ScrollContainer::get_minimum_size() const {
min_size.y = MAX(min_size.y, largest_child_min_size.y);
}

bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > min_size.x);
bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > min_size.y);
if (!ignore_scroll_bar_min_size) {
bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > min_size.x);
bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > min_size.y);

if (h_scroll_show && h_scroll->get_parent() == this) {
min_size.y += h_scroll->get_minimum_size().y;
}
if (v_scroll_show && v_scroll->get_parent() == this) {
min_size.x += v_scroll->get_minimum_size().x;
if (h_scroll_show && h_scroll->get_parent() == this) {
min_size.y += h_scroll->get_minimum_size().y;
}
if (v_scroll_show && v_scroll->get_parent() == this) {
min_size.x += v_scroll->get_minimum_size().x;
}
}

min_size += theme_cache.panel_style->get_minimum_size();
Expand Down Expand Up @@ -537,6 +539,15 @@ void ScrollContainer::set_follow_focus(bool p_follow) {
follow_focus = p_follow;
}

void ScrollContainer::set_ignore_scroll_bar_min_size(bool p_ignore) {
ignore_scroll_bar_min_size = p_ignore;
update_minimum_size();
}

bool ScrollContainer::is_ignoring_scroll_bar_min_size() const {
return ignore_scroll_bar_min_size;
}

PackedStringArray ScrollContainer::get_configuration_warnings() const {
PackedStringArray warnings = Container::get_configuration_warnings();

Expand Down Expand Up @@ -599,6 +610,9 @@ void ScrollContainer::_bind_methods() {
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("set_ignore_scroll_bar_min_size", "ignore"), &ScrollContainer::set_ignore_scroll_bar_min_size);
ClassDB::bind_method(D_METHOD("is_ignoring_scroll_bar_min_size"), &ScrollContainer::is_ignoring_scroll_bar_min_size);

ClassDB::bind_method(D_METHOD("get_h_scroll_bar"), &ScrollContainer::get_h_scroll_bar);
ClassDB::bind_method(D_METHOD("get_v_scroll_bar"), &ScrollContainer::get_v_scroll_bar);
ClassDB::bind_method(D_METHOD("ensure_control_visible", "control"), &ScrollContainer::ensure_control_visible);
Expand All @@ -607,6 +621,7 @@ void ScrollContainer::_bind_methods() {
ADD_SIGNAL(MethodInfo("scroll_ended"));

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_focus"), "set_follow_focus", "is_following_focus");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_scroll_bar_min_size"), "set_ignore_scroll_bar_min_size", "is_ignoring_scroll_bar_min_size");

ADD_GROUP("Scroll", "scroll_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal", PROPERTY_HINT_NONE, "suffix:px"), "set_h_scroll", "get_h_scroll");
Expand Down
4 changes: 4 additions & 0 deletions scene/gui/scroll_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ScrollContainer : public Container {

int deadzone = 0;
bool follow_focus = false;
bool ignore_scroll_bar_min_size = true;

struct ThemeCache {
Ref<StyleBox> panel_style;
Expand Down Expand Up @@ -115,6 +116,9 @@ class ScrollContainer : public Container {
bool is_following_focus() const;
void set_follow_focus(bool p_follow);

void set_ignore_scroll_bar_min_size(bool p_ignore);
bool is_ignoring_scroll_bar_min_size() const;

HScrollBar *get_h_scroll_bar();
VScrollBar *get_v_scroll_bar();
void ensure_control_visible(Control *p_control);
Expand Down

0 comments on commit ce3796b

Please sign in to comment.