From 4e1226739a528fc8078dcd3051e79cb98b7239cd Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 16 Dec 2025 12:35:19 -0500 Subject: [PATCH] Settings fix --- src/imgui/window/timeline.cpp | 14 +++++----- src/loader.cpp | 3 +- src/settings.cpp | 52 +++++++++++++++++++++++++++++++++-- src/settings.h | 2 ++ 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index e32bb58..be15a37 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -81,6 +81,9 @@ namespace anm2ed::imgui constexpr auto FRAME_DRAG_PAYLOAD_ID = "Frame Drag Drop"; constexpr auto FRAME_TOOLTIP_HOVER_DELAY = 0.75f; // Extra delay for frame info tooltip. +#define ITEM_FRAME_CHILD_HEIGHT ImGui::GetTextLineHeightWithSpacing() + (ImGui::GetStyle().WindowPadding.y * 1.5) +#define ITEM_CHILD_WIDTH ImGui::GetTextLineHeightWithSpacing() * 12.5 + void Timeline::update(Manager& manager, Settings& settings, Resources& resources, Clipboard& clipboard) { auto& document = *manager.get(); @@ -573,8 +576,7 @@ namespace anm2ed::imgui ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding); - auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, - ImGui::GetTextLineHeightWithSpacing() + (ImGui::GetStyle().WindowPadding.y * 2)); + auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, ITEM_FRAME_CHILD_HEIGHT); if (ImGui::BeginChild(label.c_str(), itemSize, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollWithMouse)) { @@ -818,7 +820,7 @@ namespace anm2ed::imgui auto items_child = [&]() { - auto itemsChildSize = ImVec2(ImGui::GetTextLineHeightWithSpacing() * 15, ImGui::GetContentRegionAvail().y); + auto itemsChildSize = ImVec2(ITEM_CHILD_WIDTH, ImGui::GetContentRegionAvail().y); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); bool isItemsChildOpen = ImGui::BeginChild("##Items Child", itemsChildSize, ImGuiChildFlags_Borders); @@ -938,7 +940,7 @@ namespace anm2ed::imgui ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding); - auto childSize = ImVec2(width, ImGui::GetTextLineHeightWithSpacing() + (ImGui::GetStyle().WindowPadding.y * 2)); + auto childSize = ImVec2(width, ITEM_FRAME_CHILD_HEIGHT); ImGui::PopStyleVar(2); @@ -1468,10 +1470,8 @@ namespace anm2ed::imgui auto frames_child = [&]() { - auto itemsChildWidth = ImGui::GetTextLineHeightWithSpacing() * 15; - auto cursorPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cursorPos.x + itemsChildWidth, cursorPos.y)); + ImGui::SetCursorPos(ImVec2(cursorPos.x + ITEM_CHILD_WIDTH, cursorPos.y)); auto framesChildSize = ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y); diff --git a/src/loader.cpp b/src/loader.cpp index 11879b3..777b9b7 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -212,7 +212,8 @@ namespace anm2ed ImGui::GetStyle().FontScaleMain = settings.uiScale; io.ConfigWindowsMoveFromTitleBarOnly = true; - ImGui::LoadIniSettingsFromDisk(settings_path().string().c_str()); + if (auto imguiData = Settings::imgui_data_load(settings_path()); !imguiData.empty()) + ImGui::LoadIniSettingsFromMemory(imguiData.c_str(), imguiData.size()); if (isSocketThread) { diff --git a/src/settings.cpp b/src/settings.cpp index ad5ac38..e3529f2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,5 +1,8 @@ #include "settings.h" +#include +#include + #include "filesystem_.h" #include "log.h" @@ -9,9 +12,7 @@ namespace filesystem = anm2ed::util::filesystem; namespace anm2ed { - constexpr auto IMGUI_DEFAULT = R"( -# Dear ImGui -[Window][##DockSpace] + constexpr auto IMGUI_DEFAULT = R"([Window][##DockSpace] Pos=0,54 Size=1918,1010 Collapsed=0 @@ -268,6 +269,51 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,994 Spl file.close(); } + std::string Settings::imgui_data_load(const std::filesystem::path& path) + { + auto pathUtf8 = filesystem::path_to_utf8(path); + std::ifstream file(path, std::ios::in | std::ios::binary); + if (!file.is_open()) + { + logger.error( + std::format("Failed to open settings file for Dear ImGui data: {}; using Dear ImGui defaults", pathUtf8)); + return {}; + } + + std::string line{}; + std::ostringstream dataStream; + bool isImGuiSection = false; + bool isContent = false; + + while (std::getline(file, line)) + { + if (!isImGuiSection) + { + if (line == "# Dear ImGui") isImGuiSection = true; + continue; + } + + if (isContent) dataStream << "\n"; + dataStream << line; + isContent = true; + } + + if (!isImGuiSection) + { + logger.warning( + std::format("Dear ImGui section missing from settings file: {}; using Dear ImGui defaults", pathUtf8)); + return {}; + } + + if (!isContent) + { + logger.warning(std::format("Dear ImGui section empty in settings file: {}; using Dear ImGui defaults", pathUtf8)); + return {}; + } + + return dataStream.str(); + } + void Settings::save(const std::filesystem::path& path, const std::string& imguiData) { std::ofstream file(path, std::ios::out | std::ios::binary); diff --git a/src/settings.h b/src/settings.h index 300345c..9ec65ce 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -250,6 +251,7 @@ namespace anm2ed Settings(const std::filesystem::path&); void save(const std::filesystem::path&, const std::string&); + static std::string imgui_data_load(const std::filesystem::path&); }; constexpr StringType SHORTCUT_STRING_TYPES[] = {