From 56ed912c3ee12fb0ee39f1dad191c4d379aa3015 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Tue, 27 Aug 2024 19:37:10 +0800 Subject: [PATCH] ENH: vertical layout button Change-Id: I0b205298688c9df88dcfe6eb6e72cc887a9ed5be Jira: none --- resources/images/ams_nozzle_sync.svg | 10 +++ src/slic3r/GUI/Plater.cpp | 31 +++++++--- src/slic3r/GUI/Tab.cpp | 11 ++-- src/slic3r/GUI/Widgets/Button.cpp | 91 +++++++++++++++++++++------- src/slic3r/GUI/Widgets/Button.hpp | 9 ++- src/slic3r/GUI/Widgets/Label.cpp | 13 +++- src/slic3r/GUI/Widgets/Label.hpp | 4 +- 7 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 resources/images/ams_nozzle_sync.svg diff --git a/resources/images/ams_nozzle_sync.svg b/resources/images/ams_nozzle_sync.svg new file mode 100644 index 000000000..54e935b16 --- /dev/null +++ b/resources/images/ams_nozzle_sync.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 461a812ee..e3f23d7f3 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -357,7 +357,7 @@ struct Sidebar::priv StaticBox* m_panel_printer_title = nullptr; ScalableButton* m_printer_icon = nullptr; ScalableButton* m_printer_setting = nullptr; - ScalableButton *m_extruder_sync = nullptr; + Button *m_extruder_sync = nullptr; wxStaticText * m_text_printer_settings = nullptr; wxPanel* m_panel_printer_content = nullptr; @@ -789,13 +789,6 @@ Sidebar::Sidebar(Plater *parent) m_soft_first_start = false; wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); - auto extruder_btn = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition, - wxBU_EXACTFIT | wxNO_BORDER, false, 18); - extruder_btn->SetToolTip(_L("Synchronize nozzle information and the number of AMS")); - extruder_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { - p->sync_extruder_list(); - }); - p->m_extruder_sync = extruder_btn; wxBoxSizer* h_sizer_title = new wxBoxSizer(wxHORIZONTAL); h_sizer_title->Add(p->m_printer_icon, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, em); @@ -981,6 +974,22 @@ Sidebar::Sidebar(Plater *parent) auto right_extruder = add_extruder(1, _L("Right Extruder")); p->m_right_extruder_list = right_extruder.first; p->m_right_ams_count = right_extruder.second; + p->m_dual_extruder_sizer->Add(FromDIP(2), 0); + + auto extruder_btn = new Button(p->m_panel_printer_content, _L("Sync AMS Nozzle information"), "ams_nozzle_sync"); + extruder_btn->SetFont(Label::Body_8); + extruder_btn->SetToolTip(_L("Synchronize nozzle information and the number of AMS")); + extruder_btn->SetCornerRadius(0); + extruder_btn->SetBorderColor(0xE4E4E4); + extruder_btn->SetPaddingSize({FromDIP(6), FromDIP(12)}); + extruder_btn->SetMinSize({FromDIP(48), FromDIP(68)}); + extruder_btn->SetMinSize({FromDIP(48), FromDIP(68)}); + extruder_btn->SetMaxSize({FromDIP(48), FromDIP(82)}); + extruder_btn->SetVertical(); + extruder_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { p->sync_extruder_list(); }); + p->m_extruder_sync = extruder_btn; + p->m_dual_extruder_sizer->Add(FromDIP(2), 0); + p->m_dual_extruder_sizer->Add(extruder_btn, 0, wxEXPAND); p->m_dual_extruder_sizer->Add(FromDIP(10), 0); vsizer_printer->Add(p->m_dual_extruder_sizer, 0, wxEXPAND | wxTOP, FromDIP(5)); @@ -1665,6 +1674,12 @@ void Sidebar::msw_rescale() p->m_bed_type_list->SetMinSize({-1, 3 * wxGetApp().em_unit()}); p->m_left_extruder_list->Rescale(); p->m_right_extruder_list->Rescale(); + + p->m_extruder_sync->SetPaddingSize({FromDIP(6), FromDIP(12)}); + p->m_extruder_sync->SetMinSize({FromDIP(48), FromDIP(68)}); + p->m_extruder_sync->SetMinSize({FromDIP(48), FromDIP(68)}); + p->m_extruder_sync->SetMaxSize({FromDIP(48), FromDIP(82)}); + p->m_extruder_sync->Rescale(); #if 0 if (p->mode_sizer) p->mode_sizer->msw_rescale(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index cfd0f9fe5..e808b6d80 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3172,10 +3172,6 @@ void TabFilament::build() optgroup = page->new_optgroup(L("Print temperature"), L"param_temperature"); optgroup->append_single_option_line("chamber_temperatures","chamber-temperature"); - line = { L("Nozzle"), L("Nozzle temperature when printing") }; - line.append_option(optgroup->get_option("nozzle_temperature_initial_layer", 0)); - line.append_option(optgroup->get_option("nozzle_temperature", 0)); - optgroup->append_line(line); line = {L("Bambu Cool Plate SuperTack"), L("Bed temperature when cool plate is installed. Value 0 means the filament does not support to print on the Bambu Cool Plate SuperTack")}; line.append_option(optgroup->get_option("supertack_plate_temp_initial_layer")); @@ -3232,6 +3228,13 @@ void TabFilament::build() on_value_change(opt_key, value); }; + optgroup = page->new_optgroup(L("Nozzle temperature"), L"param_temperature"); + + line = { L("Nozzle"), L("Nozzle temperature when printing") }; + line.append_option(optgroup->get_option("nozzle_temperature_initial_layer", 0)); + line.append_option(optgroup->get_option("nozzle_temperature", 0)); + optgroup->append_line(line); + //BBS optgroup = page->new_optgroup(L("Volumetric speed limitation"), L"param_volumetric_speed"); optgroup->append_single_option_line("filament_max_volumetric_speed", "", 0); diff --git a/src/slic3r/GUI/Widgets/Button.cpp b/src/slic3r/GUI/Widgets/Button.cpp index ed956b509..a487faecc 100644 --- a/src/slic3r/GUI/Widgets/Button.cpp +++ b/src/slic3r/GUI/Widgets/Button.cpp @@ -30,10 +30,10 @@ Button::Button() std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(0x37EE7C, (int) StateColor::Hovered | StateColor::Checked), std::make_pair(0x00AE42, (int) StateColor::Checked), - std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered), + std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered), std::make_pair(*wxWHITE, (int) StateColor::Normal)); text_color = StateColor( - std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled), + std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled), std::make_pair(*wxBLACK, (int) StateColor::Normal)); } @@ -150,7 +150,12 @@ bool Button::GetValue() const { return state_handler.states() & StateHandler::Ch void Button::SetCenter(bool isCenter) { - this->isCenter = isCenter; + this->isCenter = isCenter; } + +void Button::SetVertical(bool vertical) +{ + this->vertical = vertical; + messureSize(); } void Button::Rescale() @@ -184,26 +189,45 @@ void Button::render(wxDC& dc) dc.SetBrush(*wxTRANSPARENT_BRUSH); // calc content size wxSize szIcon; - wxSize szContent = textSize.GetSize(); + wxSize textSize = this->textSize.GetSize(); ScalableBitmap icon; if (m_selected || ((states & (int)StateColor::State::Hovered) != 0)) icon = active_icon; else icon = inactive_icon; - int padding = 5; + wxSize padding = this->paddingSize; + int spacing = 5; + // Wrap text + auto text = GetLabel(); + if (vertical && textSize.x + padding.x * 2 > size.x) { + Label::split_lines(dc, size.x - padding.x * 2, text, text, 2); + textSize = dc.GetMultiLineTextExtent(text); + if (padding.x * 2 + textSize.x > size.x) { + text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - padding.x * 2); + textSize = dc.GetMultiLineTextExtent(text); + } + } + auto szContent = textSize; if (icon.bmp().IsOk()) { if (szContent.y > 0) { //BBS norrow size between text and icon - szContent.x += padding; + if (vertical) + szContent.y += spacing; + else + szContent.x += spacing; } szIcon = icon.GetBmpSize(); - szContent.x += szIcon.x; - if (szIcon.y > szContent.y) - szContent.y = szIcon.y; + if (vertical) { + szContent.y += szIcon.y; + if (szIcon.x > szContent.x) szContent.x = szIcon.x; + } else { + szContent.x += szIcon.x; + if (szIcon.y > szContent.y) szContent.y = szIcon.y; + } if (szContent.x > size.x) { - int d = std::min(padding, szContent.x - size.x); - padding -= d; + int d = std::min(padding.x, (szContent.x - size.x) / 2); + padding.x -= d; szContent.x -= d; } } @@ -217,17 +241,28 @@ void Button::render(wxDC& dc) // start draw wxPoint pt = rcContent.GetLeftTop(); if (icon.bmp().IsOk()) { - pt.y += (rcContent.height - szIcon.y) / 2; + if (vertical) + pt.x += (rcContent.width - szIcon.x) / 2; + else + pt.y += (rcContent.height - szIcon.y) / 2; dc.DrawBitmap(icon.bmp(), pt); //BBS norrow size between text and icon - pt.x += szIcon.x + padding; - pt.y = rcContent.y; + if (vertical) { + pt.y += szIcon.y + spacing; + pt.x = rcContent.x; + } else { + pt.x += szIcon.x + spacing; + pt.y = rcContent.y; + } } - auto text = GetLabel(); if (!text.IsEmpty()) { - if (pt.x + textSize.width > size.x) - text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x); - pt.y += (rcContent.height - textSize.height) / 2; + if (vertical) { + pt.x += (rcContent.width - textSize.x) / 2; + } else { + if (pt.x + textSize.x > size.x) + text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x); + pt.y += (rcContent.height - textSize.y) / 2; + } dc.SetTextForeground(text_color.colorForStates(states)); #if 0 dc.SetBrush(*wxLIGHT_GREY); @@ -249,17 +284,27 @@ void Button::messureSize() if (this->active_icon.bmp().IsOk()) { if (szContent.y > 0) { //BBS norrow size between text and icon - szContent.x += 5; + if (vertical) + szContent.y += 5; + else + szContent.x += 5; } wxSize szIcon = this->active_icon.GetBmpSize(); - szContent.x += szIcon.x; - if (szIcon.y > szContent.y) - szContent.y = szIcon.y; + if (vertical) { + szContent.y += szIcon.y; + if (szIcon.x > szContent.x) szContent.x = szIcon.x; + } else { + szContent.x += szIcon.x; + if (szIcon.y > szContent.y) szContent.y = szIcon.y; + } } wxSize size = szContent + paddingSize * 2; if (minSize.GetHeight() > 0) size.SetHeight(minSize.GetHeight()); + if (auto w = GetMaxWidth(); w > 0 && size.GetWidth() > w) + size.SetWidth(GetMaxWidth()); + if (minSize.GetWidth() > size.GetWidth()) wxWindow::SetMinSize(minSize); else @@ -303,7 +348,7 @@ void Button::keyDownUp(wxKeyEvent &event) return; } if (event.GetEventType() == wxEVT_KEY_DOWN && - (event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT + (event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT || event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN)) HandleAsNavigationKey(event); else diff --git a/src/slic3r/GUI/Widgets/Button.hpp b/src/slic3r/GUI/Widgets/Button.hpp index d3496c0e4..10b44f160 100644 --- a/src/slic3r/GUI/Widgets/Button.hpp +++ b/src/slic3r/GUI/Widgets/Button.hpp @@ -17,7 +17,8 @@ class Button : public StaticBox bool pressedDown = false; bool m_selected = true; bool canFocus = true; - bool isCenter = true; + bool isCenter = true; + bool vertical = false; static const int buttonWidth = 200; static const int buttonHeight = 50; @@ -38,9 +39,9 @@ public: void SetInactiveIcon(const wxString& icon); void SetMinSize(const wxSize& size) override; - + void SetPaddingSize(const wxSize& size); - + void SetTextColor(StateColor const &color); void SetTextColorNormal(wxColor const &color); @@ -57,6 +58,8 @@ public: void SetCenter(bool isCenter); + void SetVertical(bool vertical = true); + void Rescale(); protected: diff --git a/src/slic3r/GUI/Widgets/Label.cpp b/src/slic3r/GUI/Widgets/Label.cpp index 451aa5cd8..ef1ca64ec 100644 --- a/src/slic3r/GUI/Widgets/Label.cpp +++ b/src/slic3r/GUI/Widgets/Label.cpp @@ -112,11 +112,12 @@ public: Wrap(dc, text, widthMax); } - void Wrap(wxDC const & dc, const wxString &text, int widthMax) + void Wrap(wxDC const &dc, const wxString &text, int widthMax, int maxCount = 0) { const wxArrayString ls = wxSplit(text, '\n', '\0'); for (wxArrayString::const_iterator i = ls.begin(); i != ls.end(); ++i) { wxString line = *i; + int count = 0; if (i != ls.begin()) { // Do this even if the line is empty, except if it's the first one. @@ -176,6 +177,12 @@ public: // And redo the layout with the rest. if (line[lastSpace] == ' ') ++lastSpace; line = line.substr(lastSpace); + + if (maxCount > 0 && ++count == maxCount - 1) { + OnNewLine(); + DoOutputLine(line); + break; + } } } } @@ -241,10 +248,10 @@ private: }; -wxSize Label::split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text) +wxSize Label::split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text, int max_count) { wxLabelWrapper2 wrap; - wrap.Wrap(dc, text, width); + wrap.Wrap(dc, text, width, max_count); multiline_text = wrap.GetText(); return dc.GetMultiLineTextExtent(multiline_text); } diff --git a/src/slic3r/GUI/Widgets/Label.hpp b/src/slic3r/GUI/Widgets/Label.hpp index b3581406a..f34e5be6d 100644 --- a/src/slic3r/GUI/Widgets/Label.hpp +++ b/src/slic3r/GUI/Widgets/Label.hpp @@ -53,12 +53,12 @@ public: static wxFont Body_11; static wxFont Body_9; static wxFont Body_8; - + static void initSysFont(std::string lang_code = "", bool load_font_resource = true); static wxFont sysFont(int size, bool bold = false, std::string lang_code = ""); - static wxSize split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text); + static wxSize split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text, int max_count = 0); }; #endif // !slic3r_GUI_Label_hpp_