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

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

Inheritance diagram for RadioGroup:
Collaboration diagram for RadioGroup:

Public Member Functions

 RadioGroup ()
 RadioGroup (wxWindow *parent, const std::vector< wxString > &labels={"1", "2", "3"}, long direction=wxHORIZONTAL, int row_col_limit=-1)
void Create (wxWindow *parent, const std::vector< wxString > &labels={"1", "2", "3"}, long direction=wxHORIZONTAL, int row_col_limit=-1)
int GetSelection ()
void SetSelection (int index, bool focus=false)
void SelectNext (bool focus=true)
void SelectPrevious (bool focus=true)
bool Enable (bool enable=true) override
bool IsEnabled ()
bool Disable ()
void SetRadioTooltip (int i, wxString tooltip)

Private Member Functions

void SetRadioIcon (int i, bool hover)

Private Attributes

std::vector< wxString > m_labels
std::vector< wxStaticBitmap * > m_radioButtons
std::vector< Button * > m_labelButtons
int m_selectedIndex
int m_item_count
bool m_focused
bool m_enabled
StateColor m_focus_color
StateColor m_text_color
ScalableBitmap m_on
ScalableBitmap m_off
ScalableBitmap m_on_hover
ScalableBitmap m_off_hover
ScalableBitmap m_disabled

Detailed Description

Constructor & Destructor Documentation

◆ RadioGroup() [1/2]

RadioGroup::RadioGroup ( )

◆ RadioGroup() [2/2]

RadioGroup::RadioGroup ( wxWindow * parent,
const std::vector< wxString > & labels = {"1", "2", "3"},
long direction = wxHORIZONTAL,
int row_col_limit = -1 )
27 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER) // ensure wxTAB_TRAVERSAL not applied by default
28 , m_on( this, "radio_on" , 18)
29 , m_off( this, "radio_off" , 18)
30 , m_on_hover( this, "radio_on_hover" , 18)
31 , m_off_hover(this, "radio_off_hover", 18)
32 , m_disabled( this, "radio_disabled" , 18)
34 , m_focused(false)
35 , m_enabled(true)
36{
37 Create(parent, labels, direction, row_col_limit);
38}
ScalableBitmap m_off
Definition RadioGroup.hpp:70
void Create(wxWindow *parent, const std::vector< wxString > &labels={"1", "2", "3"}, long direction=wxHORIZONTAL, int row_col_limit=-1)
Definition RadioGroup.cpp:40
bool m_enabled
Definition RadioGroup.hpp:64
ScalableBitmap m_disabled
Definition RadioGroup.hpp:73
bool m_focused
Definition RadioGroup.hpp:63
int m_selectedIndex
Definition RadioGroup.hpp:61
ScalableBitmap m_on_hover
Definition RadioGroup.hpp:71
ScalableBitmap m_off_hover
Definition RadioGroup.hpp:72
ScalableBitmap m_on
Definition RadioGroup.hpp:69

References Create(), m_disabled, m_enabled, m_focused, m_off, m_off_hover, m_on, m_on_hover, and m_selectedIndex.

Here is the call graph for this function:

Member Function Documentation

◆ Create()

