ENH: vertical layout button

Change-Id: I0b205298688c9df88dcfe6eb6e72cc887a9ed5be
Jira: none
This commit is contained in:
chunmao.guo 2024-08-27 19:37:10 +08:00 committed by lane.wei
parent 7f473c2027
commit 56ed912c3e
7 changed files with 126 additions and 43 deletions

View File

@ -0,0 +1,10 @@
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_17986_6045)">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.5612 4.68047C10.3877 4.68047 8.43221 5.60859 7.06718 7.0927C7.0249 7.13866 6.9832 7.18516 6.94207 7.23217L5.66253 6.1129C5.71296 6.05524 5.76411 5.99823 5.81595 5.94186C7.48937 4.12247 9.89256 2.98047 12.5612 2.98047C16.8403 2.98047 20.4343 5.91384 21.442 9.87942L22.7119 8.09588L24.0968 9.0819L20.0238 14.8023V12.143C20.0238 8.02156 16.6827 4.68047 12.5612 4.68047ZM4.78491 9.48372V12.143C4.78491 16.2645 8.126 19.6055 12.2474 19.6055C14.421 19.6055 16.3765 18.6774 17.7415 17.1933C17.7838 17.1473 17.8255 17.1009 17.8666 17.0538L19.1461 18.1731C19.0957 18.2308 19.0446 18.2878 18.9927 18.3442C17.3193 20.1635 14.9161 21.3055 12.2474 21.3055C7.96834 21.3055 4.37436 18.3722 3.36665 14.4066L2.09675 16.1901L0.711914 15.2041L4.78491 9.48372Z" fill="#262E30"/>
</g>
<defs>
<clipPath id="clip0_17986_6045">
<rect width="24" height="24" fill="white" transform="translate(0.404297 0.142578)"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -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();

View File

@ -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);

View File

@ -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();
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 (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()) {
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;
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)
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.height) / 2;
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
if (vertical)
szContent.y += 5;
else
szContent.x += 5;
}
wxSize szIcon = this->active_icon.GetBmpSize();
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 (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

View File

@ -18,6 +18,7 @@ class Button : public StaticBox
bool m_selected = true;
bool canFocus = true;
bool isCenter = true;
bool vertical = false;
static const int buttonWidth = 200;
static const int buttonHeight = 50;
@ -57,6 +58,8 @@ public:
void SetCenter(bool isCenter);
void SetVertical(bool vertical = true);
void Rescale();
protected:

View File

@ -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);
}

View File

@ -58,7 +58,7 @@ public:
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_