impr: Added lots of comments and cleaned up many views

This commit is contained in:
WerWolv
2023-08-29 12:14:12 +02:00
parent 10ad239fb9
commit 4288f876e2
13 changed files with 833 additions and 494 deletions

View File

@@ -17,15 +17,22 @@ namespace hex::plugin::builtin {
if (ImGui::Begin(View::toWindowName("hex.builtin.view.theme_manager.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse)) {
ImGui::Header("hex.builtin.view.theme_manager.colors"_lang, true);
// Draw theme handlers
ImGui::PushID(1);
const auto &themeHandlers = ThemeManager::getThemeHandlers();
for (auto &[name, handler] : themeHandlers) {
// Loop over each theme handler
for (auto &[name, handler] : ThemeManager::getThemeHandlers()) {
// Create a new collapsable header for each category
if (ImGui::CollapsingHeader(name.c_str())) {
// Loop over all the individual theme settings
for (auto &[colorName, colorId] : handler.colorMap) {
// Get the current color value
auto color = handler.getFunction(colorId);
if (ImGui::ColorEdit4(colorName.c_str(), (float*)&color.Value,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf))
{
// Draw a color picker for the color
if (ImGui::ColorEdit4(colorName.c_str(), (float*)&color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf)) {
// Update the color value
handler.setFunction(colorId, color);
EventManager::post<EventThemeChanged>();
}
@@ -37,12 +44,21 @@ namespace hex::plugin::builtin {
ImGui::Header("hex.builtin.view.theme_manager.styles"_lang);
// Draw style handlers
ImGui::PushID(2);
// Loop over each style handler
for (auto &[name, handler] : ThemeManager::getStyleHandlers()) {
// Create a new collapsable header for each category
if (ImGui::CollapsingHeader(name.c_str())) {
// Loop over all the individual style settings
for (auto &[styleName, style] : handler.styleMap) {
// Get the current style value
auto &[value, min, max, needsScaling] = style;
// Styles can either be floats or ImVec2s
// Determine which one it is and draw the appropriate slider
if (auto floatValue = std::get_if<float*>(&value); floatValue != nullptr) {
if (ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f")) {
EventManager::post<EventThemeChanged>();
@@ -57,12 +73,17 @@ namespace hex::plugin::builtin {
}
ImGui::PopID();
// Draw export settings
ImGui::Header("hex.builtin.view.theme_manager.export"_lang);
ImGui::InputTextIcon("hex.builtin.view.theme_manager.export.name"_lang, ICON_VS_SYMBOL_KEY, this->m_themeName);
// Draw the export buttons
if (ImGui::Button("hex.builtin.view.theme_manager.save_theme"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
fs::openFileBrowser(fs::DialogMode::Save, { { "ImHex Theme", "json" } }, [this](const std::fs::path &path){
// Export the current theme as json
auto json = ThemeManager::exportCurrentTheme(this->m_themeName);
// Write the json to the file
wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
outputFile.writeString(json.dump(4));
});