Skip to content

Commit 917f8b1

Browse files
committed
Deprecate updown icon
1 parent f92f1ce commit 917f8b1

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

doc/classes/SpinBox.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
<theme_item name="up_pressed" data_type="icon" type="Texture2D">
134134
Up button icon when the button is being pressed.
135135
</theme_item>
136-
<theme_item name="updown" data_type="icon" type="Texture2D">
137-
Single texture representing both the up and down buttons icons. It is displayed in the middle of the buttons and does not change upon interaction. It is recommended to use individual [theme_item up] and [theme_item down] graphics for better usability. This can also be used as additional decoration between the two buttons.
136+
<theme_item name="updown" data_type="icon" type="Texture2D" deprecated="Use [theme_item up] and [theme_item down] instead.">
137+
Single texture representing both the up and down buttons icons. It is displayed in the middle of the buttons and does not change upon interaction. If a valid icon is assigned, it will replace [theme_item up] and [theme_item down].
138138
</theme_item>
139139
<theme_item name="down_background" data_type="style" type="StyleBox">
140140
Background style of the down button.

scene/gui/spin_box.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ inline void SpinBox::_compute_sizes() {
399399

400400
inline int SpinBox::_get_widest_button_icon_width() {
401401
int max = 0;
402+
#ifndef DISABLE_DEPRECATED
402403
max = MAX(max, theme_cache.updown_icon->get_width());
404+
#endif
403405
max = MAX(max, theme_cache.up_icon->get_width());
404406
max = MAX(max, theme_cache.up_hover_icon->get_width());
405407
max = MAX(max, theme_cache.up_pressed_icon->get_width());
@@ -417,7 +419,6 @@ void SpinBox::_notification(int p_what) {
417419
_update_text(true);
418420
_compute_sizes();
419421

420-
RID ci = get_canvas_item();
421422
Size2i size = get_size();
422423

423424
Ref<StyleBox> up_stylebox = theme_cache.up_base_stylebox;
@@ -457,9 +458,6 @@ void SpinBox::_notification(int p_what) {
457458
down_icon_modulate = theme_cache.down_hover_icon_modulate;
458459
}
459460

460-
int updown_icon_left = sizing_cache.buttons_left + (sizing_cache.buttons_width - theme_cache.updown_icon->get_width()) / 2;
461-
int updown_icon_top = (size.height - theme_cache.updown_icon->get_height()) / 2;
462-
463461
// Compute center icon positions once we know which one is used.
464462
int up_icon_left = sizing_cache.buttons_left + (sizing_cache.buttons_width - up_icon->get_width()) / 2;
465463
int up_icon_top = (sizing_cache.button_up_height - up_icon->get_height()) / 2;
@@ -474,8 +472,16 @@ void SpinBox::_notification(int p_what) {
474472
draw_style_box(up_stylebox, Rect2(sizing_cache.buttons_left, 0, sizing_cache.buttons_width, sizing_cache.button_up_height));
475473
draw_style_box(down_stylebox, Rect2(sizing_cache.buttons_left, sizing_cache.second_button_top, sizing_cache.buttons_width, sizing_cache.button_down_height));
476474

475+
#ifndef DISABLE_DEPRECATED
476+
if (theme_cache.is_updown_assigned) {
477+
int updown_icon_left = sizing_cache.buttons_left + (sizing_cache.buttons_width - theme_cache.updown_icon->get_width()) / 2;
478+
int updown_icon_top = (size.height - theme_cache.updown_icon->get_height()) / 2;
479+
480+
theme_cache.updown_icon->draw(get_canvas_item(), Point2i(updown_icon_left, updown_icon_top));
481+
break; // If updown is a valid texture, skip other arrows (for compatibility).
482+
}
483+
#endif
477484
// Draw arrows.
478-
theme_cache.updown_icon->draw(ci, Point2i(updown_icon_left, updown_icon_top));
479485
draw_texture(up_icon, Point2i(up_icon_left, up_icon_top), up_icon_modulate);
480486
draw_texture(down_icon, Point2i(down_icon_left, down_icon_top), down_icon_modulate);
481487

@@ -503,6 +509,9 @@ void SpinBox::_notification(int p_what) {
503509
} break;
504510

505511
case NOTIFICATION_THEME_CHANGED: {
512+
#ifndef DISABLE_DEPRECATED
513+
theme_cache.is_updown_assigned = !theme_cache.updown_icon->get_size().is_zero_approx();
514+
#endif
506515
callable_mp((Control *)this, &Control::update_minimum_size).call_deferred();
507516
callable_mp((Control *)get_line_edit(), &Control::update_minimum_size).call_deferred();
508517
} break;
@@ -647,9 +656,9 @@ void SpinBox::_bind_methods() {
647656
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, SpinBox, buttons_width);
648657
#ifndef DISABLE_DEPRECATED
649658
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, SpinBox, set_min_buttons_width_from_icons);
650-
#endif
651659

652660
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, SpinBox, updown_icon, "updown");
661+
#endif
653662
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, SpinBox, up_icon, "up");
654663
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, SpinBox, up_hover_icon, "up_hover");
655664
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, SpinBox, up_pressed_icon, "up_pressed");

scene/gui/spin_box.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class SpinBox : public Range {
102102
inline int _get_widest_button_icon_width();
103103

104104
struct ThemeCache {
105-
Ref<Texture2D> updown_icon;
106105
Ref<Texture2D> up_icon;
107106
Ref<Texture2D> up_hover_icon;
108107
Ref<Texture2D> up_pressed_icon;
@@ -137,6 +136,8 @@ class SpinBox : public Range {
137136
int field_and_buttons_separation = 0;
138137
int buttons_width = 0;
139138
#ifndef DISABLE_DEPRECATED
139+
Ref<Texture2D> updown_icon;
140+
bool is_updown_assigned = false;
140141
bool set_min_buttons_width_from_icons = false;
141142
#endif
142143
} theme_cache;

0 commit comments

Comments
 (0)