mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 15:33:26 +00:00
Adds formatters for Angle and Color
Adds formatters for `omath::Angle` and `omath::Color` to allow for easy formatting using `std::format`. This allows users to easily output Angle and Color values in a human-readable format.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "omath/angles.hpp"
|
#include "omath/angles.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -149,3 +150,17 @@ namespace omath
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
template<class Type, Type min, Type max, omath::AngleFlags flags>
|
||||||
|
struct std::formatter<omath::Angle<Type, min, max, flags>> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Angle<Type, min, max, flags>& deg, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "{}deg", deg.as_degrees());
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -167,3 +167,21 @@ namespace omath
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
template<>
|
||||||
|
struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr auto parse(std::format_parse_context& ctx)
|
||||||
|
{
|
||||||
|
return ctx.begin();
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static auto format(const omath::Color& col, std::format_context& ctx)
|
||||||
|
{
|
||||||
|
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
|
||||||
|
static_cast<int>(col.x * 255.f),
|
||||||
|
static_cast<int>(col.y * 255.f),
|
||||||
|
static_cast<int>(col.z * 255.f),
|
||||||
|
static_cast<int>(col.w * 255.f));
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user