summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-06-04 21:14:45 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-06-04 21:14:45 +0100
commit6e94848aec5d42eed5f9e1f5548ade26915ce90b (patch)
treeb6cf5bc39f7da4c8853491da4008c29406b135f3 /ui
parentTidy of glRef (diff)
downloadilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.tar.bz2
ilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.tar.xz
ilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.zip
Tidy many stringy messes with std::format
Diffstat (limited to 'ui')
-rw-r--r--ui/font.cpp79
-rw-r--r--ui/window.cpp3
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;