2021-01-11 19:31:40 +00:00
|
|
|
#include "views/view_settings.hpp"
|
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-11 19:31:40 +00:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
ViewSettings::ViewSettings() : View("Settings") {
|
2021-01-27 13:26:24 +00:00
|
|
|
View::subscribeEvent(Events::OpenWindow, [this](auto name) {
|
|
|
|
if (std::any_cast<const char*>(name) == std::string("Preferences")) {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup("Preferences"); });
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
}
|
|
|
|
});
|
2021-01-11 19:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewSettings::~ViewSettings() {
|
2021-01-27 13:26:24 +00:00
|
|
|
View::unsubscribeEvent(Events::OpenWindow);
|
2021-01-11 19:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawContent() {
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX));
|
|
|
|
|
2021-01-27 13:26:24 +00:00
|
|
|
if (ImGui::BeginPopupModal("Preferences", &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
|
2021-01-11 19:31:40 +00:00
|
|
|
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
|
|
|
ImGui::TextUnformatted(category.c_str());
|
|
|
|
ImGui::Separator();
|
|
|
|
for (auto &[name, callback] : entries) {
|
|
|
|
ImGui::TextUnformatted(name.c_str());
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (callback(ContentRegistry::Settings::getSettingsData()[category][name]))
|
2021-01-21 09:53:12 +00:00
|
|
|
View::postEvent(Events::SettingsChanged);
|
2021-01-11 19:31:40 +00:00
|
|
|
ImGui::NewLine();
|
|
|
|
}
|
|
|
|
ImGui::NewLine();
|
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
2021-01-27 13:26:24 +00:00
|
|
|
} else
|
|
|
|
this->getWindowOpenState() = false;
|
2021-01-11 19:31:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewSettings::drawMenu() {
|
|
|
|
if (ImGui::BeginMenu("Help")) {
|
|
|
|
if (ImGui::MenuItem("Preferences")) {
|
|
|
|
View::doLater([]{ ImGui::OpenPopup("Preferences"); });
|
2021-01-27 13:26:24 +00:00
|
|
|
this->getWindowOpenState() = true;
|
2021-01-11 19:31:40 +00:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|