Skip to content

Commit d06a1ee

Browse files
committed
Slider: Add bottom&top tick theme item
1 parent b5bdb88 commit d06a1ee

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

doc/classes/Slider.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<theme_item name="grabber_offset" data_type="constant" type="int" default="0">
4545
Vertical or horizontal offset of the grabber.
4646
</theme_item>
47+
<theme_item name="tick_bottom_offset" data_type="constant" type="int" default="2">
48+
Vertical or horizontal offset of the bottom tick.
49+
</theme_item>
50+
<theme_item name="tick_top_offset" data_type="constant" type="int" default="2">
51+
Vertical or horizontal offset of the top tick.
52+
</theme_item>
4753
<theme_item name="grabber" data_type="icon" type="Texture2D">
4854
The texture for the grabber (the draggable element).
4955
</theme_item>
@@ -53,8 +59,11 @@
5359
<theme_item name="grabber_highlight" data_type="icon" type="Texture2D">
5460
The texture for the grabber when it's focused.
5561
</theme_item>
56-
<theme_item name="tick" data_type="icon" type="Texture2D">
57-
The texture for the ticks, visible when [member Slider.tick_count] is greater than 0.
62+
<theme_item name="tick_bottom" data_type="icon" type="Texture2D">
63+
The texture for the ticks in the bottom of the slider, visible when [member Slider.tick_count] is greater than 0.
64+
</theme_item>
65+
<theme_item name="tick_top" data_type="icon" type="Texture2D">
66+
The texture for the ticks in the top of the slider, visible when [member Slider.tick_count] is greater than 0.
5867
</theme_item>
5968
<theme_item name="grabber_area" data_type="style" type="StyleBox">
6069
The background of the area to the left or bottom of the grabber.

scene/gui/slider.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ void Slider::_notification(int p_what) {
267267
double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio();
268268

269269
Ref<StyleBox> style = theme_cache.slider_style;
270-
Ref<Texture2D> tick = theme_cache.tick_icon;
270+
Ref<Texture2D> tick_bottom = theme_cache.tick_bottom_icon;
271+
Ref<Texture2D> tick_top = theme_cache.tick_top_icon;
271272

272273
bool highlighted = editable && (mouse_inside || has_focus());
273274
Ref<Texture2D> grabber;
@@ -296,13 +297,17 @@ void Slider::_notification(int p_what) {
296297
grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, Math::round(size.height - areasize * ratio - grabber->get_height() / 2 + grabber_shift)), Size2i(widget_width, Math::round(areasize * ratio + grabber->get_height() / 2 - grabber_shift))));
297298

298299
if (ticks > 1) {
299-
int grabber_offset = (grabber->get_height() / 2 - tick->get_height() / 2);
300+
int grabber_offset_bottom = (grabber->get_height() / 2 - tick_bottom->get_height() / 2);
301+
int grabber_offset_top = (grabber->get_height() / 2 - tick_top->get_height() / 2);
300302
for (int i = 0; i < ticks; i++) {
301303
if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
302304
continue;
303305
}
304-
int ofs = (i * areasize / (ticks - 1)) + grabber_offset - grabber_shift;
305-
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
306+
int ofs_bottom = (i * areasize / (ticks - 1)) + grabber_offset_bottom - grabber_shift;
307+
tick_bottom->draw(ci, Point2i(widget_width + (size.width - widget_width) / 2 + theme_cache.tick_bottom_offset, ofs_bottom));
308+
309+
int ofs_top = (i * areasize / (ticks - 1)) + grabber_offset_top - grabber_shift;
310+
tick_top->draw(ci, Point2i((size.width - widget_width) / 2 - tick_top->get_width() - theme_cache.tick_top_offset, ofs_top));
306311
}
307312
}
308313
grabber->draw(ci, Point2i(size.width / 2 - grabber->get_width() / 2 + theme_cache.grabber_offset, size.height - ratio * areasize - grabber->get_height() + grabber_shift));
@@ -321,13 +326,17 @@ void Slider::_notification(int p_what) {
321326
}
322327

