diff --git a/src/flamegpu/visualiser/ui/ImGuiPanel.cpp b/src/flamegpu/visualiser/ui/ImGuiPanel.cpp index d027f1c..b04416c 100644 --- a/src/flamegpu/visualiser/ui/ImGuiPanel.cpp +++ b/src/flamegpu/visualiser/ui/ImGuiPanel.cpp @@ -24,19 +24,26 @@ ImGuiPanel::ImGuiPanel(const std::map> ImGui_ImplSDL2_NewFrame(); // This can't be called in the render thread, as it tries to grab the window dimensions via SDL } void ImGuiPanel::reload() { - // Do nothing + first_render = 0; } -void ImGuiPanel::drawPanel() const { +void ImGuiPanel::drawPanel() { const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(ImVec2(main_viewport->WorkPos.x + 5, main_viewport->WorkPos.y + 5), ImGuiCond_Once); + ImVec2 prev_window_size(0, 0), prev_window_pos(main_viewport->WorkPos.x, main_viewport->WorkPos.y); for (const auto &config : configs) { // Translucent background ImGui::SetNextWindowBgAlpha(150.0f / 255.0f); // Size panel to fit it's content ImGui::SetNextWindowSize(ImVec2(0, 0), ImGuiCond_Always); + if (first_render < 2) { + // Manual set once condition, as I can't get ImGuiCond to play nicely here for multiple panels + // Position multiple panels so that they don't overlap + ImGui::SetNextWindowPos(ImVec2(prev_window_pos.x + prev_window_size.x + 5, main_viewport->WorkPos.y + 5), ImGuiCond_Always); + } // Actually start creating the panel if (!ImGui::Begin(config.title.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize)) { + prev_window_size = ImGui::GetWindowSize(); + prev_window_pos = ImGui::GetWindowPos(); // Early out if the window is collapsed, as an optimization. ImGui::End(); return; @@ -57,8 +64,11 @@ void ImGuiPanel::drawPanel() const { // Finalise the panel ImGui::PopItemWidth(); + prev_window_size = ImGui::GetWindowSize(); + prev_window_pos = ImGui::GetWindowPos(); ImGui::End(); } + first_render += first_render < 2 ? 1: 0; // Auto size is not calculated until it's been drawn, so wait a frame to fix it } void ImGuiPanel::drawDebugPanel() const { const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); @@ -132,6 +142,7 @@ void ImGuiPanel::registerProperty(const std::string& name, void* ptr, bool is_co } } } + first_render = 0; // As these can change window width } } // namespace visualiser diff --git a/src/flamegpu/visualiser/ui/ImGuiPanel.h b/src/flamegpu/visualiser/ui/ImGuiPanel.h index 70cd880..4b03aea 100644 --- a/src/flamegpu/visualiser/ui/ImGuiPanel.h +++ b/src/flamegpu/visualiser/ui/ImGuiPanel.h @@ -28,7 +28,7 @@ class ImGuiPanel : public Overlay { */ explicit ImGuiPanel(const std::map> &cfgs, const Visualiser& _vis); /** - * Does nothing, as ImGui runs in immediate mode + * Only resets first_render flag, as ImGui runs in immediate mode */ void reload() override; /** @@ -68,11 +68,16 @@ class ImGuiPanel : public Overlay { /** * Calls ImGui to draw the user specified panels from configs */ - void drawPanel() const; + void drawPanel(); /** * Calls ImGui to draw the debug panel */ void drawDebugPanel() const; + /** + * Causes panels to be automatically positioned + * Takes 2 frames to process, due to auto sizing + */ + unsigned char first_render; /** * A copy of the panel configurations passed to the constructor * These are maintaned as they must be passed to ImGui prior to each frame being rendered