OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
ButtonsListCtrl Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Notebook.hpp>

Inheritance diagram for ButtonsListCtrl:
Collaboration diagram for ButtonsListCtrl:

Public Member Functions

 ButtonsListCtrl (wxWindow *parent, wxBoxSizer *side_tools=NULL)
 ~ButtonsListCtrl ()
void OnPaint (wxPaintEvent &)
void SetSelection (int sel)
void UpdateMode ()
void Rescale ()
bool InsertPage (size_t n, const wxString &text, bool bSelect=false, const std::string &bmp_name="", const wxBitmap &bmp=wxNullBitmap)
void RemovePage (size_t n)
bool SetPageImage (size_t n, const std::string &bmp_name) const
void SetPageText (size_t n, const wxString &strText)
void SetCompact (size_t n, bool compact)
wxString GetPageText (size_t n) const
wxString GetPageLabel (size_t n) const
const std::string & GetPageIcon (size_t n) const
wxFlexGridSizer * GetBtnsSizer ()
void SetOverflowButton (wxWindow *button)
wxWindow * GetOverflowButton () const

Private Attributes

wxFlexGridSizer * m_buttons_sizer
wxBoxSizer * m_sizer
std::vector< Button * > m_pageButtons
int m_selection {-1}
int m_btn_margin
int m_line_margin
std::vector< wxString > m_pageLabels
std::vector< std::string > m_pageIcons
wxWindow * m_overflow_button {nullptr}

Detailed Description

Constructor & Destructor Documentation

◆ ButtonsListCtrl()

ButtonsListCtrl::ButtonsListCtrl ( wxWindow * parent,
wxBoxSizer * side_tools = NULL )
27 :
28 wxControl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxTAB_TRAVERSAL)
29{
30#ifdef __WINDOWS__
31 SetDoubleBuffered(true);
32#endif //__WINDOWS__
33
34 wxColour default_btn_bg;
35#ifdef __APPLE__
36 default_btn_bg = wxColour("#3B4446"); // Gradient #414B4E
37#else
38 default_btn_bg = wxColour("#2D2D30"); // Gradient #414B4E
39#endif
40
41
42 SetBackgroundColour(default_btn_bg);
43
44 int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit();
45 // BBS: no gap
46 m_btn_margin = 0; // std::lround(0.3 * em);
47 m_line_margin = std::lround(0.1 * em);
48
49 m_sizer = new wxBoxSizer(wxHORIZONTAL);
50 this->SetSizer(m_sizer);
51
52 m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin);
53 m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
54
55 if (side_tools != NULL) {
56 m_sizer->AddStretchSpacer(1);
57 for (size_t idx = 0; idx < side_tools->GetItemCount(); idx++) {
58 wxSizerItem* item = side_tools->GetItem(idx);
59 wxWindow* item_win = item->GetWindow();
60 if (item_win) {
61 item_win->Reparent(this);
62 }
63 }
64 m_sizer->Add(side_tools, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin);
65 }
66
67 // BBS: disable custom paint
68 //this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this);
69 Bind(wxEVT_SYS_COLOUR_CHANGED, [](auto& e){
70 });
71}
wxFlexGridSizer * m_buttons_sizer
Definition Notebook.hpp:63
wxBoxSizer * m_sizer
Definition Notebook.hpp:64
int m_line_margin
Definition Notebook.hpp:69
int m_btn_margin
Definition Notebook.hpp:68
int em_unit(wxWindow *win)
Definition wxExtensions.cpp:424

References em_unit(), m_btn_margin, m_buttons_sizer, m_line_margin, and m_sizer.

Here is the call graph for this function:

◆ ~ButtonsListCtrl()

ButtonsListCtrl::~ButtonsListCtrl ( )
inline
36{}

Member Function Documentation

◆ GetBtnsSizer()

wxFlexGridSizer * ButtonsListCtrl::GetBtnsSizer ( )
inline
56{return m_buttons_sizer;}; // ORCA

References m_buttons_sizer.

◆ GetOverflowButton()

wxWindow * ButtonsListCtrl::GetOverflowButton ( ) const
inline
60{ return m_overflow_button; }
wxWindow * m_overflow_button
Definition Notebook.hpp:72

References m_overflow_button.

◆ GetPageIcon()

const std::string & ButtonsListCtrl::GetPageIcon ( size_t n) const
inline
52 {
53 static const std::string empty;
54 return n < m_pageIcons.size() ? m_pageIcons[n] : empty;
55 }
std::vector< std::string > m_pageIcons
Definition Notebook.hpp:71
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References m_pageIcons.

