From cd05e8f6cb4c0cf6d421eb820bea936369722ec3 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 5 Oct 2021 14:13:35 +0200 Subject: [PATCH] Tech ENABLE_PREVIEW_LAYOUT - Other fixes related to legend size when moving the application to another monitor --- src/slic3r/GUI/GCodeViewer.cpp | 17 +++++++++-------- src/slic3r/GUI/GCodeViewer.hpp | 7 +------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index a97a2ab35..51dc892f8 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3671,8 +3671,6 @@ void GCodeViewer::render_legend(float& legend_height) if (!m_legend_resizer.dirty) ImGui::SetNextItemWidth(-1.0f); - if (m_legend_resizer.last_width >= ImGui::GetWindowWidth()) - m_legend_resizer.dirty = false; ImGui::PushStyleColor(ImGuiCol_FrameBg, { 0.1f, 0.1f, 0.1f, 0.8f }); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, { 0.2f, 0.2f, 0.2f, 0.8f }); @@ -3789,7 +3787,7 @@ void GCodeViewer::render_legend(float& legend_height) total_items += color_print_ranges(i, custom_gcode_per_print_z).size(); } - const bool need_scrollable = static_cast(total_items) * (icon_size + ImGui::GetStyle().ItemSpacing.y) > child_height; + const bool need_scrollable = static_cast(total_items) * icon_size + (static_cast(total_items) - 1.0f) * ImGui::GetStyle().ItemSpacing.y > child_height; // add scrollable region, if needed if (need_scrollable) @@ -3999,7 +3997,7 @@ void GCodeViewer::render_legend(float& legend_height) ImGui::Spacing(); append_headers({ _u8L("Event"), _u8L("Remaining time"), _u8L("Duration"), _u8L("Used filament") }, offsets); - const bool need_scrollable = static_cast(partial_times.size()) * (icon_size + ImGui::GetStyle().ItemSpacing.y) > child_height; + const bool need_scrollable = static_cast(partial_times.size()) * icon_size + (static_cast(partial_times.size()) - 1.0f) * ImGui::GetStyle().ItemSpacing.y > child_height; if (need_scrollable) // add scrollable region ImGui::BeginChild("events", { -1.0f, child_height }, false); @@ -4356,12 +4354,15 @@ void GCodeViewer::render_legend(float& legend_height) window.DrawList->AddRectFilled({ mid_x - 0.09375f * size, p1.y - 0.25f * size }, { mid_x + 0.09375f * size, pos.y + margin }, color); }); - m_legend_resizer.last_width = ImGui::GetCurrentWindow()->DC.CursorPosPrevLine.x + ImGui::GetStyle().WindowPadding.x; - if (m_legend_resizer.last_width < ImGui::GetWindowWidth()) - m_legend_resizer.dirty = true; + bool size_dirty = !ImGui::GetCurrentWindow()->ScrollbarY && ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x != ImGui::GetWindowWidth(); + if (m_legend_resizer.dirty || size_dirty != m_legend_resizer.dirty) { + wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); + wxGetApp().plater()->get_current_canvas3D()->request_extra_frame(); + } + m_legend_resizer.dirty = size_dirty; #endif // ENABLE_PREVIEW_LAYOUT - legend_height = ImGui::GetCurrentWindow()->Size.y; + legend_height = ImGui::GetWindowHeight(); imgui.end(); ImGui::PopStyleVar(); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index e8c036e33..e1753576a 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -822,12 +822,7 @@ private: struct LegendResizer { bool dirty{ true }; - float last_width{ 0.0f }; - - void reset() { - dirty = true; - last_width = 0.0f; - } + void reset() { dirty = true; } }; LegendResizer m_legend_resizer; #endif // ENABLE_PREVIEW_LAYOUT