diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 1fc820b557..29083ac66b 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -41,7 +41,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id) { return build_field(id, opt); } -const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) { +const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) +{ + if (!opt.label.empty() || !opt.full_label.empty()) + Accessibility::SetNextLabelString(opt.full_label.empty() ? opt.label : opt.full_label); + // Check the gui_type field first, fall through // is the normal type. switch (opt.gui_type) { @@ -259,7 +263,6 @@ void OptionsGroup::append_separator() void OptionsGroup::activate_line(Line& line) { - if(!line.label.IsEmpty()) Accessibility::SetNextLabelString(line.label); if (line.is_separator()) return; diff --git a/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp b/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp index b567bc5433..56b61a6a0a 100644 --- a/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp +++ b/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp @@ -15,7 +15,7 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, wxSize def_size = wxDefaultSize; #endif // Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux - wxToggleButton::Create(parent, id, label, wxDefaultPosition, def_size, style | wxBU_NOTEXT); + wxToggleButton::Create(parent, id, label, wxDefaultPosition, def_size, style); } #ifdef __WXMSW__ diff --git a/src/slic3r/GUI/Widgets/CheckBox.cpp b/src/slic3r/GUI/Widgets/CheckBox.cpp index 54407c132f..7e1501b1bd 100644 --- a/src/slic3r/GUI/Widgets/CheckBox.cpp +++ b/src/slic3r/GUI/Widgets/CheckBox.cpp @@ -1,7 +1,8 @@ #include "CheckBox.hpp" -#include "slic3r/GUI/Accessibility.hpp" -//#include "../wxExtensions.hpp" +#include "../Accessibility.hpp" +#include "../I18N.hpp" +#include "../format.hpp" const int px_cnt = 16; @@ -14,10 +15,8 @@ CheckBox::CheckBox(wxWindow* parent, const wxString& name) , m_on_focused(this, "check_on_focused", px_cnt) , m_off_focused(this, "check_off_focused", px_cnt) { - if(Slic3r::GUI::Accessibility::IsLabelAvailable()) - m_accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString(); - else - m_accessibility_label = ""; + if (name.IsEmpty() && Slic3r::GUI::Accessibility::IsLabelAvailable()) + m_accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString(); #ifdef __WXOSX__ // State not fully implement on MacOS Bind(wxEVT_SET_FOCUS, &CheckBox::updateBitmap, this); @@ -64,7 +63,8 @@ void CheckBox::update() SetBitmapMargins(4, 0); update_size(); - this->SetLabel(m_accessibility_label+((val)?(" X"):(""))); + if (!m_accessibility_label.IsEmpty()) + SetLabel(Slic3r::GUI::format_wxstr("%1% %2% %3%", m_accessibility_label, _L("Checkbox"), (val ? _L(" Checked") : _L("Unchecked")))); } #ifdef __WXMSW__ diff --git a/src/slic3r/GUI/Widgets/ComboBox.cpp b/src/slic3r/GUI/Widgets/ComboBox.cpp index 52f0f6afdf..061c5780ea 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.cpp +++ b/src/slic3r/GUI/Widgets/ComboBox.cpp @@ -4,6 +4,7 @@ #include #include "../GUI_App.hpp" +#include "../Accessibility.hpp" BEGIN_EVENT_TABLE(ComboBox, TextInput) @@ -77,7 +78,7 @@ int ComboBox::GetSelection() const void ComboBox::SetSelection(int n) { drop.SetSelection(n); - SetLabel(drop.GetValue()); + SetText(drop.GetValue()); if (drop.selection >= 0) SetIcon(icons[drop.selection]); } @@ -92,41 +93,31 @@ void ComboBox::Rescale() wxString ComboBox::GetValue() const { - return drop.GetSelection() >= 0 ? drop.GetValue() : GetLabel(); + return drop.GetSelection() >= 0 ? drop.GetValue() : GetText(); } void ComboBox::SetValue(const wxString &value) { drop.SetValue(value); - SetLabel(value); + SetText(value); if (drop.selection >= 0) SetIcon(icons[drop.selection]); } -void ComboBox::SetLabel(const wxString &value) +void ComboBox::SetText(const wxString &value) { if (GetTextCtrl()->IsShown() || text_off) GetTextCtrl()->SetValue(value); else - TextInput::SetLabel(value); + TextInput::SetText(value); } -wxString ComboBox::GetLabel() const +wxString ComboBox::GetText() const { if (GetTextCtrl()->IsShown() || text_off) return GetTextCtrl()->GetValue(); else - return TextInput::GetLabel(); -} - -void ComboBox::SetTextLabel(const wxString& label) -{ - TextInput::SetLabel(label); -} - -wxString ComboBox::GetTextLabel() const -{ - return TextInput::GetLabel(); + return TextInput::GetText(); } bool ComboBox::SetFont(wxFont const& font) @@ -238,7 +229,7 @@ void ComboBox::SetString(unsigned int n, wxString const &value) if (n >= texts.size()) return; texts[n] = value; drop.Invalidate(); - if (int(n) == drop.GetSelection()) SetLabel(value); + if (int(n) == drop.GetSelection()) SetText(value); } wxBitmap ComboBox::GetItemBitmap(unsigned int n) @@ -353,7 +344,7 @@ void ComboBox::keyDown(wxKeyEvent& event) break; } const size_t pos = size_t(GetTextCtrl()->GetInsertionPoint()); - if (pos < GetLabel().Length()) + if (pos < GetText().Length()) GetTextCtrl()->SetInsertionPoint(pos + 1); break; } diff --git a/src/slic3r/GUI/Widgets/ComboBox.hpp b/src/slic3r/GUI/Widgets/ComboBox.hpp index b94acf9312..13f571e42a 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.hpp +++ b/src/slic3r/GUI/Widgets/ComboBox.hpp @@ -55,11 +55,8 @@ public: wxString GetValue() const; void SetValue(const wxString &value); - void SetLabel(const wxString &label) override; - wxString GetLabel() const override; - - void SetTextLabel(const wxString &label); - wxString GetTextLabel() const; + void SetText(const wxString &label); + wxString GetText() const; wxString GetString(unsigned int n) const override; void SetString(unsigned int n, wxString const &value) override; diff --git a/src/slic3r/GUI/Widgets/SpinInput.cpp b/src/slic3r/GUI/Widgets/SpinInput.cpp index 0671f839e2..10d19f2d22 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.cpp +++ b/src/slic3r/GUI/Widgets/SpinInput.cpp @@ -4,6 +4,8 @@ #include "UIColors.hpp" #include "../GUI_App.hpp" +#include "../I18N.hpp" +#include "../format.hpp" #include "../Accessibility.hpp" #include @@ -55,9 +57,9 @@ void SpinInputBase::SetCornerRadius(double radius) Refresh(); } -void SpinInputBase::SetLabel(const wxString &label) +void SpinInputBase::SetText(const wxString &text_in) { - wxWindow::SetLabel(label); + text = text_in; messureSize(); Refresh(); } @@ -207,7 +209,7 @@ void SpinInputBase::render(wxDC& dc) const int btn_w = button_inc->GetSize().GetWidth(); dc.DrawLine(pt, pt + wxSize{ btn_w - int(scale), 0}); // draw label - auto label = GetLabel(); + auto label = text; if (!label.IsEmpty()) { pt.x = size.x - labelSize.x - 5; pt.y = (size.y - labelSize.y) / 2; @@ -234,7 +236,7 @@ void SpinInputBase::messureSize() const double scale = this->GetContentScaleFactor(); wxClientDC dc(this); - labelSize = dc.GetMultiLineTextExtent(GetLabel()); + labelSize = dc.GetMultiLineTextExtent(text); textSize.x = size.x - labelSize.x - btnSize.x - 16; text_ctrl->SetSize(textSize); text_ctrl->SetPosition({int(3. * scale), (size.y - textSize.y) / 2}); @@ -282,15 +284,14 @@ void SpinInput::Create(wxWindow *parent, int min, int max, int initial) { StaticBox::Create(parent, wxID_ANY, pos, size); - wxWindow::SetLabel(label); state_handler.attach({&label_color, &text_color}); state_handler.update_binds(); if(Slic3r::GUI::Accessibility::IsLabelAvailable()) - wxStaticText *virtualLabel = new wxStaticText( - this, wxID_ANY, Slic3r::GUI::Accessibility::GetLastLabelString(), wxDefaultPosition, wxSize(0, 0), wxST_NO_AUTORESIZE - ); + wxWindow::SetLabel(!label.empty() ? label : + Slic3r::GUI::format_wxstr("%1% %2%", Slic3r::GUI::Accessibility::GetLastLabelString(), _L("Spin Control"))); + text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_NUMERIC)); #ifdef __WXOSX__ text_ctrl->OSXDisableAllSmartSubstitutions(); @@ -462,11 +463,14 @@ void SpinInputDouble::Create(wxWindow *parent, double inc) { StaticBox::Create(parent, wxID_ANY, pos, size); - wxWindow::SetLabel(label); state_handler.attach({&label_color, &text_color}); state_handler.update_binds(); + if (Slic3r::GUI::Accessibility::IsLabelAvailable()) + wxWindow::SetLabel(!label.empty() ? label : + Slic3r::GUI::format_wxstr("%1% %2%", Slic3r::GUI::Accessibility::GetLastLabelString(), _L("Spin Control"))); + text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_NUMERIC)); #ifdef __WXOSX__ text_ctrl->OSXDisableAllSmartSubstitutions(); diff --git a/src/slic3r/GUI/Widgets/SpinInput.hpp b/src/slic3r/GUI/Widgets/SpinInput.hpp index f81ec0b80d..3537dfa08b 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.hpp +++ b/src/slic3r/GUI/Widgets/SpinInput.hpp @@ -16,6 +16,7 @@ protected: Button * button_inc {nullptr}; Button * button_dec {nullptr}; wxTimer timer; + wxString text; static const int SpinInputWidth = 200; static const int SpinInputHeight = 50; @@ -31,7 +32,7 @@ public: void SetCornerRadius(double radius); - void SetLabel(const wxString &label) wxOVERRIDE; + void SetText(const wxString &text); void SetLabelColor(StateColor const &color); diff --git a/src/slic3r/GUI/Widgets/TextInput.cpp b/src/slic3r/GUI/Widgets/TextInput.cpp index e6538e30dd..1526bed0db 100644 --- a/src/slic3r/GUI/Widgets/TextInput.cpp +++ b/src/slic3r/GUI/Widgets/TextInput.cpp @@ -4,8 +4,10 @@ #include #include -#include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/Accessibility.hpp" +#include "../GUI_App.hpp" +#include "../I18N.hpp" +#include "../format.hpp" +#include "../Accessibility.hpp" BEGIN_EVENT_TABLE(TextInput, wxPanel) @@ -43,7 +45,7 @@ TextInput::TextInput(wxWindow * parent, } void TextInput::Create(wxWindow * parent, - wxString text, + wxString text_in, wxString label, wxString icon, const wxPoint &pos, @@ -51,16 +53,16 @@ void TextInput::Create(wxWindow * parent, long style) { text_ctrl = nullptr; + text = text_in; StaticBox::Create(parent, wxID_ANY, pos, size, style); - wxWindow::SetLabel(label); state_handler.attach({&label_color, &text_color}); state_handler.update_binds(); - if(Slic3r::GUI::Accessibility::IsLabelAvailable()) - wxStaticText *virtualLabel = new wxStaticText( - this, wxID_ANY, Slic3r::GUI::Accessibility::GetLastLabelString(), wxDefaultPosition, wxSize(0, 0), wxST_NO_AUTORESIZE - ); + if (Slic3r::GUI::Accessibility::IsLabelAvailable()) { + accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString(); + wxWindow::SetLabel(!label.empty() ? label : (accessibility_label + " " + (icon.IsEmpty() ? "" : _L("ComboBox")))); + } text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, size, style | wxBORDER_NONE); #ifdef __WXOSX__ @@ -96,11 +98,16 @@ void TextInput::Create(wxWindow * parent, messureSize(); } -void TextInput::SetLabel(const wxString& label) +void TextInput::SetText(const wxString& text_in) { - wxWindow::SetLabel(label); + text = text_in; messureSize(); Refresh(); + + // If text control is hidded (when there is TextInput from non-editable ComboBox), + // a label have to be extended for label name for this control + if (!text_ctrl->IsShown()) + this->SetLabel(Slic3r::GUI::format_wxstr("%1% %2% %3%", accessibility_label, _L("ComboBox"), text)); } bool TextInput::SetBackgroundColour(const wxColour& colour) @@ -294,7 +301,6 @@ void TextInput::render(wxDC& dc) dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r); } - auto text = wxWindow::GetLabel(); if (!text.IsEmpty()) { wxSize textSize = text_ctrl->GetSize(); if (align_right) { @@ -315,7 +321,7 @@ void TextInput::messureSize() { wxSize size = GetSize(); wxClientDC dc(this); - labelSize = dc.GetTextExtent(wxWindow::GetLabel()); + labelSize = dc.GetTextExtent(text); const wxSize textSize = text_ctrl->GetSize(); const wxSize iconSize = drop_down_icon.bmp().IsOk() ? drop_down_icon.GetSize() : wxSize(0, 0); diff --git a/src/slic3r/GUI/Widgets/TextInput.hpp b/src/slic3r/GUI/Widgets/TextInput.hpp index d48cfc679b..0b503eb949 100644 --- a/src/slic3r/GUI/Widgets/TextInput.hpp +++ b/src/slic3r/GUI/Widgets/TextInput.hpp @@ -17,6 +17,9 @@ class TextInput : public wxNavigationEnabled static const int TextInputWidth = 200; static const int TextInputHeight = 50; + wxString accessibility_label; + wxString text; + public: TextInput(); @@ -37,7 +40,9 @@ public: const wxSize & size = wxDefaultSize, long style = 0); - void SetLabel(const wxString& label) wxOVERRIDE; + void SetText(const wxString& text); + + wxString GetText() const { return text; } void SetIcon(const wxBitmapBundle& icon);