Follow-up fa36771e - Finalized using of the Accessibility class on Settings Tabs

This commit is contained in:
YuSanka 2024-02-14 15:25:42 +01:00
parent 3e399a3977
commit 7066992ba7
9 changed files with 64 additions and 57 deletions

View File

@ -41,7 +41,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id) {
return build_field(id, opt); 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 // Check the gui_type field first, fall through
// is the normal type. // is the normal type.
switch (opt.gui_type) { switch (opt.gui_type) {
@ -259,7 +263,6 @@ void OptionsGroup::append_separator()
void OptionsGroup::activate_line(Line& line) void OptionsGroup::activate_line(Line& line)
{ {
if(!line.label.IsEmpty()) Accessibility::SetNextLabelString(line.label);
if (line.is_separator()) if (line.is_separator())
return; return;

View File

@ -15,7 +15,7 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label,
wxSize def_size = wxDefaultSize; wxSize def_size = wxDefaultSize;
#endif #endif
// Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux // 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__ #ifdef __WXMSW__

View File

@ -1,7 +1,8 @@
#include "CheckBox.hpp" #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; 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_on_focused(this, "check_on_focused", px_cnt)
, m_off_focused(this, "check_off_focused", px_cnt) , m_off_focused(this, "check_off_focused", px_cnt)
{ {
if(Slic3r::GUI::Accessibility::IsLabelAvailable()) if (name.IsEmpty() && Slic3r::GUI::Accessibility::IsLabelAvailable())
m_accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString(); m_accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString();
else
m_accessibility_label = "";
#ifdef __WXOSX__ // State not fully implement on MacOS #ifdef __WXOSX__ // State not fully implement on MacOS
Bind(wxEVT_SET_FOCUS, &CheckBox::updateBitmap, this); Bind(wxEVT_SET_FOCUS, &CheckBox::updateBitmap, this);
@ -64,7 +63,8 @@ void CheckBox::update()
SetBitmapMargins(4, 0); SetBitmapMargins(4, 0);
update_size(); 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__ #ifdef __WXMSW__

View File

@ -4,6 +4,7 @@
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
#include "../GUI_App.hpp" #include "../GUI_App.hpp"
#include "../Accessibility.hpp"
BEGIN_EVENT_TABLE(ComboBox, TextInput) BEGIN_EVENT_TABLE(ComboBox, TextInput)
@ -77,7 +78,7 @@ int ComboBox::GetSelection() const
void ComboBox::SetSelection(int n) void ComboBox::SetSelection(int n)
{ {
drop.SetSelection(n); drop.SetSelection(n);
SetLabel(drop.GetValue()); SetText(drop.GetValue());
if (drop.selection >= 0) if (drop.selection >= 0)
SetIcon(icons[drop.selection]); SetIcon(icons[drop.selection]);
} }
@ -92,41 +93,31 @@ void ComboBox::Rescale()
wxString ComboBox::GetValue() const wxString ComboBox::GetValue() const
{ {
return drop.GetSelection() >= 0 ? drop.GetValue() : GetLabel(); return drop.GetSelection() >= 0 ? drop.GetValue() : GetText();
} }
void ComboBox::SetValue(const wxString &value) void ComboBox::SetValue(const wxString &value)
{ {
drop.SetValue(value); drop.SetValue(value);
SetLabel(value); SetText(value);
if (drop.selection >= 0) if (drop.selection >= 0)
SetIcon(icons[drop.selection]); SetIcon(icons[drop.selection]);
} }
void ComboBox::SetLabel(const wxString &value) void ComboBox::SetText(const wxString &value)
{ {
if (GetTextCtrl()->IsShown() || text_off) if (GetTextCtrl()->IsShown() || text_off)
GetTextCtrl()->SetValue(value); GetTextCtrl()->SetValue(value);
else else
TextInput::SetLabel(value); TextInput::SetText(value);
} }
wxString ComboBox::GetLabel() const wxString ComboBox::GetText() const
{ {
if (GetTextCtrl()->IsShown() || text_off) if (GetTextCtrl()->IsShown() || text_off)
return GetTextCtrl()->GetValue(); return GetTextCtrl()->GetValue();
else else
return TextInput::GetLabel(); return TextInput::GetText();
}
void ComboBox::SetTextLabel(const wxString& label)
{
TextInput::SetLabel(label);
}
wxString ComboBox::GetTextLabel() const
{
return TextInput::GetLabel();
} }
bool ComboBox::SetFont(wxFont const& font) bool ComboBox::SetFont(wxFont const& font)
@ -238,7 +229,7 @@ void ComboBox::SetString(unsigned int n, wxString const &value)
if (n >= texts.size()) return; if (n >= texts.size()) return;
texts[n] = value; texts[n] = value;
drop.Invalidate(); drop.Invalidate();
if (int(n) == drop.GetSelection()) SetLabel(value); if (int(n) == drop.GetSelection()) SetText(value);
} }
wxBitmap ComboBox::GetItemBitmap(unsigned int n) wxBitmap ComboBox::GetItemBitmap(unsigned int n)
@ -353,7 +344,7 @@ void ComboBox::keyDown(wxKeyEvent& event)
break; break;
} }
const size_t pos = size_t(GetTextCtrl()->GetInsertionPoint()); const size_t pos = size_t(GetTextCtrl()->GetInsertionPoint());
if (pos < GetLabel().Length()) if (pos < GetText().Length())
GetTextCtrl()->SetInsertionPoint(pos + 1); GetTextCtrl()->SetInsertionPoint(pos + 1);
break; break;
} }

View File

@ -55,11 +55,8 @@ public:
wxString GetValue() const; wxString GetValue() const;
void SetValue(const wxString &value); void SetValue(const wxString &value);
void SetLabel(const wxString &label) override; void SetText(const wxString &label);
wxString GetLabel() const override; wxString GetText() const;
void SetTextLabel(const wxString &label);
wxString GetTextLabel() const;
wxString GetString(unsigned int n) const override; wxString GetString(unsigned int n) const override;
void SetString(unsigned int n, wxString const &value) override; void SetString(unsigned int n, wxString const &value) override;

View File

@ -4,6 +4,8 @@
#include "UIColors.hpp" #include "UIColors.hpp"
#include "../GUI_App.hpp" #include "../GUI_App.hpp"
#include "../I18N.hpp"
#include "../format.hpp"
#include "../Accessibility.hpp" #include "../Accessibility.hpp"
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
@ -55,9 +57,9 @@ void SpinInputBase::SetCornerRadius(double radius)
Refresh(); Refresh();
} }
void SpinInputBase::SetLabel(const wxString &label) void SpinInputBase::SetText(const wxString &text_in)
{ {
wxWindow::SetLabel(label); text = text_in;
messureSize(); messureSize();
Refresh(); Refresh();
} }
@ -207,7 +209,7 @@ void SpinInputBase::render(wxDC& dc)
const int btn_w = button_inc->GetSize().GetWidth(); const int btn_w = button_inc->GetSize().GetWidth();
dc.DrawLine(pt, pt + wxSize{ btn_w - int(scale), 0}); dc.DrawLine(pt, pt + wxSize{ btn_w - int(scale), 0});
// draw label // draw label
auto label = GetLabel(); auto label = text;
if (!label.IsEmpty()) { if (!label.IsEmpty()) {
pt.x = size.x - labelSize.x - 5; pt.x = size.x - labelSize.x - 5;
pt.y = (size.y - labelSize.y) / 2; pt.y = (size.y - labelSize.y) / 2;
@ -234,7 +236,7 @@ void SpinInputBase::messureSize()
const double scale = this->GetContentScaleFactor(); const double scale = this->GetContentScaleFactor();
wxClientDC dc(this); wxClientDC dc(this);
labelSize = dc.GetMultiLineTextExtent(GetLabel()); labelSize = dc.GetMultiLineTextExtent(text);
textSize.x = size.x - labelSize.x - btnSize.x - 16; textSize.x = size.x - labelSize.x - btnSize.x - 16;
text_ctrl->SetSize(textSize); text_ctrl->SetSize(textSize);
text_ctrl->SetPosition({int(3. * scale), (size.y - textSize.y) / 2}); 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) int min, int max, int initial)
{ {
StaticBox::Create(parent, wxID_ANY, pos, size); StaticBox::Create(parent, wxID_ANY, pos, size);
wxWindow::SetLabel(label);
state_handler.attach({&label_color, &text_color}); state_handler.attach({&label_color, &text_color});
state_handler.update_binds(); state_handler.update_binds();
if(Slic3r::GUI::Accessibility::IsLabelAvailable()) if(Slic3r::GUI::Accessibility::IsLabelAvailable())
wxStaticText *virtualLabel = new wxStaticText( wxWindow::SetLabel(!label.empty() ? label :
this, wxID_ANY, Slic3r::GUI::Accessibility::GetLastLabelString(), wxDefaultPosition, wxSize(0, 0), wxST_NO_AUTORESIZE 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)); text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_NUMERIC));
#ifdef __WXOSX__ #ifdef __WXOSX__
text_ctrl->OSXDisableAllSmartSubstitutions(); text_ctrl->OSXDisableAllSmartSubstitutions();
@ -462,11 +463,14 @@ void SpinInputDouble::Create(wxWindow *parent,
double inc) double inc)
{ {
StaticBox::Create(parent, wxID_ANY, pos, size); StaticBox::Create(parent, wxID_ANY, pos, size);
wxWindow::SetLabel(label);
state_handler.attach({&label_color, &text_color}); state_handler.attach({&label_color, &text_color});
state_handler.update_binds(); 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)); text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_NUMERIC));
#ifdef __WXOSX__ #ifdef __WXOSX__
text_ctrl->OSXDisableAllSmartSubstitutions(); text_ctrl->OSXDisableAllSmartSubstitutions();

