From 0bb9233da73f62a3ff869479f5155fee1254694c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 23 Apr 2024 14:01:16 +0200 Subject: [PATCH] ImguiDoubleSlider: Respect to "Collapse sidebar" button + use scale from canvas Size --- src/slic3r/GUI/DoubleSliderForGcode.cpp | 2 +- src/slic3r/GUI/DoubleSliderForGcode.hpp | 2 +- src/slic3r/GUI/DoubleSliderForLayers.cpp | 6 +++--- src/slic3r/GUI/DoubleSliderForLayers.hpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 8 +------- src/slic3r/GUI/GUI_Preview.cpp | 14 +++++++++----- src/slic3r/GUI/GUI_Preview.hpp | 2 +- src/slic3r/GUI/ImGuiDoubleSlider.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 10 +++++----- src/slic3r/GUI/Plater.hpp | 2 +- 10 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/slic3r/GUI/DoubleSliderForGcode.cpp b/src/slic3r/GUI/DoubleSliderForGcode.cpp index 0924f279ff..7ad6c3bf81 100644 --- a/src/slic3r/GUI/DoubleSliderForGcode.cpp +++ b/src/slic3r/GUI/DoubleSliderForGcode.cpp @@ -10,7 +10,7 @@ namespace DoubleSlider { static const float LEFT_MARGIN = 13.0f + 100.0f; // avoid thumbnail toolbar static const float HORIZONTAL_SLIDER_HEIGHT = 45.0f; -void DSForGcode::Render(const int canvas_width, const int canvas_height, float extra_scale/* = 0.1f*/) +void DSForGcode::Render(const int canvas_width, const int canvas_height, float extra_scale/* = 0.1f*/, float offset/* = 0.f*/) { if (!m_ctrl.IsShown()) return; diff --git a/src/slic3r/GUI/DoubleSliderForGcode.hpp b/src/slic3r/GUI/DoubleSliderForGcode.hpp index c216fe3017..0cb528b125 100644 --- a/src/slic3r/GUI/DoubleSliderForGcode.hpp +++ b/src/slic3r/GUI/DoubleSliderForGcode.hpp @@ -22,7 +22,7 @@ public: } ~DSForGcode() {} - void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f) override; + void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f, float offset = 0.f) override; void set_render_as_disabled(bool value) { m_render_as_disabled = value; } bool is_rendering_as_disabled() const { return m_render_as_disabled; } diff --git a/src/slic3r/GUI/DoubleSliderForLayers.cpp b/src/slic3r/GUI/DoubleSliderForLayers.cpp index fdf9cbfa49..3f0a2e1eaf 100644 --- a/src/slic3r/GUI/DoubleSliderForLayers.cpp +++ b/src/slic3r/GUI/DoubleSliderForLayers.cpp @@ -615,7 +615,7 @@ bool DSForLayers::render_jump_to_window(const ImVec2& pos, double* active_value, return enter_pressed || ok_pressed; } -void DSForLayers::Render(const int canvas_width, const int canvas_height, float extra_scale/* = 0.1f*/) +void DSForLayers::Render(const int canvas_width, const int canvas_height, float extra_scale/* = 0.1f*/, float offset /*= 0.f*/) { if (!m_ctrl.IsShown()) return; @@ -627,11 +627,11 @@ void DSForLayers::Render(const int canvas_width, const int canvas_height, float ImVec2 pos; pos.x = canvas_width - VERTICAL_SLIDER_WIDTH * m_scale - tick_icon_side; - pos.y = 1.5f * action_btn_sz; + pos.y = 1.5f * action_btn_sz + offset; if (m_allow_editing) pos.y += 2.f; - ImVec2 size = ImVec2(VERTICAL_SLIDER_WIDTH * m_scale, canvas_height - 4.f * action_btn_sz); + ImVec2 size = ImVec2(VERTICAL_SLIDER_WIDTH * m_scale, canvas_height - 4.f * action_btn_sz - offset); m_ctrl.Init(pos, size, m_scale); if (m_ctrl.render()) { diff --git a/src/slic3r/GUI/DoubleSliderForLayers.hpp b/src/slic3r/GUI/DoubleSliderForLayers.hpp index 620c21c530..5eea05913e 100644 --- a/src/slic3r/GUI/DoubleSliderForLayers.hpp +++ b/src/slic3r/GUI/DoubleSliderForLayers.hpp @@ -73,7 +73,7 @@ public: void SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder); - void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f) override; + void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f, float offset = 0.f) override; // jump to selected layer void jump_to_value(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7c111d63c5..0348f811d9 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1947,13 +1947,7 @@ void GLCanvas3D::render() wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overlay_window_width()); - wxGetApp().plater()->render_sliders(*this, -#if ENABLE_RETINA_GL - m_retina_helper->get_scale_factor() -#else - 1.f -#endif - ); + wxGetApp().plater()->render_sliders(*this); wxGetApp().imgui()->render(); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 4b61a0c65e..bb773bf421 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -322,14 +322,18 @@ void Preview::msw_rescale() reload_print(); } -void Preview::render_sliders(GLCanvas3D& canvas, float extra_scale/* = 0.1f*/) +void Preview::render_sliders(GLCanvas3D& canvas) { - const Size cnv_size = canvas.get_canvas_size(); - const int canvas_width = cnv_size.get_width(); - const int canvas_height = cnv_size.get_height(); + const Size cnv_size = canvas.get_canvas_size(); + const int canvas_width = cnv_size.get_width(); + const int canvas_height = cnv_size.get_height(); + const float extra_scale = cnv_size.get_scale_factor(); + + GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); + const bool is_collapse_btn_shown = collapse_toolbar.is_enabled(); if (m_layers_slider) - m_layers_slider->Render(canvas_width, canvas_height, extra_scale); + m_layers_slider->Render(canvas_width, canvas_height, extra_scale, is_collapse_btn_shown ? collapse_toolbar.get_height() : 0.f); if (m_moves_slider) m_moves_slider->Render(canvas_width, canvas_height, extra_scale); } diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index f901447a43..9d8f85304d 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -135,7 +135,7 @@ public: void msw_rescale(); - void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f); + void render_sliders(GLCanvas3D& canvas); float get_layers_slider_width(); float get_moves_slider_height(); diff --git a/src/slic3r/GUI/ImGuiDoubleSlider.hpp b/src/slic3r/GUI/ImGuiDoubleSlider.hpp index 0f949ddba4..59493e8880 100644 --- a/src/slic3r/GUI/ImGuiDoubleSlider.hpp +++ b/src/slic3r/GUI/ImGuiDoubleSlider.hpp @@ -243,7 +243,7 @@ public: float GetWidth() { return m_ctrl.GetCtrlSize().x; } float GetHeight() { return m_ctrl.GetCtrlSize().y; } - virtual void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f) = 0; + virtual void Render(const int canvas_width, const int canvas_height, float extra_scale = 1.f, float offset = 0.f) = 0; void set_callback_on_thumb_move(std::function cb) { m_cb_thumb_move = cb; }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 73f3d7af20..3ba7588d34 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -385,7 +385,7 @@ struct Plater::priv void set_current_canvas_as_dirty(); GLCanvas3D* get_current_canvas3D(); - void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f); + void render_sliders(GLCanvas3D& canvas); void unbind_canvas_event_handlers(); void reset_canvas_volumes(); @@ -3185,10 +3185,10 @@ GLCanvas3D* Plater::priv::get_current_canvas3D() return (current_panel == view3D) ? view3D->get_canvas3d() : ((current_panel == preview) ? preview->get_canvas3d() : nullptr); } -void Plater::priv::render_sliders(GLCanvas3D& canvas, float extra_scale /*= 0.1f*/) +void Plater::priv::render_sliders(GLCanvas3D& canvas) { if (current_panel == preview) - preview->render_sliders(canvas, extra_scale); + preview->render_sliders(canvas); } void Plater::priv::unbind_canvas_event_handlers() @@ -6404,9 +6404,9 @@ GLCanvas3D* Plater::get_current_canvas3D() return p->get_current_canvas3D(); } -void Plater::render_sliders(GLCanvas3D& canvas, float extra_scale) +void Plater::render_sliders(GLCanvas3D& canvas) { - p->render_sliders(canvas, extra_scale); + p->render_sliders(canvas); } static std::string concat_strings(const std::set &strings, diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 656ef4a2f7..462c875e2e 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -272,7 +272,7 @@ public: const GLCanvas3D * canvas3D() const; GLCanvas3D* get_current_canvas3D(); - void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f); + void render_sliders(GLCanvas3D& canvas); void arrange(); void arrange(Worker &w, bool selected);