Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added increment_pressed and decrement_pressed icons to scrollbars #51805

Merged
merged 1 commit into from
Sep 13, 2021
Merged
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
6 changes: 6 additions & 0 deletions doc/classes/HScrollBar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<theme_item name="decrement_highlight" data_type="icon" type="Texture2D">
Displayed when the mouse cursor hovers over the decrement button.
</theme_item>
<theme_item name="decrement_pressed" data_type="icon" type="Texture2D">
Displayed when the decrement button is being pressed.
</theme_item>
<theme_item name="grabber" data_type="style" type="StyleBox">
Used as texture for the grabber, the draggable element representing current scroll.
</theme_item>
Expand All @@ -34,6 +37,9 @@
<theme_item name="increment_highlight" data_type="icon" type="Texture2D">
Displayed when the mouse cursor hovers over the increment button.
</theme_item>
<theme_item name="increment_pressed" data_type="icon" type="Texture2D">
Displayed when the increment button is being pressed.
</theme_item>
<theme_item name="scroll" data_type="style" type="StyleBox">
Used as background of this [ScrollBar].
</theme_item>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/VScrollBar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<theme_item name="decrement_highlight" data_type="icon" type="Texture2D">
Displayed when the mouse cursor hovers over the decrement button.
</theme_item>
<theme_item name="decrement_pressed" data_type="icon" type="Texture2D">
Displayed when the decrement button is being pressed.
</theme_item>
<theme_item name="grabber" data_type="style" type="StyleBox">
Used as texture for the grabber, the draggable element representing current scroll.
</theme_item>
Expand All @@ -38,6 +41,9 @@
<theme_item name="increment_highlight" data_type="icon" type="Texture2D">
Displayed when the mouse cursor hovers over the increment button.
</theme_item>
<theme_item name="increment_pressed" data_type="icon" type="Texture2D">
Displayed when the increment button is being pressed.
</theme_item>
<theme_item name="scroll" data_type="style" type="StyleBox">
Used as background of this [ScrollBar].
</theme_item>
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_icon("increment", "HScrollBar", empty_icon);
theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
theme->set_icon("increment_pressed", "HScrollBar", empty_icon);
theme->set_icon("decrement", "HScrollBar", empty_icon);
theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
theme->set_icon("decrement_pressed", "HScrollBar", empty_icon);

// VScrollBar
theme->set_stylebox("scroll", "VScrollBar", make_stylebox(theme->get_icon("GuiScrollBg", "EditorIcons"), 5, 5, 5, 5, 0, 0, 0, 0));
Expand All @@ -1148,8 +1150,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_icon("increment", "VScrollBar", empty_icon);
theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
theme->set_icon("increment_pressed", "VScrollBar", empty_icon);
theme->set_icon("decrement", "VScrollBar", empty_icon);
theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
theme->set_icon("decrement_pressed", "VScrollBar", empty_icon);

// HSlider
theme->set_icon("grabber_highlight", "HSlider", theme->get_icon("GuiSliderGrabberHl", "EditorIcons"));
Expand Down
26 changes: 24 additions & 2 deletions scene/gui/scroll_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
double total = orientation == VERTICAL ? get_size().height : get_size().width;

if (ofs < decr_size) {
decr_active = true;
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
update();
return;
}

if (ofs > total - incr_size) {
incr_active = true;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
update();
return;
}

Expand Down Expand Up @@ -130,6 +134,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
}

} else {
incr_active = false;
decr_active = false;
drag.active = false;
update();
}
Expand Down Expand Up @@ -215,8 +221,24 @@ void ScrollBar::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();

Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon(SNAME("decrement_highlight")) : get_theme_icon(SNAME("decrement"));
Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon(SNAME("increment_highlight")) : get_theme_icon(SNAME("increment"));
Ref<Texture2D> decr, incr;

if (decr_active) {
decr = get_theme_icon(SNAME("decrement_pressed"));
} else if (highlight == HIGHLIGHT_DECR) {
decr = get_theme_icon(SNAME("decrement_highlight"));
} else {
decr = get_theme_icon(SNAME("decrement"));
}

if (incr_active) {
incr = get_theme_icon(SNAME("increment_pressed"));
} else if (highlight == HIGHLIGHT_INCR) {
incr = get_theme_icon(SNAME("increment_highlight"));
} else {
incr = get_theme_icon(SNAME("increment"));
}

Ref<StyleBox> bg = has_focus() ? get_theme_stylebox(SNAME("scroll_focus")) : get_theme_stylebox(SNAME("scroll"));

Ref<StyleBox> grabber;
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/scroll_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ScrollBar : public Range {

HighlightStatus highlight = HIGHLIGHT_NONE;

bool incr_active = false;
bool decr_active = false;

struct Drag {
bool active = false;
float pos_at_click = 0.0;
Expand Down
4 changes: 4 additions & 0 deletions scene/resources/default_theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const

theme->set_icon("increment", "HScrollBar", empty_icon);
theme->set_icon("increment_highlight", "HScrollBar", empty_icon);
theme->set_icon("increment_pressed", "HScrollBar", empty_icon);
theme->set_icon("decrement", "HScrollBar", empty_icon);
theme->set_icon("decrement_highlight", "HScrollBar", empty_icon);
theme->set_icon("decrement_pressed", "HScrollBar", empty_icon);

// VScrollBar

Expand All @@ -535,8 +537,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const

theme->set_icon("increment", "VScrollBar", empty_icon);
theme->set_icon("increment_highlight", "VScrollBar", empty_icon);
theme->set_icon("increment_pressed", "VScrollBar", empty_icon);
theme->set_icon("decrement", "VScrollBar", empty_icon);
theme->set_icon("decrement_highlight", "VScrollBar", empty_icon);
theme->set_icon("decrement_pressed", "VScrollBar", empty_icon);

// HSlider

Expand Down