View File

@ -16,6 +16,7 @@ protected:
Button * button_inc {nullptr}; Button * button_inc {nullptr};
Button * button_dec {nullptr}; Button * button_dec {nullptr};
wxTimer timer; wxTimer timer;
wxString text;
static const int SpinInputWidth = 200; static const int SpinInputWidth = 200;
static const int SpinInputHeight = 50; static const int SpinInputHeight = 50;
@ -31,7 +32,7 @@ public:
void SetCornerRadius(double radius); void SetCornerRadius(double radius);
void SetLabel(const wxString &label) wxOVERRIDE; void SetText(const wxString &text);
void SetLabelColor(StateColor const &color); void SetLabelColor(StateColor const &color);

View File

@ -4,8 +4,10 @@
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
#include <wx/panel.h> #include <wx/panel.h>
#include "slic3r/GUI/GUI_App.hpp" #include "../GUI_App.hpp"
#include "slic3r/GUI/Accessibility.hpp" #include "../I18N.hpp"
#include "../format.hpp"
#include "../Accessibility.hpp"
BEGIN_EVENT_TABLE(TextInput, wxPanel) BEGIN_EVENT_TABLE(TextInput, wxPanel)
@ -43,7 +45,7 @@ TextInput::TextInput(wxWindow * parent,
} }
void TextInput::Create(wxWindow * parent, void TextInput::Create(wxWindow * parent,
wxString text, wxString text_in,
wxString label, wxString label,
wxString icon, wxString icon,
const wxPoint &pos, const wxPoint &pos,
@ -51,16 +53,16 @@ void TextInput::Create(wxWindow * parent,
long style) long style)
{ {
text_ctrl = nullptr; text_ctrl = nullptr;
text = text_in;
StaticBox::Create(parent, wxID_ANY, pos, size, style); StaticBox::Create(parent, wxID_ANY, pos, size, style);
wxWindow::SetLabel(label);
state_handler.attach({&label_color, &text_color}); state_handler.attach({&label_color, &text_color});
state_handler.update_binds(); state_handler.update_binds();
if(Slic3r::GUI::Accessibility::IsLabelAvailable()) if (Slic3r::GUI::Accessibility::IsLabelAvailable()) {
wxStaticText *virtualLabel = new wxStaticText( accessibility_label = Slic3r::GUI::Accessibility::GetLastLabelString();
this, wxID_ANY, Slic3r::GUI::Accessibility::GetLastLabelString(), wxDefaultPosition, wxSize(0, 0), wxST_NO_AUTORESIZE 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); text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, size, style | wxBORDER_NONE);
#ifdef __WXOSX__ #ifdef __WXOSX__
@ -96,11 +98,16 @@ void TextInput::Create(wxWindow * parent,
messureSize(); messureSize();
} }
void TextInput::SetLabel(const wxString& label) void TextInput::SetText(const wxString& text_in)
{ {
wxWindow::SetLabel(label); text = text_in;
messureSize(); messureSize();
Refresh(); 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) bool TextInput::SetBackgroundColour(const wxColour& colour)
@ -294,7 +301,6 @@ void TextInput::render(wxDC& dc)
dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r); dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r);
} }
auto text = wxWindow::GetLabel();
if (!text.IsEmpty()) { if (!text.IsEmpty()) {
wxSize textSize = text_ctrl->GetSize(); wxSize textSize = text_ctrl->GetSize();
if (align_right) { if (align_right) {
@ -315,7 +321,7 @@ void TextInput::messureSize()
{ {
wxSize size = GetSize(); wxSize size = GetSize();
wxClientDC dc(this); wxClientDC dc(this);
labelSize = dc.GetTextExtent(wxWindow::GetLabel()); labelSize = dc.GetTextExtent(text);
const wxSize textSize = text_ctrl->GetSize(); const wxSize textSize = text_ctrl->GetSize();
const wxSize iconSize = drop_down_icon.bmp().IsOk() ? drop_down_icon.GetSize() : wxSize(0, 0); const wxSize iconSize = drop_down_icon.bmp().IsOk() ? drop_down_icon.GetSize() : wxSize(0, 0);

View File

@ -17,6 +17,9 @@ class TextInput : public wxNavigationEnabled<StaticBox>
static const int TextInputWidth = 200; static const int TextInputWidth = 200;
static const int TextInputHeight = 50; static const int TextInputHeight = 50;
wxString accessibility_label;
wxString text;
public: public:
TextInput(); TextInput();
@ -37,7 +40,9 @@ public:
const wxSize & size = wxDefaultSize, const wxSize & size = wxDefaultSize,
long style = 0); long style = 0);
void SetLabel(const wxString& label) wxOVERRIDE; void SetText(const wxString& text);
wxString GetText() const { return text; }
void SetIcon(const wxBitmapBundle& icon); void SetIcon(const wxBitmapBundle& icon);