Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/classes/ScrollBar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
</signal>
</signals>
<theme_items>
<theme_item name="padding_bottom" data_type="constant" type="int" default="0">
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.
</theme_item>
<theme_item name="padding_left" data_type="constant" type="int" default="0">
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.
</theme_item>
<theme_item name="padding_right" data_type="constant" type="int" default="0">
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.
</theme_item>
<theme_item name="padding_top" data_type="constant" type="int" default="0">
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.
</theme_item>
<theme_item name="decrement" data_type="icon" type="Texture2D">
Icon used as a button to scroll the [ScrollBar] left/up. Supports custom step using the [member ScrollBar.custom_step] property.
</theme_item>
Expand Down
23 changes: 19 additions & 4 deletions scene/gui/scroll_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -488,15 +492,21 @@ 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;
minsize.height += get_grabber_min_size();
}

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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions scene/gui/scroll_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ScrollBar : public Range {
Ref<Texture2D> decrement_icon;
Ref<Texture2D> decrement_hl_icon;
Ref<Texture2D> 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();
Expand Down