From abad9133ebfd48a1e048203cf1a42379207e4890 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 30 Mar 2020 11:53:58 +0200 Subject: [PATCH] Added new icon for "collapse sidebar" + The tooltip for a "Collapse" button is updated according to the collapse state --- resources/icons/collapse.svg | 16 ++++++++++++++++ src/slic3r/GUI/GLCanvas3D.cpp | 17 ++++++++++++++--- src/slic3r/GUI/GLToolbar.cpp | 6 ++++++ src/slic3r/GUI/GLToolbar.hpp | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 resources/icons/collapse.svg diff --git a/resources/icons/collapse.svg b/resources/icons/collapse.svg new file mode 100644 index 000000000..c0d6f43d5 --- /dev/null +++ b/resources/icons/collapse.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5c109ca7f..c31995e62 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5161,10 +5161,21 @@ bool GLCanvas3D::_init_undoredo_toolbar() return false; item.name = "collapse_sidebar"; - item.icon_filename = "cross.svg"; - item.tooltip = _utf8(L("Collapse right panel")); + item.icon_filename = "collapse.svg"; + item.tooltip = wxGetApp().plater()->is_sidebar_collapsed() ? + _utf8(L("Expand right panel")) : _utf8(L("Collapse right panel")); item.sprite_id = 2; - item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_COLLAPSE_SIDEBAR)); }; + item.left.action_callback = [this, item]() { + std::string new_tooltip = wxGetApp().plater()->is_sidebar_collapsed() ? + _utf8(L("Collapse right panel")) : _utf8(L("Expand right panel")); + + int id = m_undoredo_toolbar.get_item_id("collapse_sidebar"); + m_undoredo_toolbar.set_tooltip(id, new_tooltip); + set_tooltip(""); + + post_event(SimpleEvent(EVT_GLCANVAS_COLLAPSE_SIDEBAR)); + }; + item.enabling_callback = []()->bool { return true; }; if (!m_undoredo_toolbar.add_item(item)) return false; diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 4219fe482..0bd087814 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -406,6 +406,12 @@ void GLToolbar::set_additional_tooltip(int item_id, const std::string& text) m_items[item_id]->set_additional_tooltip(text); } +void GLToolbar::set_tooltip(int item_id, const std::string& text) +{ + if (0 <= item_id && item_id < (int)m_items.size()) + m_items[item_id]->set_tooltip(text); +} + bool GLToolbar::update_items_state() { bool ret = false; diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index b4aac9206..27b43fef6 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -118,6 +118,7 @@ public: const std::string& get_tooltip() const { return m_data.tooltip; } const std::string& get_additional_tooltip() const { return m_data.additional_tooltip; } void set_additional_tooltip(const std::string& text) { m_data.additional_tooltip = text; } + void set_tooltip(const std::string& text) { m_data.tooltip = text; } void do_left_action() { m_last_action_type = Left; m_data.left.action_callback(); } void do_right_action() { m_last_action_type = Right; m_data.right.action_callback(); } @@ -317,6 +318,7 @@ public: void get_additional_tooltip(int item_id, std::string& text); void set_additional_tooltip(int item_id, const std::string& text); + void set_tooltip(int item_id, const std::string& text); // returns true if any item changed its state bool update_items_state();