Files
Renderive/render_2D/axis/Numeric_Axis.h
T
2026-08-11 23:17:03 +08:00

71 lines
2.0 KiB
C++

#pragma once
#include "Abs_Axis.h"
#include "Axis_Builder.h"
#include <renderive/base/property/Attach_Builder.hpp>
#include <renderive/state/Double_State_Strategy.hpp>
namespace renderive {
struct Axis_Properties : Axis_Base_Properties {
Range coordinates{0.0, 20.0};
int precision = 2;
bool wheel{};
bool drag{};
};
namespace detail {
struct Numeric_Axis_State {
Range coordinates{0.0, 20.0};
int precision = 2;
bool wheel{};
bool drag{};
};
struct Axis_Interaction_State {
bool dragging{};
PointF last_pointer{};
};
class LIB_DECL Axis_Control : public Abs_Axis, public Event_Handler {
public:
Axis_Control(Plot_Core& plot, const Axis_Properties& properties);
[[nodiscard]] Range coord_range() const override;
[[nodiscard]] int label_precision() const;
void set_label_precision(int value);
[[nodiscard]] double coord_start() const;
void set_coord_start(double value);
[[nodiscard]] double coord_length() const;
void set_coord_length(double value);
void set_coord_range(Range range);
void set_use_wheel(bool value);
void set_use_drag(bool value);
[[nodiscard]] bool use_wheel() const;
[[nodiscard]] bool use_drag() const;
void handle_event(const Event& event) override;
[[nodiscard]] std::string tick_label(double tick) const override;
void publish() override;
[[nodiscard]] std::uint64_t state_revision() const override;
protected:
[[nodiscard]] Numeric_Axis_State numeric_state() const;
[[nodiscard]] Numeric_Axis_State render_numeric_state() const;
private:
struct Numeric_Base {};
struct Interaction_Base {};
using Numeric_State = Double_State_Strategy<Numeric_Base, Numeric_Axis_State>;
using Interaction_State = Double_State_Strategy<Interaction_Base, Axis_Interaction_State>;
Numeric_State numeric_;
Interaction_State interaction_;
};
} // namespace detail
using Axis = Attach_Builder<detail::Axis_Control, Axis_Properties, detail::Axis_Renderable_Builder>;
} // namespace renderive