Skip to content

Commit

Permalink
clean up some weirdness.
Browse files Browse the repository at this point in the history
  • Loading branch information
wutipong committed Jan 21, 2024
1 parent 5aa76b1 commit cb2d9f7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 48 deletions.
37 changes: 17 additions & 20 deletions main_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -148,20 +148,16 @@ void MainScene::DoUI(Context &context) {

bool axisChanged = false;

static constexpr magic_enum::containers::array<VariationAxis,
const char *>
axisLabel = {{{
"Italic##axis",
"Optical size##axis",
"Slant##axis",
"Weight##axis",
"Width##axis",
}}};
constexpr magic_enum::containers::array<VariationAxis, const char *>
axisLabel = {
"Italic##axis", "Optical size##axis", "Slant##axis",
"Weight##axis", "Width##axis",
};

magic_enum::enum_for_each<VariationAxis>(
[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 {
Expand All @@ -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)) {
Expand All @@ -212,12 +208,13 @@ void MainScene::DoUI(Context &context) {
};

if (ImGui::BeginCombo("Direction", directionLabels[selectedDirection])) {
magic_enum::enum_for_each<TextDirection>([this, &directionLabels](
const auto &dir) {
if (ImGui::Selectable(directionLabels[dir], dir == selectedDirection)) {
selectedDirection = dir;
}
});
magic_enum::enum_for_each<TextDirection>(
[this, &directionLabels](const auto &dir) {
if (ImGui::Selectable(directionLabels[dir],
dir == selectedDirection)) {
selectedDirection = dir;
}
});

ImGui::EndCombo();
}
Expand Down
75 changes: 47 additions & 28 deletions main_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,69 @@ class MainScene : public Scene {
std::array<char, 4096> buffer = {0};
float color[3];
int fontSize = 64;
bool isShape = false;
bool isShaping = false;

int selectedFontIndex = -1;
std::vector<std::filesystem::path> fontPaths;

std::vector<unsigned char> 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<ScriptPair, 7> 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<ScriptPair, 7> 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<LanguagePair, 8> 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<LanguagePair, 8> 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;
Expand Down

0 comments on commit cb2d9f7

Please sign in to comment.