2021-01-11 20:31:40 +01:00
|
|
|
#include "views/view_settings.hpp"
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
ViewSettings::ViewSettings() : View("hex.view.settings.title"_lang) {
|
2021-01-27 14:26:24 +01:00
|
|
|
View::subscribeEvent(Events::OpenWindow, [this](auto name) {
|
2021-02-11 23:09:45 +01:00
|
|
|
if (std::any_cast<const char*>(name) == std::string("hex.view.settings.title"_lang)) {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
}
|
|
|
|
});
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewSettings::~ViewSettings() {
|
2021-01-27 14:26:24 +01:00
|
|
|
View::unsubscribeEvent(Events::OpenWindow);
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawContent() {
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX));
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BeginPopupModal("hex.view.settings.title"_lang, &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
|
2021-01-11 20:31:40 +01:00
|
|
|
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]))
|
2021-01-21 10:53:12 +01:00
|
|
|
View::postEvent(Events::SettingsChanged);
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
ImGui::NewLine();
|
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
2021-01-27 14:26:24 +01:00
|
|
|
} else
|
|
|
|
this->getWindowOpenState() = false;
|
2021-01-11 20:31:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawMenu() {
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BeginMenu("hex.menu.help"_lang)) {
|
|
|
|
if (ImGui::MenuItem("hex.view.settings.title"_lang)) {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.settings.title"_lang); });
|
2021-01-27 14:26:24 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|