diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-07 13:52:34 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-07 13:52:34 +0800 |
commit | bba3d52af4526ee19bd962c2448d0f8d24d4070b (patch) | |
tree | 592839be6277cb79cf81bb88091c6d0ada0e3cfc /include/cru | |
parent | 6e665c0b9c0d38fe597df04a517833e219bddfc1 (diff) | |
download | cru-bba3d52af4526ee19bd962c2448d0f8d24d4070b.tar.gz cru-bba3d52af4526ee19bd962c2448d0f8d24d4070b.tar.bz2 cru-bba3d52af4526ee19bd962c2448d0f8d24d4070b.zip |
Fix some compile error on macOS.
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/platform/GraphicsBase.h | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h index 3d131e22..fb8d6bdd 100644 --- a/include/cru/platform/GraphicsBase.h +++ b/include/cru/platform/GraphicsBase.h @@ -43,8 +43,12 @@ constexpr bool operator!=(const Point& left, const Point& right) { return !(left == right); } +inline std::string ToUtf8String(const Point& point) { + return std::format("(x: {}, y: {})", point.x, point.y); +} + inline String ToString(const Point& point) { - return String::FromUtf8(std::format("(x: {}, y: {})", point.x, point.y)); + return String::FromUtf8(ToUtf8String(point)); } struct CRU_PLATFORM_API Size final { @@ -84,9 +88,12 @@ constexpr bool operator!=(const Size& left, const Size& right) { return !(left == right); } +inline std::string ToUtf8String(const Size& size) { + return std::format("(width: {}, height: {})", size.width, size.height); +} + inline String ToString(const Size& size) { - return String::FromUtf8( - std::format("(width: {}, height: {})", size.width, size.height)); + return String::FromUtf8(ToUtf8String(size)); } struct Thickness final { @@ -287,3 +294,24 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) { using TextRange = Range; } // namespace cru::platform + +template <typename T> +struct ImplementFormatterByToUtf8String { + template <class ParseContext> + constexpr ParseContext::iterator parse(ParseContext& ctx) const { + return ctx.end(); + } + + template <class FmtContext> + FmtContext::iterator format(const T& object, FmtContext& ctx) const { + return std::ranges::copy(ToUtf8String(object), ctx.out()).out; + } +}; + +template <> +struct std::formatter<cru::platform::Point, char> + : ImplementFormatterByToUtf8String<cru::platform::Point> {}; + +template <> +struct std::formatter<cru::platform::Size, char> + : ImplementFormatterByToUtf8String<cru::platform::Size> {}; |