From 1a95169466614af21707f4928097af2d49f86403 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 29 Sep 2021 11:56:55 +0200 Subject: [PATCH] Tech ENABLE_PREVIEW_LAYOUT - Fixed legend width when moving the application to another monitor --- src/slic3r/GUI/GCodeViewer.cpp | 14 ++++++++++++-- src/slic3r/GUI/GCodeViewer.hpp | 17 +++++++++++++++++ src/slic3r/GUI/GLCanvas3D.cpp | 3 +++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index b65d401f7..0ab4f80d6 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -758,6 +758,9 @@ void GCodeViewer::reset() #if ENABLE_GCODE_VIEWER_STATISTICS m_statistics.reset_all(); #endif // ENABLE_GCODE_VIEWER_STATISTICS +#if ENABLE_PREVIEW_LAYOUT + m_legend_resizer.reset(); +#endif // ENABLE_PREVIEW_LAYOUT } void GCodeViewer::render() @@ -3513,8 +3516,11 @@ void GCodeViewer::render_legend(float& legend_height) bool view_type_changed = false; int old_view_type = static_cast(get_view_type()); int view_type = old_view_type; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::PushItemWidth(ImGui::GetWindowWidth() - style.ItemSpacing.x - 2.0f * style.FramePadding.x); + + ImGui::SetNextItemWidth(m_legend_resizer.dirty ? 0.0f : -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 }); imgui.combo("", { _u8L("Feature type"), @@ -4182,6 +4188,10 @@ void GCodeViewer::render_legend(float& legend_height) const float mid_x = 0.5f * (pos.x + pos.x + size); 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; #endif // ENABLE_PREVIEW_LAYOUT legend_height = ImGui::GetCurrentWindow()->Size.y; diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 15b8d453c..b002826d1 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -793,6 +793,19 @@ private: Shells m_shells; EViewType m_view_type{ EViewType::FeatureType }; bool m_legend_enabled{ true }; +#if ENABLE_PREVIEW_LAYOUT + struct LegendResizer + { + bool dirty{ true }; + float last_width{ 0.0f }; + + void reset() { + dirty = true; + last_width = 0.0f; + } + }; + LegendResizer m_legend_resizer; +#endif // ENABLE_PREVIEW_LAYOUT PrintEstimatedStatistics m_print_statistics; PrintEstimatedStatistics::ETimeMode m_time_estimate_mode{ PrintEstimatedStatistics::ETimeMode::Normal }; #if ENABLE_GCODE_VIEWER_STATISTICS @@ -858,6 +871,10 @@ public: std::vector& get_custom_gcode_per_print_z() { return m_custom_gcode_per_print_z; } size_t get_extruders_count() { return m_extruders_count; } +#if ENABLE_PREVIEW_LAYOUT + void invalidate_legend() { m_legend_resizer.reset(); } +#endif // ENABLE_PREVIEW_LAYOUT + private: void load_toolpaths(const GCodeProcessor::Result& gcode_result); void load_shells(const Print& print, bool initialized); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5ebf57c6c..57d338600 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3741,6 +3741,9 @@ void GLCanvas3D::set_cursor(ECursorType type) void GLCanvas3D::msw_rescale() { +#if ENABLE_PREVIEW_LAYOUT + m_gcode_viewer.invalidate_legend(); +#endif // ENABLE_PREVIEW_LAYOUT } void GLCanvas3D::update_tooltip_for_settings_item_in_main_toolbar()