56 float trackY =
_y + (
_height - trackHeight) / 2.0F;
63 float valueRatio = 0.0F;
67 valueRatio = std::clamp(valueRatio, 0.0F, 1.0F);
68 float filledWidth =
_width * valueRatio;
71 if (filledWidth > 0) {
73 static_cast<int>(filledWidth),
static_cast<int>(trackHeight),
78 float handleX =
_x + filledWidth;
176 _x = (
static_cast<float>(screenWidth) -
_width) / 2.0F;
179 _y = (
static_cast<float>(screenHeight) -
_height) / 2.0F;
182 _x = (
static_cast<float>(screenWidth) -
_width) / 2.0F;
183 _y = (
static_cast<float>(screenHeight) -
_height) / 2.0F;
208 float valueRatio = 0.0F;
212 valueRatio = std::clamp(valueRatio, 0.0F, 1.0F);
213 float handleX =
_x +
_width * valueRatio;
217 float dx =
static_cast<float>(mouseX) - handleX;
218 float dy =
static_cast<float>(mouseY) - handleY;
219 float distanceSquared = dx * dx + dy * dy;
228 return static_cast<float>(mouseX) >=
_x &&
static_cast<float>(mouseX) <=
_x +
_width &&
229 static_cast<float>(mouseY) >=
_y &&
static_cast<float>(mouseY) <=
_y +
_height;
236 float relativeX =
static_cast<float>(mouseX) -
_x;
237 float valueRatio = relativeX /
_width;
240 valueRatio = std::max(0.0F, std::min(1.0F, valueRatio));
Abstract interface for graphics rendering operations.
virtual bool IsMouseButtonDown(int button) const =0
Check if a mouse button is currently being held down.
virtual void DrawCircleFilled(int x, int y, int radius, unsigned int color)=0
Draw a filled circle.
virtual int GetMouseX() const =0
Get the current X position of the mouse cursor.
virtual int GetScreenHeight() const =0
Get the screen height (same as window height)
virtual int GetMouseY() const =0
Get the current Y position of the mouse cursor.
virtual bool IsMouseButtonPressed(int button) const =0
Check if a mouse button was pressed (triggered once when button goes down)
virtual int GetScreenWidth() const =0
Get the screen width (same as window width)
virtual void DrawCircle(int x, int y, int radius, unsigned int color)=0
Draw a circle outline.
virtual void DrawRectangle(int x, int y, int width, int height, unsigned int color)=0
Draw a filled rectangle (alias for DrawRectFilled)
void Render() override
Render the slider.
void SetMinValue(float minValue) override
Set the minimum value.
void SetValue(float value) override
Set the current value.
void SetHandleHoverColor(unsigned int color) override
Set the handle hover color.
void SetOnValueChanged(std::function< void(float)> callback) override
Set callback invoked when value changes.
std::function< void(float)> _onValueChanged
Align GetAlign() const override
Get the current alignment mode.
void SetEnabled(bool enabled) override
Enable or disable the slider.
unsigned int _handleColor
bool IsMouseOverTrack() const
Check whether the mouse cursor is over the track.
unsigned int _handleHoverColor
void Update() override
Update the slider internal state (hover, drag).
unsigned int _filledColor
bool IsEnabled() const override
Check if the slider is enabled.
void SetSize(float width, float height) override
Set the slider size.
void SetFilledColor(unsigned int color) override
Set the filled track color (portion before handle).
void ApplyAlignment() override
Apply the current alignment mode to the position.
void ClampValue()
Clamp value to [min, max] range.
static constexpr float TRACK_HEIGHT_RATIO
bool IsMouseOverHandle() const
Check whether the mouse cursor is over the handle.
static constexpr float HANDLE_RADIUS
void SetTrackColor(unsigned int color) override
Set the track color (unfilled portion).
void SetAlign(Align align) override
Set alignment mode relative to the window.
void UpdateValueFromMouse()
Update value based on mouse position.
void SetHandleColor(unsigned int color) override
Set the handle color.
RaylibSlider(Graphics::IGraphics &graphics)
Construct a new RaylibSlider.
void GetSize(float &width, float &height) const override
Get the current size of the slider.
void GetPosition(float &x, float &y) const override
Get the current top-left position of the slider.
void SetMaxValue(float maxValue) override
Set the maximum value.
Graphics::IGraphics & _graphics
float GetValue() const override
Get the current value.
void SetPosition(float x, float y) override
Set the top-left position of the slider.
Align
Alignment modes relative to the current window.
@ CENTER_VERTICAL
Center on the Y axis.
@ CENTER_BOTH
Center on both axes.
@ CENTER_HORIZONTAL
Center on the X axis.