Updated TextCtrl::BUILD()
This commit is contained in:
parent
867e867cdd
commit
c6ff5ccbf4
3 changed files with 22 additions and 38 deletions
|
@ -10,6 +10,14 @@
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
wxString double_to_string(double const value)
|
||||||
|
{
|
||||||
|
int precision = 10 * value - int(10 * value) == 0 ? 1 : 2;
|
||||||
|
return value - int(value) == 0 ?
|
||||||
|
wxString::Format(_T("%i"), int(value)) :
|
||||||
|
wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None);
|
||||||
|
}
|
||||||
|
|
||||||
void Field::on_kill_focus(wxEvent& event) {
|
void Field::on_kill_focus(wxEvent& event) {
|
||||||
// Without this, there will be nasty focus bugs on Windows.
|
// Without this, there will be nasty focus bugs on Windows.
|
||||||
// Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all
|
// Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all
|
||||||
|
@ -88,16 +96,12 @@ namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
wxString text_value = wxString("");
|
wxString text_value = wxString("");
|
||||||
|
|
||||||
/* switch (m_opt.type) {
|
switch (m_opt.type) {
|
||||||
case coFloatOrPercent:
|
case coFloatOrPercent:
|
||||||
{
|
{
|
||||||
if (static_cast<const ConfigOptionFloatOrPercent*>(m_opt.default_value)->percent)
|
text_value = double_to_string(m_opt.default_value->getFloat());
|
||||||
{
|
if (static_cast<const ConfigOptionFloatOrPercent*>(m_opt.default_value)->percent)
|
||||||
text_value = wxString::Format(_T("%i"), int(m_opt.default_value->getFloat()));
|
text_value += "%";
|
||||||
text_value += "%";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
text_value = wxNumberFormatter::ToString(m_opt.default_value->getFloat(), 2);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case coPercent:
|
case coPercent:
|
||||||
|
@ -107,29 +111,15 @@ namespace Slic3r { namespace GUI {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case coPercents:
|
case coPercents:
|
||||||
{
|
case coFloats:
|
||||||
const ConfigOptionPercents *vec = static_cast<const ConfigOptionPercents*>(m_opt.default_value);
|
|
||||||
if (vec == nullptr || vec->empty()) break;
|
|
||||||
if (vec->size() > 1)
|
|
||||||
break;
|
|
||||||
double val = vec->get_at(0);
|
|
||||||
text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case coFloat:
|
case coFloat:
|
||||||
{
|
{
|
||||||
double val = m_opt.default_value->getFloat();
|
double val = m_opt.type == coFloats ?
|
||||||
text_value = (val - int(val)) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
|
static_cast<const ConfigOptionFloats*>(m_opt.default_value)->get_at(0) :
|
||||||
break;
|
m_opt.type == coFloat ?
|
||||||
}
|
m_opt.default_value->getFloat() :
|
||||||
case coFloats:
|
static_cast<const ConfigOptionPercents*>(m_opt.default_value)->get_at(0);
|
||||||
{
|
text_value = double_to_string(val);
|
||||||
const ConfigOptionFloats *vec = static_cast<const ConfigOptionFloats*>(m_opt.default_value);
|
|
||||||
if (vec == nullptr || vec->empty()) break;
|
|
||||||
if (vec->size() > 1)
|
|
||||||
break;
|
|
||||||
double val = vec->get_at(0);
|
|
||||||
text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case coString:
|
case coString:
|
||||||
|
@ -148,7 +138,7 @@ namespace Slic3r { namespace GUI {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/ auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0));
|
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0));
|
||||||
|
|
||||||
temp->SetToolTip(get_tooltip_text(text_value));
|
temp->SetToolTip(get_tooltip_text(text_value));
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ using t_field = std::unique_ptr<Field>;
|
||||||
using t_kill_focus = std::function<void()>;
|
using t_kill_focus = std::function<void()>;
|
||||||
using t_change = std::function<void(t_config_option_key, boost::any)>;
|
using t_change = std::function<void(t_config_option_key, boost::any)>;
|
||||||
|
|
||||||
|
wxString double_to_string(double const value);
|
||||||
|
|
||||||
class Field {
|
class Field {
|
||||||
protected:
|
protected:
|
||||||
// factory function to defer and enforce creation of derived type.
|
// factory function to defer and enforce creation of derived type.
|
||||||
|
|
|
@ -289,14 +289,6 @@ boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString double_to_string(double const value)
|
|
||||||
{
|
|
||||||
int precision = 10 * value - int(10 * value) == 0 ? 1 : 2;
|
|
||||||
return value - int(value) == 0 ?
|
|
||||||
wxString::Format(_T("%i"), int(value)) :
|
|
||||||
wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std::string opt_key, int opt_index/* = -1*/)
|
boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std::string opt_key, int opt_index/* = -1*/)
|
||||||
{
|
{
|
||||||
size_t idx = opt_index == -1 ? 0 : opt_index;
|
size_t idx = opt_index == -1 ? 0 : opt_index;
|
||||||
|
|
Loading…
Add table
Reference in a new issue