323328
if (ticks > 1) {
324-
int grabber_offset = (grabber->get_width() / 2 - tick->get_width() / 2);
329+
int grabber_offset_bottom = (grabber->get_width() / 2 - tick_bottom->get_width() / 2);
330+
int grabber_offset_top = (grabber->get_width() / 2 - tick_top->get_width() / 2);
325331
for (int i = 0; i < ticks; i++) {
326332
if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
327333
continue;
328334
}
329-
int ofs = (i * areasize / (ticks - 1)) + grabber_offset + grabber_shift;
330-
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
335+
int ofs_bottom = (i * areasize / (ticks - 1)) + grabber_offset_bottom + grabber_shift;
336+
tick_bottom->draw(ci, Point2i(ofs_bottom, widget_height + (size.height - widget_height) / 2 + theme_cache.tick_bottom_offset));
337+
338+
int ofs_top = (i * areasize / (ticks - 1)) + grabber_offset_top + grabber_shift;
339+
tick_top->draw(ci, Point2i(ofs_top, (size.height - widget_height) / 2 - tick_top->get_height() - theme_cache.tick_top_offset));
331340
}
332341
}
333342
grabber->draw(ci, Point2i((rtl ? 1 - ratio : ratio) * areasize + grabber_shift, size.height / 2 - grabber->get_height() / 2 + theme_cache.grabber_offset));
@@ -419,10 +428,13 @@ void Slider::_bind_methods() {
419428
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, grabber_icon, "grabber");
420429
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, grabber_hl_icon, "grabber_highlight");
421430
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, grabber_disabled_icon, "grabber_disabled");
422-
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, tick_icon, "tick");
431+
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, tick_bottom_icon, "tick_bottom");
432+
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, Slider, tick_top_icon, "tick_top");
423433

424434
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Slider, center_grabber);
425435
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Slider, grabber_offset);
436+
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Slider, tick_bottom_offset);
437+
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Slider, tick_top_offset);
426438
}
427439

428440
Slider::Slider(Orientation p_orientation) {

scene/gui/slider.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ class Slider : public Range {
6161
Ref<Texture2D> grabber_icon;
6262
Ref<Texture2D> grabber_hl_icon;
6363
Ref<Texture2D> grabber_disabled_icon;
64-
Ref<Texture2D> tick_icon;
64+
Ref<Texture2D> tick_bottom_icon;
65+
Ref<Texture2D> tick_top_icon;
6566

6667
bool center_grabber = false;
6768
int grabber_offset = 0;
69+
int tick_bottom_offset = 2;
70+
int tick_top_offset = 2;
6871
} theme_cache;
6972

7073
protected:

scene/theme/default_theme.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,13 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
596596
theme->set_icon("grabber", "HSlider", icons["slider_grabber"]);
597597
theme->set_icon("grabber_highlight", "HSlider", icons["slider_grabber_hl"]);
598598
theme->set_icon("grabber_disabled", "HSlider", icons["slider_grabber_disabled"]);
599-
theme->set_icon("tick", "HSlider", icons["hslider_tick"]);
599+
theme->set_icon("tick_bottom", "HSlider", icons["hslider_tick"]);
600+
theme->set_icon("tick_top", "HSlider", empty_icon);
600601

601602
theme->set_constant("center_grabber", "HSlider", 0);
602603
theme->set_constant("grabber_offset", "HSlider", 0);
604+
theme->set_constant("tick_bottom_offset", "HSlider", 2);
605+
theme->set_constant("tick_top_offset", "HSlider", 2);
603606

604607
// VSlider
605608

@@ -610,10 +613,13 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
610613
theme->set_icon("grabber", "VSlider", icons["slider_grabber"]);
611614
theme->set_icon("grabber_highlight", "VSlider", icons["slider_grabber_hl"]);
612615
theme->set_icon("grabber_disabled", "VSlider", icons["slider_grabber_disabled"]);
613-
theme->set_icon("tick", "VSlider", icons["vslider_tick"]);
616+
theme->set_icon("tick_bottom", "VSlider", icons["vslider_tick"]);
617+
theme->set_icon("tick_top", "VSlider", empty_icon);
614618

615619
theme->set_constant("center_grabber", "VSlider", 0);
616620
theme->set_constant("grabber_offset", "VSlider", 0);
621+
theme->set_constant("tick_bottom_offset", "VSlider", 2);
622+
theme->set_constant("tick_top_offset", "VSlider", 2);
617623

618624
// SpinBox
619625

scene/theme/icons/hslider_tick.svg

Lines changed: 1 addition & 1 deletion
Loading

scene/theme/icons/vslider_tick.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)