7#include "../macros.hpp"
13hi_export_module(hikogui.utility.units);
15hi_export
namespace hi {
inline namespace v1 {
17template<
typename Tag,
typename T,
typename Ratio = std::ratio<1>>
23 constexpr unit(
unit const&)
noexcept =
default;
24 constexpr unit(
unit&&)
noexcept =
default;
25 constexpr unit& operator=(
unit const&)
noexcept =
default;
26 constexpr unit& operator=(
unit&&)
noexcept =
default;
28 constexpr explicit unit(value_type value) noexcept : _value(value) {}
30 template<
typename OtherT,
typename OtherRatio>
32 requires(not std::is_same_v<unit<Tag, OtherT, OtherRatio>,
unit>)
37 tmp *= conversion::den;
38 tmp /= conversion::num;
42 template<
typename OtherT,
typename OtherRatio>
44 requires(not std::is_same_v<unit<Tag, OtherT, OtherRatio>,
unit>)
49 tmp *= conversion::den;
50 tmp /= conversion::num;
55 [[nodiscard]]
constexpr value_type count()
const noexcept
60 [[nodiscard]]
constexpr unit operator*(value_type
const& rhs)
const noexcept
62 return unit{count() * rhs};
65 [[nodiscard]]
constexpr unit operator/(value_type
const& rhs)
const noexcept
67 return unit{count() / rhs};
70 [[nodiscard]]
constexpr unit& operator+=(
unit const& rhs)
noexcept
72 _value += rhs.count();
76 [[nodiscard]]
constexpr unit& operator-=(
unit const& rhs)
noexcept
78 _value -= rhs.count();
82 [[nodiscard]]
constexpr unit&
operator*=(value_type
const& rhs)
noexcept
88 [[nodiscard]]
constexpr unit& operator/=(value_type
const& rhs)
noexcept
100template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
105 std::common_type_t<T1, T2>,
106 std::conditional_t<std::ratio_less_v<Ratio1, Ratio2>, Ratio1, Ratio2>>;
110namespace hi {
inline namespace v1 {
112template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
113[[nodiscard]]
constexpr bool operator==(unit<Tag, T1, Ratio1>
const& lhs, unit<Tag, T2, Ratio2>
const& rhs)
noexcept
115 using common_type = std::common_type_t<unit<Tag, T1, Ratio1>, unit<Tag, T2, Ratio2>>;
118 hilet rhs_ = common_type{rhs};
120 return lhs_.count() == rhs_.count();
123template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
128 hilet lhs_ = common_type{lhs};
129 hilet rhs_ = common_type{rhs};
131 return lhs_.count() <=> rhs_.count();
134template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
139 hilet lhs_ = common_type{lhs};
140 hilet rhs_ = common_type{rhs};
142 return common_type{lhs_.count() + rhs_.count()};
145template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
150 hilet lhs_ = common_type{lhs};
151 hilet rhs_ = common_type{rhs};
153 return common_type{lhs_.count() - rhs_.count()};
156template<
typename Tag,
typename T1,
typename Ratio1,
typename T2,
typename Ratio2>
161 hilet lhs_ = common_type{lhs};
162 hilet rhs_ = common_type{rhs};
164 return lhs_.count() / rhs_.count();
Functions for casting values between types savely.
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:22
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
unit< em_length_tag, double > em_quads
Em-quad: A font's line-height.
Definition units.hpp:199
unit< px_length_tag, double > pixels
A physical pixel on a display.
Definition units.hpp:195
unit< si_length_tag, double, std::ratio< 254, 960 '000 >::type > dips
Device Independent Pixels: 1/96 inch.
Definition units.hpp:191
unit< si_length_tag, double, std::ratio< 254, 10 '000 >::type > inches
Inch: 254 mm.
Definition units.hpp:184
unit< si_length_tag, double, std::ratio< 254, 720 '000 >::type > points
Points: 1/72 inch.
Definition units.hpp:180
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
constexpr Lhs & operator*=(Lhs &lhs, Rhs const &rhs) noexcept
Inplace geometric translation.
Definition transform.hpp:432
constexpr Out wide_cast(In const &rhs) noexcept
Cast to a type which can hold all values from the input type.
Definition cast.hpp:175