void RadioGroup::Create ( wxWindow * parent,
const std::vector< wxString > & labels = {"1", "2", "3"},
long direction = wxHORIZONTAL,
int row_col_limit = -1 )
46{
47 m_labels = labels;
48 m_item_count = m_labels.size();
49
50 auto bg = parent->GetBackgroundColour();
51 this->SetBackgroundColour(bg);
52
53 m_text_color = StateColor(
54 std::pair(wxColour("#6B6A6A"), (int)StateColor::Disabled),
55 std::pair(wxColour("#363636"), (int)StateColor::Enabled)
56 );
57
58 m_focus_color = StateColor(
59 std::pair(bg , (int)StateColor::NotFocused),
60 std::pair(wxColour("#009688"), (int)StateColor::Focused)
61 );
62
63 auto bmp_size = m_on.GetBmpSize();
64 int item_limit = row_col_limit < 0 ? 1 : row_col_limit > m_item_count ? m_item_count : row_col_limit;
65 int count = (int(m_item_count / item_limit) + (m_item_count % item_limit));
66 int rows = (direction & wxHORIZONTAL) ? item_limit : count;
67 int cols = (direction & wxHORIZONTAL) ? count : item_limit;
68 wxFlexGridSizer* f_sizer = new wxFlexGridSizer(rows, cols, 0, 0);
69
70 SetDoubleBuffered(true);
71
72 for (int i = 0; i < m_item_count; ++i){
73 auto rb = new wxStaticBitmap(this, wxID_ANY, m_off.bmp(), wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxNO_BORDER);
74 m_radioButtons.push_back(rb);
75 rb->Bind(wxEVT_LEFT_DOWN ,([this, i](wxMouseEvent e) {SetSelection(i, true) ; e.Skip();}));
76 rb->Bind(wxEVT_ENTER_WINDOW,([this, i](wxMouseEvent e) {SetRadioIcon(i, true) ; e.Skip();}));
77 rb->Bind(wxEVT_LEAVE_WINDOW,([this, i](wxMouseEvent e) {
78 // prevent removing hover effect while switching between button and its text
79 auto win = wxFindWindowAtPoint(wxGetMousePosition());
80 if(!win || win->GetId() != m_labelButtons[i]->GetId())
81 SetRadioIcon(i, false);
82 e.Skip();
83 }));
84
85 auto tx = new Button(this, m_labels[i]);
86 if(i != 0) // one focusable control must exist. wxPanel starts taking focus if there is no focusable control
87 tx->SetCanFocus(false);
88 tx->SetPaddingSize(FromDIP(wxSize(5,2)));
89 tx->SetBackgroundColor(bg);
90 tx->SetCornerRadius(0);
91 tx->SetBorderWidth(FromDIP(1));
92 tx->SetBorderColor(m_focus_color);
93 tx->SetFont(Label::Body_14);
94 tx->SetTextColor(m_text_color);
95 tx->Bind(wxEVT_BUTTON ,([this, i](wxCommandEvent e) {SetSelection(i, true) ; e.Skip();}));
96 tx->Bind(wxEVT_ENTER_WINDOW,([this, i](wxMouseEvent e) {SetRadioIcon(i, true) ; e.Skip();}));
97 tx->Bind(wxEVT_LEAVE_WINDOW,([this, i](wxMouseEvent e) {
98 // prevent removing hover effect while switching between button and its text
99 auto win = wxFindWindowAtPoint(wxGetMousePosition());
100 if(!win || win->GetId() != m_radioButtons[i]->GetId())
101 SetRadioIcon(i, false);
102 e.Skip();
103 }));
104 tx->Bind(wxEVT_CHAR_HOOK, ([this, tx](wxKeyEvent&e){
105 if(tx->HasFocus()){
106 int k = e.GetKeyCode();
107 bool is_next = (k == WXK_DOWN || k == WXK_RIGHT);
108 bool is_prev = (k == WXK_LEFT || k == WXK_UP);
109 if (is_next) SelectNext();
110 else if (is_prev) SelectPrevious();
111 e.Skip(!(is_next || is_prev));
112 }else{
113 e.Skip();
114 }
115 }));
116 m_labelButtons.push_back(tx);
117
118 wxBoxSizer* radio_sizer = new wxBoxSizer(wxHORIZONTAL);
119 radio_sizer->Add(rb, 0, wxALIGN_CENTER_VERTICAL);
120 radio_sizer->Add(tx, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, this->FromDIP(10));
121 f_sizer->Add(radio_sizer, 0, wxTOP | wxBOTTOM, this->FromDIP(4));
122 }
124 SetSizer(f_sizer);
125}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
static wxFont Body_14
Definition Label.hpp:53
StateColor m_focus_color
Definition RadioGroup.hpp:66
std::vector< wxString > m_labels
Definition RadioGroup.hpp:57
std::vector< Button * > m_labelButtons
Definition RadioGroup.hpp:59
void SetRadioIcon(int i, bool hover)
Definition RadioGroup.cpp:163
std::vector< wxStaticBitmap * > m_radioButtons
Definition RadioGroup.hpp:58
void SelectPrevious(bool focus=true)
Definition RadioGroup.cpp:158
int m_item_count
Definition RadioGroup.hpp:62
void SetSelection(int index, bool focus=false)
Definition RadioGroup.cpp:127
StateColor m_text_color
Definition RadioGroup.hpp:67
void SelectNext(bool focus=true)
Definition RadioGroup.cpp:153
@ NotFocused
Definition StateColor.hpp:24
@ Disabled
Definition StateColor.hpp:22
@ Enabled
Definition StateColor.hpp:17
@ Focused
Definition StateColor.hpp:19
size_t cols(const T &raster)
Definition MarchingSquares.hpp:173
size_t rows(const T &raster)
Definition MarchingSquares.hpp:171

References Label::Body_14, count, StateColor::Disabled, StateColor::Enabled, StateColor::Focused, m_focus_color, m_item_count, m_labelButtons, m_labels, m_off, m_on, m_radioButtons, m_selectedIndex, m_text_color, StateColor::NotFocused, SelectNext(), SelectPrevious(), SetRadioIcon(), and SetSelection().

Referenced by RadioGroup().

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

◆ Disable()

bool RadioGroup::Disable ( )
190{return RadioGroup::Enable(false);};
bool Enable(bool enable=true) override
Definition RadioGroup.cpp:169

References Enable().

Here is the call graph for this function:

◆ Enable()

bool RadioGroup::Enable ( bool enable = true)
override
170{
171 m_enabled = enable;
172 bool result = wxPanel::Enable(enable);
173
174 if (result) {
175 for (size_t i = 0; i < m_item_count; ++i){
176 SetRadioIcon(i, false);
177 m_labelButtons[i]->Enable(enable); // normally disabling parent should do this but not
178 }
179
180 wxCommandEvent e(EVT_ENABLE_CHANGED);
181 e.SetEventObject(this);
182 GetEventHandler()->ProcessEvent(e);
183 }
184
185 return result;
186};

