mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-12 21:09:03 +08:00
Moved implementation of most UI_Choice methods into its own file.
This commit is contained in:
parent
14fc049c6f
commit
4d6188e0d1
@ -260,6 +260,7 @@ IF(wxWidgets_FOUND)
|
||||
${GUI_LIBDIR}/Settings.cpp
|
||||
${GUI_LIBDIR}/misc_ui.cpp
|
||||
${GUI_LIBDIR}/OptionsGroup/UI_NumChoice.cpp
|
||||
${GUI_LIBDIR}/OptionsGroup/UI_Choice.cpp
|
||||
)
|
||||
target_compile_features(slic3r_gui PUBLIC cxx_std_14)
|
||||
#only build GUI lib if building with wx
|
||||
|
@ -196,49 +196,18 @@ private:
|
||||
|
||||
class UI_Choice : public UI_Window {
|
||||
public:
|
||||
UI_Choice(wxWindow* parent, Slic3r::ConfigOptionDef _opt, wxWindowID id = wxID_ANY) : UI_Window(parent, _opt) {
|
||||
int style {0};
|
||||
style |= wxTE_PROCESS_ENTER;
|
||||
if (opt.gui_type.size() > 0 && opt.gui_type.compare("select_open"s)) style |= wxCB_READONLY;
|
||||
|
||||
/// Load the values
|
||||
auto values {wxArrayString()};
|
||||
for (auto v : opt.enum_values) values.Add(wxString(v));
|
||||
|
||||
_choice = new wxComboBox(parent, id,
|
||||
(opt.default_value != nullptr ? opt.default_value->getString() : ""),
|
||||
wxDefaultPosition, _default_size(), values, style);
|
||||
window = _choice;
|
||||
|
||||
_choice->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); });
|
||||
_choice->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); });
|
||||
_choice->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { if (this->on_kill_focus != nullptr) {this->on_kill_focus(""); this->_on_change("");} e.Skip(); });
|
||||
}
|
||||
std::string get_string() override {
|
||||
if (opt.enum_values.size() > 0) {
|
||||
auto idx = this->_choice->GetSelection();
|
||||
if (idx != wxNOT_FOUND) return this->opt.enum_values.at(idx);
|
||||
}
|
||||
return this->_choice->GetValue().ToStdString();
|
||||
}
|
||||
UI_Choice(wxWindow* parent, Slic3r::ConfigOptionDef _opt, wxWindowID id = wxID_ANY);
|
||||
~UI_Choice() { _choice->Destroy(); }
|
||||
|
||||
std::string get_string() override;
|
||||
|
||||
/// Returns a bare pointer to the underlying combobox, usually for test interface
|
||||
wxComboBox* choice() { return this->_choice; }
|
||||
|
||||
void set_value(boost::any value) override {
|
||||
auto result {std::find(opt.enum_values.cbegin(), opt.enum_values.cend(), boost::any_cast<std::string>(value))};
|
||||
if (result == opt.enum_values.cend()) {
|
||||
this->_choice->SetValue(wxString(boost::any_cast<std::string>(value)));
|
||||
} else {
|
||||
auto idx = std::distance(opt.enum_values.cbegin(), result);
|
||||
this->_choice->SetSelection(idx);
|
||||
}
|
||||
}
|
||||
void set_value(boost::any value) override;
|
||||
|
||||
/// Function to call when the contents of this change.
|
||||
std::function<void (const std::string&, std::string value)> on_change {nullptr};
|
||||
|
||||
/// Returns a bare pointer to the underlying combobox, usually for test interface
|
||||
wxComboBox* choice() { return this->_choice; }
|
||||
protected:
|
||||
virtual std::string LogChannel() override { return "UI_Choice"s; }
|
||||
|
||||
|
43
src/GUI/OptionsGroup/UI_Choice.cpp
Normal file
43
src/GUI/OptionsGroup/UI_Choice.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "OptionsGroup/Field.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
UI_Choice::UI_Choice(wxWindow* parent, Slic3r::ConfigOptionDef _opt, wxWindowID id) : UI_Window(parent, _opt) {
|
||||
int style {0};
|
||||
style |= wxTE_PROCESS_ENTER;
|
||||
if (opt.gui_type.size() > 0 && opt.gui_type.compare("select_open"s)) style |= wxCB_READONLY;
|
||||
|
||||
/// Load the values
|
||||
auto values {wxArrayString()};
|
||||
for (auto v : opt.enum_values) values.Add(wxString(v));
|
||||
|
||||
_choice = new wxComboBox(parent, id,
|
||||
(opt.default_value != nullptr ? opt.default_value->getString() : ""),
|
||||
wxDefaultPosition, _default_size(), values, style);
|
||||
window = _choice;
|
||||
|
||||
_choice->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); });
|
||||
_choice->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& e) { this->_on_change(""); e.Skip(); });
|
||||
_choice->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) { if (this->on_kill_focus != nullptr) {this->on_kill_focus(""); this->_on_change("");} e.Skip(); });
|
||||
}
|
||||
|
||||
std::string UI_Choice::get_string() {
|
||||
if (opt.enum_values.size() > 0) {
|
||||
auto idx = this->_choice->GetSelection();
|
||||
if (idx != wxNOT_FOUND) return this->opt.enum_values.at(idx);
|
||||
}
|
||||
return this->_choice->GetValue().ToStdString();
|
||||
}
|
||||
|
||||
|
||||
void UI_Choice::set_value(boost::any value) {
|
||||
auto result {std::find(opt.enum_values.cbegin(), opt.enum_values.cend(), boost::any_cast<std::string>(value))};
|
||||
if (result == opt.enum_values.cend()) {
|
||||
this->_choice->SetValue(wxString(boost::any_cast<std::string>(value)));
|
||||
} else {
|
||||
auto idx = std::distance(opt.enum_values.cbegin(), result);
|
||||
this->_choice->SetSelection(idx);
|
||||
}
|
||||
}
|
||||
|
||||
} } // Namespace Slic3r::GUI
|
Loading…
x
Reference in New Issue
Block a user