Referenced by Notebook::GetPageIcon().

Here is the caller graph for this function:

◆ GetPageLabel()

wxString ButtonsListCtrl::GetPageLabel ( size_t n) const
281{
282 return n < m_pageLabels.size() ? m_pageLabels[n] : wxString();
283}
std::vector< wxString > m_pageLabels
Definition Notebook.hpp:70

References m_pageLabels.

Referenced by Notebook::GetPageLabel().

Here is the caller graph for this function:

◆ GetPageText()

wxString ButtonsListCtrl::GetPageText ( size_t n) const
274{
275 Button* btn = m_pageButtons[n];
276 return btn->GetLabel();
277}
std::vector< Button * > m_pageButtons
Definition Notebook.hpp:66

References m_pageButtons.

Referenced by Notebook::GetPageText().

Here is the caller graph for this function:

◆ InsertPage()

bool ButtonsListCtrl::InsertPage ( size_t n,
const wxString & text,
bool bSelect = false,
const std::string & bmp_name = "",
const wxBitmap & bmp = wxNullBitmap )
170{
171 Button * btn = new Button(this, text, bmp_name, wxNO_BORDER);
172 btn->SetCornerRadius(0);
173
174 if (bmp_name.empty() && bmp.IsOk())
175 btn->SetIcon(bmp);
176
177 // The label no longer carries a leading space, so widen the icon<->text gap to keep the
178 // original spacing between a tab's icon and its caption.
179 {
180 wxClientDC dc(btn);
181 dc.SetFont(btn->GetFont());
182 int space_w = 0;
183 dc.GetTextExtent(" ", &space_w, nullptr);
184 btn->SetIconSpacing(5 + space_w);
185 }
186
187 int em = em_unit(this);
188 //BBS set size for button
189 btn->SetMinSize({(text.empty() ? 40 : 136) * em / 10, 36 * em / 10});
190
191 StateColor bg_color = StateColor(
192 std::pair{wxColour(107, 107, 107), (int) StateColor::Hovered},
193 std::pair{wxColour(59, 68, 70), (int) StateColor::Normal});
194
195 btn->SetBackgroundColor(bg_color);
196 StateColor text_color = StateColor(
197 std::pair{wxColour(254,254, 254), (int) StateColor::Normal});
199 btn->Bind(wxEVT_BUTTON, [this, btn](wxCommandEvent& event) {
200 if (auto it = std::find(m_pageButtons.begin(), m_pageButtons.end(), btn); it != m_pageButtons.end()) {
201 auto sel = it - m_pageButtons.begin();
202 //do it later
203 //SetSelection(sel);
204
205 wxCommandEvent evt = wxCommandEvent(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED);
206 evt.SetId(sel);
207 wxPostEvent(this->GetParent(), evt);
208 }
209 });
210 Slic3r::GUI::wxGetApp().UpdateDarkUI(btn);
211 m_pageButtons.insert(m_pageButtons.begin() + n, btn);
212 m_pageLabels.insert(m_pageLabels.begin() + n, text); // ORCA
213 m_pageIcons.insert(m_pageIcons.begin() + n, bmp_name);
214 m_buttons_sizer->Insert(n, new wxSizerItem(btn));
215 m_buttons_sizer->SetCols(m_buttons_sizer->GetCols() + 1);
216 m_sizer->Layout();
217 return true;
218}
const wxColour text_color(107, 107, 107)
void SetMinSize(const wxSize &size) override
Definition Button.cpp:112
void SetTextColor(StateColor const &color)
Definition Button.cpp:137
void SetIconSpacing(int spacing)
Definition Button.cpp:130
void SetIcon(const wxString &icon)
Definition Button.cpp:89
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
void SetCornerRadius(double radius)
Definition StaticBox.cpp:62
void SetBackgroundColor(StateColor const &color)
Definition StaticBox.cpp:102
wxColour bg_color()
Definition SpeedDialDialog.cpp:69

References em_unit(), StateColor::Hovered, m_buttons_sizer, m_pageButtons, m_pageIcons, m_pageLabels, m_sizer, StateColor::Normal, StaticBox::SetBackgroundColor(), StaticBox::SetCornerRadius(), Button::SetIcon(), Button::SetIconSpacing(), Button::SetMinSize(), Button::SetTextColor(), and text_color().

Referenced by Notebook::InsertPage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnPaint()