References m_enabled, m_item_count, m_labelButtons, and SetRadioIcon().

Referenced by Disable().

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

◆ GetSelection()

int RadioGroup::GetSelection ( )
149{
150 return m_selectedIndex;
151}

References m_selectedIndex.

◆ IsEnabled()

bool RadioGroup::IsEnabled ( )
192{return m_enabled;};

References m_enabled.

◆ SelectNext()

void RadioGroup::SelectNext ( bool focus = true)
154{
155 SetSelection(m_selectedIndex + 1 > (m_radioButtons.size() - 1) ? 0 : m_selectedIndex + 1, focus);
156}

References m_radioButtons, m_selectedIndex, and SetSelection().

Referenced by Create().

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

◆ SelectPrevious()

void RadioGroup::SelectPrevious ( bool focus = true)
159{
160 SetSelection(m_selectedIndex - 1 < 0 ? (m_radioButtons.size() - 1) : m_selectedIndex - 1, focus);
161}

References m_radioButtons, m_selectedIndex, and SetSelection().

Referenced by Create().

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

◆ SetRadioIcon()

void RadioGroup::SetRadioIcon ( int i,
bool hover )
private
164{
165 auto icon = !m_enabled ? m_disabled : m_selectedIndex == i ? (hover ? m_on_hover : m_on) : (hover ? m_off_hover : m_off);
166 m_radioButtons[i]->SetBitmap(icon.bmp());
167}

References m_disabled, m_enabled, m_off, m_off_hover, m_on, m_on_hover, m_radioButtons, and m_selectedIndex.

Referenced by Create(), Enable(), and SetSelection().

Here is the caller graph for this function:

◆ SetRadioTooltip()

void RadioGroup::SetRadioTooltip ( int i,
wxString tooltip )
195{
196 m_radioButtons[i]->SetToolTip(tooltip);
197 m_labelButtons[i]->SetToolTip(tooltip);
198}

References m_labelButtons, and m_radioButtons.

Referenced by Slic3r::GUI::PreferencesDialog::create_debug_page().

Here is the caller graph for this function:

◆ SetSelection()

void RadioGroup::SetSelection ( int index,
bool focus = false )
128{
129 if (index >= 0 && index < m_item_count){
130 int prev_index = m_selectedIndex;
131 if(index != prev_index){ // prevent no focusable item on first creation. wxPanel starts taking focus if there is no focusable control
132 m_labelButtons[index]->SetCanFocus(true);
133 m_labelButtons[prev_index]->SetCanFocus(false);
134 }
135 if(focus)
136 m_labelButtons[index]->SetFocus();
137 m_selectedIndex = index;
138 for (size_t i = 0; i < m_item_count; ++i)
139 SetRadioIcon(i, m_labelButtons[index]->HasFocus() && i == m_selectedIndex);
140
141 wxCommandEvent evt(wxEVT_COMMAND_RADIOBOX_SELECTED, GetId());
142 evt.SetInt(index);
143 evt.SetString(m_labels[index]);
144 GetEventHandler()->ProcessEvent(evt);
145 }
146}

References m_item_count, m_labelButtons, m_labels, m_selectedIndex, and SetRadioIcon().

Referenced by Slic3r::GUI::ProjectDropDialog::ProjectDropDialog(), Create(), SelectNext(), and SelectPrevious().

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

Member Data Documentation

◆ m_disabled

ScalableBitmap RadioGroup::m_disabled
private

Referenced by RadioGroup(), and SetRadioIcon().

◆ m_enabled

bool RadioGroup::m_enabled
private

◆ m_focus_color

StateColor RadioGroup::m_focus_color
private

Referenced by Create().

◆ m_focused

bool RadioGroup::m_focused
private

Referenced by RadioGroup().

◆ m_item_count

int RadioGroup::m_item_count
private

Referenced by Create(), Enable(), and SetSelection().

◆ m_labelButtons

std::vector<Button*> RadioGroup::m_labelButtons
private

◆ m_labels

std::vector<wxString> RadioGroup::m_labels
private

Referenced by Create(), and SetSelection().

◆ m_off

ScalableBitmap RadioGroup::m_off
private

Referenced by RadioGroup(), Create(), and SetRadioIcon().

◆ m_off_hover

ScalableBitmap RadioGroup::m_off_hover
private

Referenced by RadioGroup(), and SetRadioIcon().

◆ m_on

ScalableBitmap RadioGroup::m_on
private

Referenced by RadioGroup(), Create(), and SetRadioIcon().

◆ m_on_hover

ScalableBitmap RadioGroup::m_on_hover
private

Referenced by RadioGroup(), and SetRadioIcon().

◆ m_radioButtons

std::vector<wxStaticBitmap*> RadioGroup::m_radioButtons
private

◆ m_selectedIndex

int RadioGroup::m_selectedIndex
private

◆ m_text_color

StateColor RadioGroup::m_text_color
private

Referenced by Create().


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