From 3c257f081cc205a8df27bafbad186f15c0d276f2 Mon Sep 17 00:00:00 2001 From: Dominik <45536968+authaldo@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:39:05 +0000 Subject: [PATCH] load root window size from .ini file --- src/rig_reconfigure.cpp | 46 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/rig_reconfigure.cpp b/src/rig_reconfigure.cpp index a739d97..a8a4c5a 100644 --- a/src/rig_reconfigure.cpp +++ b/src/rig_reconfigure.cpp @@ -15,9 +15,10 @@ #include #include +#include + #include "service_wrapper.hpp" #include "utils.hpp" -#include "lodepng.h" #include "node_window.hpp" #include "parameter_window.hpp" @@ -27,6 +28,8 @@ constexpr auto STATUS_WARNING_COLOR = ImVec4(1, 0, 0, 1); constexpr auto NODES_AUTO_REFRESH_INTERVAL = 1s; // unit: seconds constexpr auto DESIRED_FRAME_RATE = 30; constexpr std::chrono::duration DESIRED_FRAME_DURATION_MS = 1000ms / DESIRED_FRAME_RATE; +constexpr auto DEFAULT_WINDOW_WIDTH = 600; +constexpr auto DEFAULT_WINDOW_HEIGHT = 800; // window names constexpr auto NODE_WINDOW_NAME = "Nodes"; @@ -59,36 +62,47 @@ int main(int argc, char *argv[]) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - // Create window with graphics context - GLFWwindow *window = glfwCreateWindow(600, 800, "Parameter modification editor", - nullptr, nullptr); - if (window == nullptr) { - return 1; - } - glfwMakeContextCurrent(window); - glfwSwapInterval(1); // Enable vsync - - const auto resourcePath = findResourcePath(argv[0]); - - loadWindowIcon(window, resourcePath); - // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); // place the imgui.ini config file within the users home directory (instead of current working directory) const std::filesystem::path config_file_dir(std::string(std::getenv("HOME")) + "/.config/rig_reconfigure"); + const std::string config_file_path = config_file_dir.string() + "/imgui.ini"; if (!std::filesystem::exists(config_file_dir)) { std::filesystem::create_directory(config_file_dir); } - const std::string config_file_path = config_file_dir.string() + "/imgui.ini"; ImGui::GetIO().IniFilename = config_file_path.c_str(); + ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; + // load window size if already stored from last iteration bool configFileExisting = std::filesystem::exists(config_file_path); + auto window_width = DEFAULT_WINDOW_WIDTH; + auto window_height = DEFAULT_WINDOW_HEIGHT; - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; + if (configFileExisting) { + ImGui::LoadIniSettingsFromDisk(config_file_path.c_str()); + ImGuiID id = ImHashStr("Root window"); + ImGuiWindowSettings* root_window_settings = ImGui::FindWindowSettingsByID(id); + + window_width = root_window_settings->Size.x; + window_height = root_window_settings->Size.y; + } + + // Create window with graphics context + GLFWwindow *window = glfwCreateWindow(window_width, window_height, "Parameter modification editor", + nullptr, nullptr); + if (window == nullptr) { + return 1; + } + glfwMakeContextCurrent(window); + glfwSwapInterval(1); // Enable vsync + + const auto resourcePath = findResourcePath(argv[0]); + + loadWindowIcon(window, resourcePath); // Setup Dear ImGui style ImGui::StyleColorsDark();