Files
imhex/source/views/view_settings.cpp
WerWolv 36a4930b35 Implement localization all throughout ImHex
English only for now, additional languages will come in the future
2021-02-11 23:09:45 +01:00

50 lines
1.7 KiB
C++

#include "views/view_settings.hpp"
#include <hex/api/content_registry.hpp>
namespace hex {
ViewSettings::ViewSettings() : View("hex.view.settings.title"_lang) {
View::subscribeEvent(Events::OpenWindow, [this](auto name) {
if (std::any_cast<const char*>(name) == std::string("hex.view.settings.title"_lang)) {
View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); });
this->getWindowOpenState() = true;
}
});
}
ViewSettings::~ViewSettings() {
View::unsubscribeEvent(Events::OpenWindow);
}
void ViewSettings::drawContent() {
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX));
if (ImGui::BeginPopupModal("hex.view.settings.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
ImGui::TextUnformatted(category.c_str());
ImGui::Separator();
for (auto &[name, callback] : entries) {
if (callback(ContentRegistry::Settings::getSettingsData()[category][name]))
View::postEvent(Events::SettingsChanged);
}
ImGui::NewLine();
}
ImGui::EndPopup();
} else
this->getWindowOpenState() = false;
}
void ViewSettings::drawMenu() {
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
if (ImGui::MenuItem("hex.view.settings.title"_lang)) {
View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); });
this->getWindowOpenState() = true;
}
ImGui::EndMenu();
}
}
}