mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
improved encoding for formating
This commit is contained in:
@@ -39,6 +39,7 @@ else ()
|
|||||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ if (OMATH_BUILD_TESTS)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (OMATH_BUILD_BENCHMARK)
|
if (OMATH_BUILD_BENCHMARK)
|
||||||
|
set(BENCHMARK_ENABLE_TESTING OFF)
|
||||||
add_subdirectory(benchmark)
|
add_subdirectory(benchmark)
|
||||||
endif ()
|
endif ()
|
||||||
@@ -174,13 +174,30 @@ struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
|
|||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class FormatContext>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static auto format(const omath::Color& col, std::format_context& ctx)
|
static auto format(const omath::Color& col, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
|
if constexpr (std::is_same_v<std::format_context::char_type, char>)
|
||||||
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
|
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
|
||||||
static_cast<int>(col.x * 255.f),
|
static_cast<int>(col.x * 255.f),
|
||||||
static_cast<int>(col.y * 255.f),
|
static_cast<int>(col.y * 255.f),
|
||||||
static_cast<int>(col.z * 255.f),
|
static_cast<int>(col.z * 255.f),
|
||||||
static_cast<int>(col.w * 255.f));
|
static_cast<int>(col.w * 255.f));
|
||||||
|
if constexpr (std::is_same_v<std::format_context::char_type, wchar_t>)
|
||||||
|
return std::format_to(ctx.out(), L"[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));
|
||||||
|
|
||||||
|
if constexpr (std::is_same_v<std::format_context::char_type, char8_t>)
|
||||||
|
return std::format_to(ctx.out(), u8"[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));
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user