Redesigned slider to support customizing the size of the Scrubber.
This commit is contained in:
@@ -18,56 +18,53 @@
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
T roundMultiple( T value, T multiple )
|
||||
{
|
||||
if (multiple == 0) return value;
|
||||
return static_cast<T>(std::round(static_cast<double>(value)/static_cast<double>(multiple))*static_cast<double>(multiple));
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Scrubber {
|
||||
public:
|
||||
Color4 color;
|
||||
UDim2 size;
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// A slider is a widget with a handle which can be pulled back and forth to change the value.
|
||||
class Slider : public Rect, public Clickable, public Hoverable
|
||||
{
|
||||
public:
|
||||
/// Invoked when the value of the slider is changed, usually by the user interacting with it.
|
||||
Event<float> ValueChanged;
|
||||
|
||||
/// The default constructor initializes member variables to reasonable defaults.
|
||||
Slider();
|
||||
/// Constructs a slider by specifying it's parent widget.
|
||||
explicit Slider(JUI::Widget* parent);
|
||||
|
||||
/// @return The minimum value allowed by the slider.
|
||||
[[nodiscard]] float Minimum() const;
|
||||
/// @return The maximum value allowed by the slider.
|
||||
[[nodiscard]] float Maximum() const;
|
||||
/// @return The increments the slider moves in.
|
||||
[[nodiscard]] float Interval() const;
|
||||
[[nodiscard]] float CurrentValue() const;
|
||||
|
||||
[[nodiscard]] Color4 ScrubberColor() const;
|
||||
[[nodiscard]] float ScrubberWidth() const;
|
||||
/// @note Deprecated in favor of Slider::ScrubberSize().
|
||||
[[deprecated]] [[nodiscard]] float ScrubberWidth() const;
|
||||
[[nodiscard]] UDim2 ScrubberSize() const;
|
||||
[[nodiscard]] float ScrubberRounding() const;
|
||||
|
||||
/// Returns whether the slider is currently being dragged by the user.
|
||||
[[nodiscard]] bool Dragging() const;
|
||||
[[nodiscard]] float Range() const;
|
||||
|
||||
/// Sets the minimum value allowed by the slider.
|
||||
void Minimum(float min);
|
||||
void Maximum(float max);
|
||||
void Interval(float inter);
|
||||
void CurrentValue(float value);
|
||||
|
||||
/// @return The percentage of the slider, in the range [0, 1].
|
||||
float Percentage() const;
|
||||
|
||||
/// Sets the percentage of the slider, in the range [0, 1]. The percentage is the underlying representation used interally.
|
||||
void Percentage(float value);
|
||||
|
||||
void ScrubberColor(const Color4& color);
|
||||
void ScrubberWidth(float width);
|
||||
/// @note Deprecated in favor of Slider::ScrubberSize().
|
||||
[[deprecated]] void ScrubberWidth(float width);
|
||||
void ScrubberSize(const UDim2& size);
|
||||
void ScrubberRounding(float rounding);
|
||||
|
||||
void SetDragging(bool value);
|
||||
|
||||
void OnClick(const J3ML::LinearAlgebra::Vector2 &MousePos, const JUI::MouseButton &MouseButton) override;
|
||||
@@ -75,7 +72,13 @@ namespace JUI
|
||||
void OnHover(const J3ML::LinearAlgebra::Vector2 &MousePos) override;
|
||||
void OnExit(const J3ML::LinearAlgebra::Vector2 &MousePos) override;
|
||||
void Update(float delta) override;
|
||||
|
||||
Vector2 GetScrubberAbsolutePosition() const;
|
||||
Vector2 GetScrubberAbsoluteSize() const;
|
||||
|
||||
|
||||
void Draw() override;
|
||||
|
||||
void InnerDraw() override;
|
||||
|
||||
protected:
|
||||
@@ -85,8 +88,9 @@ namespace JUI
|
||||
float current;
|
||||
float percentage = 0.f;
|
||||
bool dragging = false;
|
||||
float scrubber_width = 20;
|
||||
UDim2 scrubber_size {20_px, 100_percent};
|
||||
Color4 scrubber_color = Colors::White;
|
||||
float scrubber_rounding = 0.f;
|
||||
private:
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user