diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/font.cpp | 79 | ||||
-rw-r--r-- | ui/window.cpp | 3 |
2 files changed, 43 insertions, 39 deletions
diff --git a/ui/font.cpp b/ui/font.cpp index b6669b0..ebd29d0 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -1,6 +1,7 @@ #include "font.h" #include <algorithm> #include <cctype> +#include <format> #include <ft2build.h> #include FT_FREETYPE_H #include "gl_traits.h" @@ -15,49 +16,51 @@ // IWYU pragma: no_forward_declare FT_LibraryRec_ -std::string -FT_Error_StringSafe(FT_Error err) -{ - if (const auto errstr = FT_Error_String(err)) { - return {errstr}; +namespace { + std::string + FT_Error_StringSafe(FT_Error err) + { + if (const auto errstr = FT_Error_String(err)) { + return {errstr}; + } + return std::format("Unknown FT error: {}", err); } - return std::to_string(err); -} -template<auto Func, typename... Args> -void -FT_Check(Args &&... args) -{ - if (const auto err = Func(std::forward<Args>(args)...)) { - throw std::runtime_error {std::string {"FreeType error: "} + FT_Error_StringSafe(err)}; + template<auto Func, typename... Args> + void + FT_Check(Args &&... args) + { + if (const auto err = Func(std::forward<Args>(args)...)) { + throw std::runtime_error {std::format("FreeType error: {}", FT_Error_StringSafe(err))}; + } } -} -const std::string BASIC_CHARS = []() { - std::string chars; - for (char c {}; c >= 0; c++) { - if (isgraph(c)) { - chars += c; + const std::string BASIC_CHARS = []() { + std::string chars {"£€²³"}; + for (char c {}; c >= 0; c++) { + if (isgraph(c)) { + chars += c; + } } - } - return chars + "£€²³"; -}(); - -using FT = glRef<FT_Library, - []() { - FT_Library ft {}; - FT_Check<FT_Init_FreeType>(&ft); - return ft; - }, - FT_Done_FreeType>; - -using Face = glRef<FT_Face, - [](FT_Library ft, const char * const name) { - FT_Face face {}; - FT_Check<FT_New_Face>(ft, name, 0, &face); - return face; - }, - FT_Done_Face>; + return chars; + }(); + + using FT = glRef<FT_Library, + []() { + FT_Library ft {}; + FT_Check<FT_Init_FreeType>(&ft); + return ft; + }, + FT_Done_FreeType>; + + using Face = glRef<FT_Face, + [](FT_Library ft, const char * const name) { + FT_Face face {}; + FT_Check<FT_New_Face>(ft, name, 0, &face); + return face; + }, + FT_Done_Face>; +} Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)} { diff --git a/ui/window.cpp b/ui/window.cpp index 6855aa0..dd488d7 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,5 +1,6 @@ #include "window.h" #include "uiComponent.h" +#include <format> #include <glad/gl.h> #include <glm/glm.hpp> #include <stdexcept> @@ -9,7 +10,7 @@ Window::GLInitHelper::GLInitHelper() [[maybe_unused]] static auto init = []() { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) if (const auto version = gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress)); version < 30003) { - throw std::runtime_error {"Insufficient OpenGL version: " + std::to_string(version)}; + throw std::runtime_error {std::format("Insufficient OpenGL version: {}", version)}; } else { return version; |