From cb2d9f78a874c0544430a15da74c581f5c9503ea Mon Sep 17 00:00:00 2001 From: Wutipong Wongsakuldej Date: Mon, 22 Jan 2024 05:12:59 +0700 Subject: [PATCH] clean up some weirdness. --- main_scene.cpp | 37 ++++++++++++------------- main_scene.hpp | 75 +++++++++++++++++++++++++++++++------------------- 2 files changed, 64 insertions(+), 48 deletions(-) diff --git a/main_scene.cpp b/main_scene.cpp index 97e7cca..19f4864 100644 --- a/main_scene.cpp +++ b/main_scene.cpp @@ -58,7 +58,7 @@ void MainScene::Tick(SDL_Renderer *renderer, Context &ctx) { 0xFF, }; - font.RenderText(renderer, ctx, std::string(buffer.data()), isShape, + font.RenderText(renderer, ctx, std::string(buffer.data()), isShaping, selectedDirection, sdlColor, languages[selectedLanguage].code, scripts[selectedScript].script); } @@ -148,20 +148,16 @@ void MainScene::DoUI(Context &context) { bool axisChanged = false; - static constexpr magic_enum::containers::array - axisLabel = {{{ - "Italic##axis", - "Optical size##axis", - "Slant##axis", - "Weight##axis", - "Width##axis", - }}}; + constexpr magic_enum::containers::array + axisLabel = { + "Italic##axis", "Optical size##axis", "Slant##axis", + "Weight##axis", "Width##axis", + }; magic_enum::enum_for_each( - [this, &axisChanged](const VariationAxis &axis) { + [this, &axisChanged, &axisLabel](const VariationAxis &axis) { if (axisLimits[axis].has_value()) { - auto [min, max, _] = *axisLimits[axis]; + [[maybe_unused]] auto [min, max, _] = *axisLimits[axis]; axisChanged |= ImGui::DragFloat(axisLabel[axis], &axisValue[axis], 1.0f, min, max); } else { @@ -183,9 +179,9 @@ void MainScene::DoUI(Context &context) { ImGui::LabelText("Line height", "%.3f", font.LineHeight()); ImGui::SeparatorText("OpenType text shaping"); - ImGui::Checkbox("Enable##Shape Text", &isShape); + ImGui::Checkbox("Enable##Shape Text", &isShaping); - ImGui::BeginDisabled(!isShape); + ImGui::BeginDisabled(!isShaping); if (ImGui::BeginCombo("Language", languages[selectedLanguage].name)) { for (size_t i = 0; i < languages.size(); i++) { if (ImGui::Selectable(languages[i].name, i == selectedLanguage)) { @@ -212,12 +208,13 @@ void MainScene::DoUI(Context &context) { }; if (ImGui::BeginCombo("Direction", directionLabels[selectedDirection])) { - magic_enum::enum_for_each([this, &directionLabels]( - const auto &dir) { - if (ImGui::Selectable(directionLabels[dir], dir == selectedDirection)) { - selectedDirection = dir; - } - }); + magic_enum::enum_for_each( + [this, &directionLabels](const auto &dir) { + if (ImGui::Selectable(directionLabels[dir], + dir == selectedDirection)) { + selectedDirection = dir; + } + }); ImGui::EndCombo(); } diff --git a/main_scene.hpp b/main_scene.hpp index 1da8746..c8fb2c8 100644 --- a/main_scene.hpp +++ b/main_scene.hpp @@ -36,50 +36,69 @@ class MainScene : public Scene { std::array buffer = {0}; float color[3]; int fontSize = 64; - bool isShape = false; + bool isShaping = false; int selectedFontIndex = -1; std::vector fontPaths; - std::vector fontData; - - ImGui::FileBrowser dirChooser{ - ImGuiFileBrowserFlags_SelectDirectory, - }; + ImGui::FileBrowser dirChooser{ImGuiFileBrowserFlags_SelectDirectory}; Font font{}; - // clang-format off struct ScriptPair { - const char* name; + const char *name; const hb_script_t script; }; - static constexpr std::array scripts = { - ScriptPair{"Common", HB_SCRIPT_COMMON}, - ScriptPair{"Thai", HB_SCRIPT_THAI}, - ScriptPair{"Hiragana", HB_SCRIPT_HIRAGANA}, - ScriptPair{"Katakana", HB_SCRIPT_KATAKANA}, - ScriptPair{"Han", HB_SCRIPT_HAN}, - ScriptPair{"Hangul", HB_SCRIPT_HANGUL}, - ScriptPair{"Arabic", HB_SCRIPT_ARABIC}, + static constexpr std::array scripts{ + ScriptPair{"Common", HB_SCRIPT_COMMON}, + ScriptPair{"Thai", HB_SCRIPT_THAI}, + ScriptPair{"Hiragana", HB_SCRIPT_HIRAGANA}, + ScriptPair{"Katakana", HB_SCRIPT_KATAKANA}, + ScriptPair{"Han", HB_SCRIPT_HAN}, + ScriptPair{"Hangul", HB_SCRIPT_HANGUL}, + ScriptPair{"Arabic", HB_SCRIPT_ARABIC}, }; struct LanguagePair { - const char* name; - const char* code; + const char *name; + const char *code; }; - static constexpr std::array languages = { - LanguagePair{ "None", "", }, - LanguagePair{ "English US", "en-US", }, - LanguagePair{ "Thai Thailand", "th-TH", }, - LanguagePair{ "Japanese Japan", "ja-JP", }, - LanguagePair{ "Korean Republic of Korea","ko-KR", }, - LanguagePair{ "Chinese China", "zh-CN", }, - LanguagePair{ "Chinese Taiwan", "zh-TW", }, - LanguagePair{ "Arabic Saudi Arabia", "ar-SA", }, + + static constexpr std::array languages{ + LanguagePair{ + "None", + "", + }, + LanguagePair{ + "English US", + "en-US", + }, + LanguagePair{ + "Thai Thailand", + "th-TH", + }, + LanguagePair{ + "Japanese Japan", + "ja-JP", + }, + LanguagePair{ + "Korean Republic of Korea", + "ko-KR", + }, + LanguagePair{ + "Chinese China", + "zh-CN", + }, + LanguagePair{ + "Chinese Taiwan", + "zh-TW", + }, + LanguagePair{ + "Arabic Saudi Arabia", + "ar-SA", + }, }; - // clang-format on int selectedScript = 0; int selectedLanguage = 0;