Files
OrcaSlicer/src/slic3r/GUI/Notebook.cpp
T
Kris AustinandRodrigo Faselli 1749c293a6 build: clear 237 warnings - unused lambda captures (#15417)
* build: enable /Zc:lambda for MSVC

MSVC keeps its legacy lambda processor under /std:c++17, which rejects
reading a constexpr constant inside a lambda that does not capture it
(C3493). No other compiler requires that capture, and clang reports it as
an unused one, so the two cannot both be satisfied without the flag.

/Zc:lambda selects the conforming lambda parser that clang and GCC
already use. It is implied by /std:c++20 and /permissive-, so it is only
needed while we are on C++17. clang-cl is conforming already and does not
take the flag.

It requires VS2019 16.8, so build_release_vs.bat now says 16.8+.

* build: clear 237 unused lambda capture warnings

236 captures across 81 files, 142 of them `this`. Removing an unused
capture changes no behavior; clang does not report a capture whose type
has a non-trivial destructor, so nothing held only to extend an object's
lifetime is in this set.

Nine of them are the second half of the warning, "is not required to be
captured for this use", where the capture is a const or constexpr value
the body does read. Those depend on the /Zc:lambda change in the previous
commit. One of them, in FillRectilinear.cpp, had been worked around with
an #ifndef __APPLE__ guard around the capture list, which is now gone.

GUI_ObjectTableSettings.cpp captured its reset button only to read it
inside #ifdef __WXOSX_MAC__. That branch now takes the button from the
event it is already handling.

* build: fail configure on MSVC older than 19.28 instead of dropping /Zc:lambda

cl.exe answers an unrecognized /Zc: sub-option with warning D9002 and keeps
going, so on VS2019 before 16.8 the flag is silently ignored and the build
instead dies with C3493 in FillRectilinear.cpp, nowhere near the cause.

* fix: delete three locals that are now unused

Their only remaining use was the lambda capture this branch removed. The
Clang builds set -Wno-unused-variable, so the build never flagged them.

---------

Co-authored-by: Rodrigo Faselli <162915171+RF47@users.noreply.github.com>
2026-09-02 07:38:05 -03:00

300 lines
9.1 KiB
C++

#include "Notebook.hpp"
//#ifdef _WIN32
#include "GUI_App.hpp"
#include "wxExtensions.hpp"
#include "Widgets/Button.hpp"
//BBS set font size
#include "Widgets/Label.hpp"
#include <wx/button.h>
#include <wx/sizer.h>
wxDEFINE_EVENT(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, wxCommandEvent);
ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, wxBoxSizer* side_tools) :
wxControl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxTAB_TRAVERSAL)
{
#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__
wxColour default_btn_bg;
#ifdef __APPLE__
default_btn_bg = wxColour("#3B4446"); // Gradient #414B4E
#else
default_btn_bg = wxColour("#2D2D30"); // Gradient #414B4E
#endif
SetBackgroundColour(default_btn_bg);
int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit();
// BBS: no gap
m_btn_margin = 0; // std::lround(0.3 * em);
m_line_margin = std::lround(0.1 * em);
m_sizer = new wxBoxSizer(wxHORIZONTAL);
this->SetSizer(m_sizer);
m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin);
m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
if (side_tools != NULL) {
m_sizer->AddStretchSpacer(1);
for (size_t idx = 0; idx < side_tools->GetItemCount(); idx++) {
wxSizerItem* item = side_tools->GetItem(idx);
wxWindow* item_win = item->GetWindow();
if (item_win) {
item_win->Reparent(this);
}
}
m_sizer->Add(side_tools, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin);
}
// BBS: disable custom paint
//this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this);
Bind(wxEVT_SYS_COLOUR_CHANGED, [](auto& e){
});
}
void ButtonsListCtrl::OnPaint(wxPaintEvent&)
{
//Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
const wxSize sz = GetSize();
wxPaintDC dc(this);
if (m_selection < 0 || m_selection >= (int)m_pageButtons.size())
return;
wxColour selected_btn_bg("#1F8EEA");
wxColour default_btn_bg("#3B4446"); // Gradient #414B4E
const wxColour& btn_marker_color = Slic3r::GUI::wxGetApp().get_color_hovered_btn_label();
// highlight selected notebook button
for (int idx = 0; idx < int(m_pageButtons.size()); idx++) {
Button* btn = m_pageButtons[idx];
btn->SetBackgroundColor(idx == m_selection ? selected_btn_bg : default_btn_bg);
wxPoint pos = btn->GetPosition();
wxSize size = btn->GetSize();
const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg;
dc.SetPen(clr);
dc.SetBrush(clr);
dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
}
// Draw orange bottom line
dc.SetPen(btn_marker_color);
dc.SetBrush(btn_marker_color);
dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin);
}
void ButtonsListCtrl::UpdateMode()
{
//m_mode_sizer->SetMode(Slic3r::GUI::wxGetApp().get_mode());
}
void ButtonsListCtrl::Rescale()
{
//m_mode_sizer->msw_rescale();
int em = em_unit(this);
for (Button* btn : m_pageButtons) {
//BBS
btn->SetMinSize({(btn->GetLabel().empty() ? 40 : 132) * em / 10, 36 * em / 10});
btn->Rescale();
}
// BBS: no gap
//m_btn_margin = std::lround(0.3 * em);
//m_line_margin = std::lround(0.1 * em);
//m_buttons_sizer->SetVGap(m_btn_margin);
//m_buttons_sizer->SetHGap(m_btn_margin);
m_sizer->Layout();
}
void ButtonsListCtrl::SetSelection(int sel)
{
if (m_selection == sel && sel >= 0 && sel < static_cast<int>(m_pageButtons.size()))
return;
// BBS: change button color
wxColour selected_btn_bg("#009688"); // Gradient #009688
if (m_selection >= 0 && m_selection < static_cast<int>(m_pageButtons.size())) {
StateColor bg_color = StateColor(
std::pair{wxColour(107, 107, 107), (int) StateColor::Hovered},
std::pair{wxColour(59, 68, 70), (int) StateColor::Normal});
m_pageButtons[m_selection]->SetBackgroundColor(bg_color);
StateColor text_color = StateColor(
std::pair{wxColour(254,254, 254), (int) StateColor::Normal}
);
m_pageButtons[m_selection]->SetTextColor(text_color);
}
if (sel < 0 || sel >= static_cast<int>(m_pageButtons.size())) {
m_selection = -1;
Refresh();
return;
}
m_selection = sel;
StateColor bg_color = StateColor(
std::pair{wxColour(0, 150, 136), (int) StateColor::Hovered},
std::pair{wxColour(0,150, 136), (int) StateColor::Normal});
m_pageButtons[m_selection]->SetBackgroundColor(bg_color);
StateColor text_color = StateColor(
std::pair{wxColour(254, 254, 254), (int) StateColor::Normal}
);
m_pageButtons[m_selection]->SetTextColor(text_color);
Refresh();
}
bool ButtonsListCtrl::InsertPage(size_t n, const wxString &text, bool bSelect /* = false*/, const std::string &bmp_name /* = ""*/, const wxBitmap &bmp /* = wxNullBitmap */)
{
Button * btn = new Button(this, text.empty() ? text : " " + text, bmp_name, wxNO_BORDER);
btn->SetCornerRadius(0);
if (bmp_name.empty() && bmp.IsOk())
btn->SetIcon(bmp);
int em = em_unit(this);
//BBS set size for button
btn->SetMinSize({(text.empty() ? 40 : 136) * em / 10, 36 * em / 10});
StateColor bg_color = StateColor(
std::pair{wxColour(107, 107, 107), (int) StateColor::Hovered},
std::pair{wxColour(59, 68, 70), (int) StateColor::Normal});
btn->SetBackgroundColor(bg_color);
StateColor text_color = StateColor(
std::pair{wxColour(254,254, 254), (int) StateColor::Normal});
btn->SetTextColor(text_color);
btn->Bind(wxEVT_BUTTON, [this, btn](wxCommandEvent& event) {
if (auto it = std::find(m_pageButtons.begin(), m_pageButtons.end(), btn); it != m_pageButtons.end()) {
auto sel = it - m_pageButtons.begin();
//do it later
//SetSelection(sel);
wxCommandEvent evt = wxCommandEvent(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED);
evt.SetId(sel);
wxPostEvent(this->GetParent(), evt);
}
});
Slic3r::GUI::wxGetApp().UpdateDarkUI(btn);
m_pageButtons.insert(m_pageButtons.begin() + n, btn);
m_pageLabels.insert(m_pageLabels.begin() + n, text); // ORCA
m_buttons_sizer->Insert(n, new wxSizerItem(btn));
m_buttons_sizer->SetCols(m_buttons_sizer->GetCols() + 1);
m_sizer->Layout();
return true;
}
void ButtonsListCtrl::RemovePage(size_t n)
{
if (n >= m_pageButtons.size())
return;
if (m_selection == static_cast<int>(n))
m_selection = -1;
else if (m_selection > static_cast<int>(n))
--m_selection;
Button* btn = m_pageButtons[n];
m_pageButtons.erase(m_pageButtons.begin() + n);
m_pageLabels.erase(m_pageLabels.begin() + n); // ORCA
m_buttons_sizer->Remove(n);
#if __WXOSX__
RemoveChild(btn);
#else
btn->Reparent(nullptr);
#endif
btn->Destroy();
m_sizer->Layout();
}
bool ButtonsListCtrl::SetPageImage(size_t n, const std::string& bmp_name) const
{
if (n >= m_pageButtons.size())
return false;
// BBS
//return m_pageButtons[n]->SetBitmap_(bmp_name);
ScalableBitmap bitmap(NULL, bmp_name);
//m_pageButtons[n]->SetBitmap_(bitmap);
return true;
}
void ButtonsListCtrl::SetPageText(size_t n, const wxString& strText)
{
Button* btn = m_pageButtons[n];
btn->SetLabel(strText);
if(!strText.empty()) // ORCA
m_pageLabels[n] = strText;
}
// ORCA
void ButtonsListCtrl::SetCompact(size_t n, bool compact)
{
int em = em_unit(this);
Button* btn = m_pageButtons[n];
btn->SetMinSize({(compact ? 40 : 136) * em / 10, 36 * em / 10});
btn->SetLabel(compact ? "" : (" " + m_pageLabels[n]));
}
wxString ButtonsListCtrl::GetPageText(size_t n) const
{
Button* btn = m_pageButtons[n];
return btn->GetLabel();
}
// ORCA
void ButtonsListCtrl::SetOverflowButton(wxWindow* button)
{
if (m_overflow_button == button)
return;
if (m_overflow_button != nullptr)
m_sizer->Detach(m_overflow_button);
m_overflow_button = button;
if (m_overflow_button != nullptr)
// Right after the tab buttons (index 0), ahead of any stretch spacer / side_tools.
m_sizer->Insert(1, m_overflow_button, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
m_sizer->Layout();
}
//#endif // _WIN32
void Notebook::Init()
{
// We don't need any border as we don't have anything to separate the
// page contents from.
SetInternalBorder(0);
// No effects by default.
m_showEffect = m_hideEffect = wxSHOW_EFFECT_NONE;
m_showTimeout = m_hideTimeout = 0;
m_pageNames.clear();
/* On Linux, Gstreamer wxMediaCtrl does not seem to get along well with
* 32-bit X11 visuals (the overlay does not work). Is this a wxWindows
* bug? Is this a Gstreamer bug? No idea, but it is our problem ...
* and anyway, this transparency thing just isn't all that interesting,
* so we just don't do it on Linux.
*/
#ifndef __WXGTK__
SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
#endif
}