void ButtonsListCtrl::OnPaint ( wxPaintEvent & )
74{
75 //Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
76 const wxSize sz = GetSize();
77 wxPaintDC dc(this);
78
80 return;
81
82 wxColour selected_btn_bg("#1F8EEA");
83 wxColour default_btn_bg("#3B4446"); // Gradient #414B4E
84 const wxColour& btn_marker_color = Slic3r::GUI::wxGetApp().get_color_hovered_btn_label();
85
86 // highlight selected notebook button
87
88 for (int idx = 0; idx < int(m_pageButtons.size()); idx++) {
89 Button* btn = m_pageButtons[idx];
90
91 btn->SetBackgroundColor(idx == m_selection ? selected_btn_bg : default_btn_bg);
92
93 wxPoint pos = btn->GetPosition();
94 wxSize size = btn->GetSize();
95 const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg;
96 dc.SetPen(clr);
97 dc.SetBrush(clr);
98 dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
99 }
100 // Draw orange bottom line
101
102 dc.SetPen(btn_marker_color);
103 dc.SetBrush(btn_marker_color);
104 dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin);
105}
int m_selection
Definition Notebook.hpp:67
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References m_line_margin, m_pageButtons, m_selection, and StaticBox::SetBackgroundColor().

Here is the call graph for this function:

◆ RemovePage()

void ButtonsListCtrl::RemovePage ( size_t n)
221{
222 if (n >= m_pageButtons.size())
223 return;
224
225 if (m_selection == static_cast<int>(n))
226 m_selection = -1;
227 else if (m_selection > static_cast<int>(n))
228 --m_selection;
229
230 Button* btn = m_pageButtons[n];
231 m_pageButtons.erase(m_pageButtons.begin() + n);
232 m_pageLabels.erase(m_pageLabels.begin() + n); // ORCA
233 m_pageIcons.erase(m_pageIcons.begin() + n);
234 m_buttons_sizer->Remove(n);
235#if __WXOSX__
236 RemoveChild(btn);
237#else
238 btn->Reparent(nullptr);
239#endif
240 btn->Destroy();
241 m_sizer->Layout();
242}

References m_buttons_sizer, m_pageButtons, m_pageIcons, m_pageLabels, m_selection, and m_sizer.

Referenced by Notebook::DoRemovePage().

Here is the caller graph for this function:

◆ Rescale()

void ButtonsListCtrl::Rescale ( )
113{
114 //m_mode_sizer->msw_rescale();
115 int em = em_unit(this);
116 for (Button* btn : m_pageButtons) {
117 //BBS
118 btn->SetMinSize({(btn->GetLabel().empty() ? 40 : 132) * em / 10, 36 * em / 10});
119 btn->Rescale();
120 }
121
122 // BBS: no gap
123 //m_btn_margin = std::lround(0.3 * em);
124 //m_line_margin = std::lround(0.1 * em);
125 //m_buttons_sizer->SetVGap(m_btn_margin);
126 //m_buttons_sizer->SetHGap(m_btn_margin);
127
128 m_sizer->Layout();
129}

References em_unit(), m_pageButtons, and m_sizer.

Referenced by Notebook::Rescale().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCompact()

void ButtonsListCtrl::SetCompact ( size_t n,
bool compact )
266{
267 int em = em_unit(this);
268 Button* btn = m_pageButtons[n];
269 btn->SetMinSize({(compact ? 40 : 136) * em / 10, 36 * em / 10});
270 btn->SetLabel(compact ? "" : m_pageLabels[n]);
271}
void SetLabel(const wxString &label) override
Definition Button.cpp:72
void compact(const VertexInfos &v_infos, const TriangleInfos &t_infos, const EdgeInfos &e_infos, indexed_triangle_set &its)
Definition QuadricEdgeCollapse.cpp:842

References em_unit(), m_pageButtons, m_pageLabels, Button::SetLabel(), and Button::SetMinSize().

Here is the call graph for this function:

◆ SetOverflowButton()

