diff --git a/doc/classes/ScrollBar.xml b/doc/classes/ScrollBar.xml index d9f0217638a3..c5e7272140e7 100644 --- a/doc/classes/ScrollBar.xml +++ b/doc/classes/ScrollBar.xml @@ -23,6 +23,22 @@ + + Padding between the bottom of the [theme_item scroll] element and the [theme_item grabber]. Only used in [HScrollBar]. + [b]Note:[/b] To apply vertical padding to [VScrollBar], modify the top/bottom content margins of [theme_item scroll] instead. + + + Padding between the left of the [theme_item scroll] element and the [theme_item grabber]. Only used in [VScrollBar]. + [b]Note:[/b] To apply horizontal padding to [HScrollBar], modify the top/bottom content margins of [theme_item scroll] instead. + + + Padding between the right of the [theme_item scroll] element and the [theme_item grabber]. Only used in [VScrollBar]. + [b]Note:[/b] To apply horizontal padding to [HScrollBar], modify the top/bottom content margins of [theme_item scroll] instead. + + + Padding between the top of the [theme_item scroll] element and the [theme_item grabber]. Only used in [HScrollBar]. + [b]Note:[/b] To apply vertical padding to [VScrollBar], modify the top/bottom content margins of [theme_item scroll] instead. + Icon used as a button to scroll the [ScrollBar] left/up. Supports custom step using the [member ScrollBar.custom_step] property. diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index c8b848fc3544..a62782e87126 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -295,15 +295,19 @@ void ScrollBar::_notification(int p_what) { Rect2 grabber_rect; if (orientation == HORIZONTAL) { + int padding_top = MAX(theme_cache.padding_top, 0); + int padding_bottom = MAX(theme_cache.padding_bottom, 0); grabber_rect.size.width = get_grabber_size(); - grabber_rect.size.height = get_size().height; - grabber_rect.position.y = 0; + grabber_rect.size.height = get_size().height - padding_top - padding_bottom; + grabber_rect.position.y = padding_top; grabber_rect.position.x = get_grabber_offset() + decr->get_width() + theme_cache.scroll_style->get_margin(SIDE_LEFT); } else { - grabber_rect.size.width = get_size().width; + int padding_left = MAX(theme_cache.padding_left, 0); + int padding_right = MAX(theme_cache.padding_right, 0); + grabber_rect.size.width = get_size().width - padding_left - padding_right; grabber_rect.size.height = get_grabber_size(); grabber_rect.position.y = get_grabber_offset() + decr->get_height() + theme_cache.scroll_style->get_margin(SIDE_TOP); - grabber_rect.position.x = 0; + grabber_rect.position.x = padding_left; } grabber->draw(ci, grabber_rect); @@ -488,7 +492,10 @@ Size2 ScrollBar::get_minimum_size() const { Size2 minsize; if (orientation == VERTICAL) { + int padding_left = MAX(theme_cache.padding_left, 0); + int padding_right = MAX(theme_cache.padding_right, 0); minsize.width = MAX(incr->get_size().width, bg->get_minimum_size().width); + minsize.width += padding_left + padding_right; minsize.height += incr->get_size().height; minsize.height += decr->get_size().height; minsize.height += bg->get_minimum_size().height; @@ -496,7 +503,10 @@ Size2 ScrollBar::get_minimum_size() const { } if (orientation == HORIZONTAL) { + int padding_top = MAX(theme_cache.padding_top, 0); + int padding_bottom = MAX(theme_cache.padding_bottom, 0); minsize.height = MAX(incr->get_size().height, bg->get_minimum_size().height); + minsize.height += padding_top + padding_bottom; minsize.width += incr->get_size().width; minsize.width += decr->get_size().width; minsize.width += bg->get_minimum_size().width; @@ -654,6 +664,11 @@ void ScrollBar::_bind_methods() { BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, ScrollBar, decrement_icon, "decrement"); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, ScrollBar, decrement_hl_icon, "decrement_highlight"); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, ScrollBar, decrement_pressed_icon, "decrement_pressed"); + + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, ScrollBar, padding_left, "padding_left"); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, ScrollBar, padding_top, "padding_top"); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, ScrollBar, padding_right, "padding_right"); + BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, ScrollBar, padding_bottom, "padding_bottom"); } ScrollBar::ScrollBar(Orientation p_orientation) { diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index f2a49e4e7fac..4b3f94e9d4e5 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -98,6 +98,11 @@ class ScrollBar : public Range { Ref decrement_icon; Ref decrement_hl_icon; Ref decrement_pressed_icon; + + int padding_left = 0; + int padding_top = 0; + int padding_right = 0; + int padding_bottom = 0; } theme_cache; void _drag_node_exit();