diff --git a/CMakeLists.txt b/CMakeLists.txt index 50cd207..c859534 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ add_executable(${PROJECT_NAME} src/rig_reconfigure.cpp src/service_wrapper.cpp s #target_compile_options(${PROJECT_NAME} PRIVATE -g -fsanitize=thread) #target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=thread) -target_include_directories(${PROJECT_NAME} PRIVATE include external/imspinner external/lodepng) +target_include_directories(${PROJECT_NAME} PRIVATE include external/lodepng) target_link_libraries(${PROJECT_NAME} imgui rclcpp::rclcpp ament_index_cpp::ament_index_cpp) install(TARGETS ${PROJECT_NAME} diff --git a/src/node_window.cpp b/src/node_window.cpp index 8eddfea..ee1e9cc 100644 --- a/src/node_window.cpp +++ b/src/node_window.cpp @@ -19,7 +19,7 @@ struct TreeNode { std::string name; // node name (leaf node) / namespace (other) std::string fullName; // full node name for easier usage - std::vector> children; + std::vector> children = {}; }; class NodeTree { diff --git a/src/rig_reconfigure.cpp b/src/rig_reconfigure.cpp index a739d97..4d7af70 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,50 @@ 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().IniFilename = config_file_path.c_str(); // important for automatic saving of .ini file + 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; + + if (configFileExisting) { + // manual loading of the .ini file since we require the window size before creating the glfw window + ImGui::LoadIniSettingsFromDisk(config_file_path.c_str()); + ImGuiID id = ImHashStr("Root window"); + ImGuiWindowSettings* root_window_settings = ImGui::FindWindowSettingsByID(id); + + if (root_window_settings != nullptr) { + window_width = root_window_settings->Size.x; + window_height = root_window_settings->Size.y; + } + } - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; + // 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();