1 #ifndef TERMOX_WIDGET_WIDGETS_NUMBER_VIEW_HPP
2 #define TERMOX_WIDGET_WIDGETS_NUMBER_VIEW_HPP
10 #include <termox/widget/align.hpp>
11 #include <termox/widget/widgets/label.hpp>
16 template <
typename Number_t>
18 static_assert(std::is_integral_v<Number_t> ||
19 std::is_floating_point_v<Number_t>);
25 Align alignment = Align::Left;
52 [[nodiscard]]
auto value() const noexcept -> Number_t {
return value_; }
62 [[nodiscard]]
auto precision() const noexcept ->
int {
return precision_; }
76 if constexpr (std::is_floating_point_v<Number_t>) {
77 auto ss = std::stringstream{};
82 return std::to_string(
value);
90 template <
typename Number_t>
91 [[nodiscard]]
auto number_view(Number_t initial = 0,
93 Align alignment = Align::Left)
94 -> std::unique_ptr<Number_view<Number_t>>
96 return std::make_unique<Number_view<Number_t>>(initial, precision,
101 template <
typename Number_t>
102 [[nodiscard]]
auto number_view(
103 typename Number_view<Number_t>::Parameters parameters)
104 -> std::unique_ptr<Number_view<Number_t>>
106 return std::make_unique<Number_view<Number_t>>(std::move(parameters));
109 using Int_view = Number_view<int>;
112 [[nodiscard]]
inline auto int_view(
int initial = 0,
114 Align alignment = Align::Left)
115 -> std::unique_ptr<Int_view>
117 return std::make_unique<Int_view>(initial, precision, alignment);
121 [[nodiscard]]
inline auto int_view(Int_view::Parameters parameters)
122 -> std::unique_ptr<Int_view>
124 return std::make_unique<Int_view>(std::move(parameters));
127 using Unsigned_view = Number_view<unsigned int>;
130 [[nodiscard]]
inline auto unsigned_view(
unsigned int initial = 0,
132 Align alignment = Align::Left)
133 -> std::unique_ptr<Unsigned_view>
135 return std::make_unique<Unsigned_view>(initial, precision, alignment);
139 [[nodiscard]]
inline auto unsigned_view(Unsigned_view::Parameters parameters)
140 -> std::unique_ptr<Unsigned_view>
142 return std::make_unique<Unsigned_view>(std::move(parameters));
145 using Double_view = Number_view<double>;
148 [[nodiscard]]
inline auto double_view(
double initial = 0,
150 Align alignment = Align::Left)
151 -> std::unique_ptr<Double_view>
153 return std::make_unique<Double_view>(initial, precision, alignment);
157 [[nodiscard]]
inline auto double_view(Double_view::Parameters parameters)
158 -> std::unique_ptr<Double_view>
160 return std::make_unique<Double_view>(std::move(parameters));
163 using Float_view = Number_view<float>;
166 [[nodiscard]]
inline auto float_view(
float initial = 0,
168 Align alignment = Align::Left)
169 -> std::unique_ptr<Float_view>
171 return std::make_unique<Float_view>(initial, precision, alignment);
175 [[nodiscard]]
inline auto float_view(Float_view::Parameters parameters)
176 -> std::unique_ptr<Float_view>
178 return std::make_unique<Float_view>(std::move(parameters));
A single line of text with alignment, non-editable.
Definition: label.hpp:22
auto alignment() const noexcept -> Align
Return the Align given to set_alignment().
Definition: label.cpp:111
void set_alignment(Align x)
Set text alignment of Label and update display.
Definition: label.cpp:104
void set_text(Glyph_string text)
Set text contents of Label and update display.
Definition: label.cpp:81
Displays a number on a single horizontal line.
Definition: number_view.hpp:17
auto alignment() const noexcept -> Align
Return the Align given to set_alignment().
Definition: label.cpp:111
auto precision() const noexcept -> int
Return the current precision value.
Definition: number_view.hpp:62
Number_view(Number_t initial=0, int precision=2, Align alignment=Align::Left)
Precision is only used if Number_t is floating point.
Definition: number_view.hpp:30
void set_value(Number_t x)
Set a new value to display in the Number_view.
Definition: number_view.hpp:45
void set_precision(int x)
Set a new value for floating point precision to display.
Definition: number_view.hpp:55
auto value() const noexcept -> Number_t
Return the current value.
Definition: number_view.hpp:52
Definition: number_view.hpp:22