diff options
author | rtk0c <[email protected]> | 2021-03-31 20:19:18 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-03-31 20:19:18 -0700 |
commit | 44f5fa5c8f258e8fc1f7d7e2e45e0485bd6cc490 (patch) | |
tree | 3f09a1cce46d38f5a8c6266150e67af3802d4b95 /core/src/Entrypoint/main.cpp | |
parent | 31950890c939862f79c817053c106bf711c63a64 (diff) |
Complete items tab (UI and serialization)
Diffstat (limited to 'core/src/Entrypoint/main.cpp')
-rw-r--r-- | core/src/Entrypoint/main.cpp | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/core/src/Entrypoint/main.cpp b/core/src/Entrypoint/main.cpp index 5811547..357c333 100644 --- a/core/src/Entrypoint/main.cpp +++ b/core/src/Entrypoint/main.cpp @@ -17,12 +17,14 @@ #include <IconsFontAwesome.h> #include <imgui.h> #include <argparse/argparse.hpp> +#include <filesystem> #include <iostream> #include <memory> #include <stdexcept> #include <string> #include <string_view> +namespace fs = std::filesystem; using namespace std::literals::string_literals; using namespace std::literals::string_view_literals; @@ -114,6 +116,9 @@ static std::unique_ptr<RenderingBackend> CreateBackend(std::string_view option) int main(int argc, char* argv[]) { argparse::ArgumentParser parser; + parser.add_argument("--global-data-directory") + .help("Directory in which global data (such as recently used projects) are saved to. Use 'default' to use the default directory on each platform.") + .default_value("default"s); parser.add_argument("--rendering-backend") .help("Which rendering backend to use. If equals 'default', the preferred API for each platform will be used") .default_value("default"s); @@ -129,31 +134,56 @@ int main(int argc, char* argv[]) { auto backendOption = parser.get<std::string>("--rendering-backend"); auto backend = CreateBackend(backendOption); - ImGui::GetIO().IniFilename = nullptr; - ImGui::GetIO().LogFilename = nullptr; + auto& io = ImGui::GetIO(); + + // Disable saving window positions + io.IniFilename = nullptr; + // Disable log (dump widget tree) file, we don't trigger it but just to be safe + io.LogFilename = nullptr; + + // Light mode because all major OS's default theme is white + // TODO follow system theme ImGui::StyleColorsLight(); - // Includes latin alphabet, although for some reason smaller than if rendered using 18 point NotoSans regular - ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/NotoSansSC-Regular.otf", 18, nullptr, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + // Configure default fonts + { + // Includes latin alphabet, although for some reason smaller than if rendered using 18 point NotoSans regular + io.Fonts->AddFontFromFileTTF("fonts/NotoSansSC-Regular.otf", 18, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); + + ImWchar iconRanges[] = { ICON_MIN_FA, ICON_MAX_FA }; + ImFontConfig config; + config.MergeMode = true; + io.Fonts->AddFontFromFileTTF("fonts/FontAwesome5-Solid.otf", 14, &config, iconRanges); + } - ImWchar iconRanges[] = { ICON_MIN_FA, ICON_MAX_FA }; - ImFontConfig config; - config.MergeMode = true; - ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/FontAwesome5-Solid.otf", 14, &config, iconRanges); + // Initialize localization utilities + { + I18n::OnLanguageChange.Connect([]() { LocaleStrings::Instance = std::make_unique<LocaleStrings>(); }); + // Do i18n initialization after linking reload signals, so that when SetLanguage() is called, the locale strings will be initialized (without us writing the code another time outside the slot) + I18n::Init(); + I18n::SetLanguage("zh_CN"); + // All of our usage are cached in XxxTranslation objects, no need to keep key -> entry mappings anymore + I18n::Unload(); + } - I18n::OnReload.Connect([]() { LocaleStrings::Instance = std::make_unique<LocaleStrings>(); }); - // Do i18n initialization after linking reload signals, so that when SetLanguage() is called, the locale strings will be initialized (without us writing the code another time outside the slot) - I18n::Init(); - I18n::SetLanguage("zh_CN"); + auto dataDirOption = parser.get<std::string>("--global-data-directory"); + if (dataDirOption == "default") { + GlobalStates::Init(); + } else { + fs::path path(dataDirOption); + if (fs::exists(path)) { + GlobalStates::Init(std::move(path)); + } else { + GlobalStates::Init(); + } + } - GlobalStates::Init(); UIState::Init(); auto window = backend->GetWindow(); while (!glfwWindowShouldClose(window)) { backend->BeginFrame(); UI::MainWindow(); - ImGui::ShowDemoWindow(); backend->EndFrame(); } |