void ButtonsListCtrl::SetOverflowButton ( wxWindow * button)
287{
288 if (m_overflow_button == button)
289 return;
290
291 if (m_overflow_button != nullptr)
292 m_sizer->Detach(m_overflow_button);
293
295
296 if (m_overflow_button != nullptr)
297 // Right after the tab buttons (index 0), ahead of any stretch spacer / side_tools.
298 m_sizer->Insert(1, m_overflow_button, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
299
300 m_sizer->Layout();
301}
bool button(const IconManager::Icon &activ, const IconManager::Icon &hover, const IconManager::Icon &disable, bool disabled)
Use icon as button with 3 states activ hover and disabled.
Definition IconManager.cpp:418

References m_btn_margin, m_overflow_button, and m_sizer.

Referenced by Notebook::SetOverflowButton().

Here is the caller graph for this function:

◆ SetPageImage()

bool ButtonsListCtrl::SetPageImage ( size_t n,
const std::string & bmp_name ) const
245{
246 if (n >= m_pageButtons.size())
247 return false;
248
249 // BBS
250 //return m_pageButtons[n]->SetBitmap_(bmp_name);
251 ScalableBitmap bitmap(NULL, bmp_name);
252 //m_pageButtons[n]->SetBitmap_(bitmap);
253 return true;
254}

References m_pageButtons.

Referenced by Notebook::SetPageImage().

Here is the caller graph for this function:

◆ SetPageText()

void ButtonsListCtrl::SetPageText ( size_t n,
const wxString & strText )
257{
258 Button* btn = m_pageButtons[n];
259 btn->SetLabel(strText);
260 if(!strText.empty()) // ORCA
261 m_pageLabels[n] = strText;
262}

References m_pageButtons, m_pageLabels, and Button::SetLabel().

Referenced by Notebook::SetPageText().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSelection()

void ButtonsListCtrl::SetSelection ( int sel)
132{
133 if (m_selection == sel && sel >= 0 && sel < static_cast<int>(m_pageButtons.size()))
134 return;
135 // BBS: change button color
136 wxColour selected_btn_bg("#009688"); // Gradient #009688
137 if (m_selection >= 0 && m_selection < static_cast<int>(m_pageButtons.size())) {
138 StateColor bg_color = StateColor(
139 std::pair{wxColour(107, 107, 107), (int) StateColor::Hovered},
140 std::pair{wxColour(59, 68, 70), (int) StateColor::Normal});
141 m_pageButtons[m_selection]->SetBackgroundColor(bg_color);
142 StateColor text_color = StateColor(
143 std::pair{wxColour(254,254, 254), (int) StateColor::Normal}
144 );
145 m_pageButtons[m_selection]->SetTextColor(text_color);
146 }
147
148 if (sel < 0 || sel >= static_cast<int>(m_pageButtons.size())) {
149 m_selection = -1;
150 Refresh();
151 return;
152 }
153
154 m_selection = sel;
155
156 StateColor bg_color = StateColor(
157 std::pair{wxColour(0, 150, 136), (int) StateColor::Hovered},
158 std::pair{wxColour(0,150, 136), (int) StateColor::Normal});
159 m_pageButtons[m_selection]->SetBackgroundColor(bg_color);
160
161 StateColor text_color = StateColor(
162 std::pair{wxColour(254, 254, 254), (int) StateColor::Normal}
163 );
164 m_pageButtons[m_selection]->SetTextColor(text_color);
165
166 Refresh();
167}

References StateColor::Hovered, m_pageButtons, m_selection, StateColor::Normal, and text_color().

Referenced by Notebook::ChangeSelection(), and Notebook::SetSelection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateMode()

void ButtonsListCtrl::UpdateMode ( )
108{
109 //m_mode_sizer->SetMode(Slic3r::GUI::wxGetApp().get_mode());
110}

Referenced by Notebook::UpdateMode().

Here is the caller graph for this function:

Member Data Documentation

◆ m_btn_margin

int ButtonsListCtrl::m_btn_margin
private

◆ m_buttons_sizer

wxFlexGridSizer* ButtonsListCtrl::m_buttons_sizer
private

◆ m_line_margin

int ButtonsListCtrl::m_line_margin
private

Referenced by ButtonsListCtrl(), and OnPaint().

◆ m_overflow_button

wxWindow* ButtonsListCtrl::m_overflow_button {nullptr}
private
72{nullptr}; // ORCA

Referenced by GetOverflowButton(), and SetOverflowButton().

◆ m_pageButtons

std::vector<Button*> ButtonsListCtrl::m_pageButtons
private

◆ m_pageIcons

std::vector<std::string> ButtonsListCtrl::m_pageIcons
private

Referenced by GetPageIcon(), InsertPage(), and RemovePage().

◆ m_pageLabels

std::vector<wxString> ButtonsListCtrl::m_pageLabels
private

◆ m_selection

int ButtonsListCtrl::m_selection {-1}
private
67{-1};

Referenced by OnPaint(), RemovePage(), and SetSelection().

◆ m_sizer

wxBoxSizer* ButtonsListCtrl::m_sizer
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Notebook.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Notebook.cpp