@@ -308,7 +308,19 @@ void Slider::_notification(int p_what) {
308308 continue ;
309309 }
310310 int ofs = (i * areasize / (ticks - 1 )) + grabber_offset - grabber_shift;
311- tick->draw (ci, Point2i ((size.width - widget_width) / 2 , ofs));
311+
312+ if (ticks_position == TICK_POSITION_BOTTOM_RIGHT || ticks_position == TICK_POSITION_BOTH) {
313+ tick->draw (ci, Point2i (widget_width + (size.width - widget_width) / 2 + theme_cache.tick_offset , ofs));
314+ }
315+
316+ if (ticks_position == TICK_POSITION_TOP_LEFT || ticks_position == TICK_POSITION_BOTH) {
317+ Point2i pos = Point2i ((size.width - widget_width) / 2 - tick->get_width () - theme_cache.tick_offset , ofs);
318+ tick->draw_rect (ci, Rect2i (pos, Size2i (-tick->get_width (), tick->get_height ())));
319+ }
320+
321+ if (ticks_position == TICK_POSITION_CENTER) {
322+ tick->draw (ci, Point2i ((size.width - tick->get_width ()) / 2 + theme_cache.tick_offset , ofs));
323+ }
312324 }
313325 }
314326 grabber->draw (ci, Point2i (size.width / 2 - grabber->get_width () / 2 + theme_cache.grabber_offset , size.height - ratio * areasize - grabber->get_height () + grabber_shift));
@@ -333,7 +345,19 @@ void Slider::_notification(int p_what) {
333345 continue ;
334346 }
335347 int ofs = (i * areasize / (ticks - 1 )) + grabber_offset + grabber_shift;
336- tick->draw (ci, Point2i (ofs, (size.height - widget_height) / 2 ));
348+
349+ if (ticks_position == TICK_POSITION_BOTTOM_RIGHT || ticks_position == TICK_POSITION_BOTH) {
350+ tick->draw (ci, Point2i (ofs, widget_height + (size.height - widget_height) / 2 + theme_cache.tick_offset ));
351+ }
352+
353+ if (ticks_position == TICK_POSITION_TOP_LEFT || ticks_position == TICK_POSITION_BOTH) {
354+ Point2i pos = Point2i (ofs, (size.height - widget_height) / 2 - tick->get_height () - theme_cache.tick_offset );
355+ tick->draw_rect (ci, Rect2i (pos, Size2i (tick->get_width (), -tick->get_height ())));
356+ }
357+
358+ if (ticks_position == TICK_POSITION_CENTER) {
359+ tick->draw (ci, Point2i (ofs, (size.height - tick->get_height ()) / 2 + theme_cache.tick_offset ));
360+ }
337361 }
338362 }
339363 grabber->draw (ci, Point2i ((rtl ? 1 - ratio : ratio) * areasize + grabber_shift, size.height / 2 - grabber->get_height () / 2 + theme_cache.grabber_offset ));
@@ -342,6 +366,12 @@ void Slider::_notification(int p_what) {
342366 }
343367}
344368
369+ void Slider::_validate_property (PropertyInfo &p_property) const {
370+ if (p_property.name == " ticks_position" ) {
371+ p_property.hint_string = orientation == VERTICAL ? " Right,Left,Both,Center" : " Bottom,Top,Both,Center" ;
372+ }
373+ }
374+
345375void Slider::set_custom_step (double p_custom_step) {
346376 custom_step = p_custom_step;
347377}
@@ -367,6 +397,10 @@ bool Slider::get_ticks_on_borders() const {
367397 return ticks_on_borders;
368398}
369399
400+ Slider::TickPosition Slider::get_ticks_position () const {
401+ return ticks_position;
402+ }
403+
370404void Slider::set_ticks_on_borders (bool _tob) {
371405 if (ticks_on_borders == _tob) {
372406 return ;
@@ -376,6 +410,15 @@ void Slider::set_ticks_on_borders(bool _tob) {
376410 queue_redraw ();
377411}
378412
413+ void Slider::set_ticks_position (TickPosition p_ticks_position) {
414+ if (ticks_position == p_ticks_position) {
415+ return ;
416+ }
417+
418+ ticks_position = p_ticks_position;
419+ queue_redraw ();
420+ }
421+
379422void Slider::set_editable (bool p_editable) {
380423 if (editable == p_editable) {
381424 return ;
@@ -405,6 +448,9 @@ void Slider::_bind_methods() {
405448 ClassDB::bind_method (D_METHOD (" get_ticks_on_borders" ), &Slider::get_ticks_on_borders);
406449 ClassDB::bind_method (D_METHOD (" set_ticks_on_borders" , " ticks_on_border" ), &Slider::set_ticks_on_borders);
407450
451+ ClassDB::bind_method (D_METHOD (" get_ticks_position" ), &Slider::get_ticks_position);
452+ ClassDB::bind_method (D_METHOD (" set_ticks_position" , " ticks_on_border" ), &Slider::set_ticks_position);
453+
408454 ClassDB::bind_method (D_METHOD (" set_editable" , " editable" ), &Slider::set_editable);
409455 ClassDB::bind_method (D_METHOD (" is_editable" ), &Slider::is_editable);
410456 ClassDB::bind_method (D_METHOD (" set_scrollable" , " scrollable" ), &Slider::set_scrollable);
@@ -417,6 +463,12 @@ void Slider::_bind_methods() {
417463 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scrollable" ), " set_scrollable" , " is_scrollable" );
418464 ADD_PROPERTY (PropertyInfo (Variant::INT, " tick_count" , PROPERTY_HINT_RANGE, " 0,4096,1" ), " set_ticks" , " get_ticks" );
419465 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " ticks_on_borders" ), " set_ticks_on_borders" , " get_ticks_on_borders" );
466+ ADD_PROPERTY (PropertyInfo (Variant::INT, " ticks_position" , PROPERTY_HINT_ENUM), " set_ticks_position" , " get_ticks_position" );
467+
468+ BIND_ENUM_CONSTANT (TICK_POSITION_BOTTOM_RIGHT);
469+ BIND_ENUM_CONSTANT (TICK_POSITION_TOP_LEFT);
470+ BIND_ENUM_CONSTANT (TICK_POSITION_BOTH);
471+ BIND_ENUM_CONSTANT (TICK_POSITION_CENTER);
420472
421473 BIND_THEME_ITEM_CUSTOM (Theme::DATA_TYPE_STYLEBOX, Slider, slider_style, " slider" );
422474 BIND_THEME_ITEM_CUSTOM (Theme::DATA_TYPE_STYLEBOX, Slider, grabber_area_style, " grabber_area" );
@@ -429,6 +481,7 @@ void Slider::_bind_methods() {
429481
430482 BIND_THEME_ITEM (Theme::DATA_TYPE_CONSTANT, Slider, center_grabber);
431483 BIND_THEME_ITEM (Theme::DATA_TYPE_CONSTANT, Slider, grabber_offset);
484+ BIND_THEME_ITEM (Theme::DATA_TYPE_CONSTANT, Slider, tick_offset);
432485}
433486
434487Slider::Slider (Orientation p_orientation) {
0 commit comments