Slider: Add tick position property and tick offset theme item

Allow ticks to be placed at the top, bottom, or center with custom offset.
This commit is contained in:
LuoZhihao 2025-06-09 12:36:08 +08:00
parent 9e02194297
commit 257c6ebe3c
6 changed files with 97 additions and 4 deletions

View file

@ -35,6 +35,15 @@
class Slider : public Range {
GDCLASS(Slider, Range);
public:
enum TickPosition {
TICK_POSITION_BOTTOM_RIGHT,
TICK_POSITION_TOP_LEFT,
TICK_POSITION_BOTH,
TICK_POSITION_CENTER,
};
private:
struct Grab {
int pos = 0;
double uvalue = 0.0; // Value at `pos`.
@ -43,6 +52,8 @@ class Slider : public Range {
} grab;
int ticks = 0;
TickPosition ticks_position = TICK_POSITION_BOTTOM_RIGHT;
bool mouse_inside = false;
Orientation orientation;
double custom_step = -1.0;
@ -65,6 +76,7 @@ class Slider : public Range {
bool center_grabber = false;
int grabber_offset = 0;
int tick_offset = 0;
} theme_cache;
protected:
@ -72,6 +84,7 @@ protected:
virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
void _validate_property(PropertyInfo &p_property) const;
static void _bind_methods();
public:
@ -86,6 +99,9 @@ public:
void set_ticks_on_borders(bool);
bool get_ticks_on_borders() const;
void set_ticks_position(TickPosition p_ticks_position);
TickPosition get_ticks_position() const;
void set_editable(bool p_editable);
bool is_editable() const;
@ -95,6 +111,8 @@ public:
Slider(Orientation p_orientation = VERTICAL);
};
VARIANT_ENUM_CAST(Slider::TickPosition);
class HSlider : public Slider {
GDCLASS(HSlider, Slider);