mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-09 23:22:33 -04:00
Accessibility over serial (#1717)
* Initial accessibility support * added it to some widgets to test * More widget accessibility response * More widgets, better output * Mark selected widget on list * typo
This commit is contained in:
parent
eedebe1c52
commit
1a69ce2d97
7 changed files with 275 additions and 0 deletions
|
@ -237,6 +237,12 @@ void Widget::dirty_overlapping_children_in_rect(const Rect& child_rect) {
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::getAccessibilityText(std::string& result) {
|
||||
result = "";
|
||||
}
|
||||
void Widget::getWidgetName(std::string& result) {
|
||||
result = "";
|
||||
}
|
||||
/* View ******************************************************************/
|
||||
|
||||
void View::paint(Painter& painter) {
|
||||
|
@ -367,6 +373,12 @@ void Text::set(std::string_view value) {
|
|||
set_dirty();
|
||||
}
|
||||
|
||||
void Text::getAccessibilityText(std::string& result) {
|
||||
result = text;
|
||||
}
|
||||
void Text::getWidgetName(std::string& result) {
|
||||
result = "Text";
|
||||
}
|
||||
void Text::paint(Painter& painter) {
|
||||
const auto rect = screen_rect();
|
||||
auto s = has_focus() ? style().invert() : style();
|
||||
|
@ -407,6 +419,17 @@ void Labels::paint(Painter& painter) {
|
|||
}
|
||||
}
|
||||
|
||||
void Labels::getAccessibilityText(std::string& result) {
|
||||
result = "";
|
||||
for (auto& label : labels_) {
|
||||
result += label.text;
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
void Labels::getWidgetName(std::string& result) {
|
||||
result = "Labels";
|
||||
}
|
||||
|
||||
/* LiveDateTime **********************************************************/
|
||||
|
||||
void LiveDateTime::on_tick_second() {
|
||||
|
@ -579,6 +602,13 @@ void ProgressBar::set_value(const uint32_t value) {
|
|||
set_dirty();
|
||||
}
|
||||
|
||||
void ProgressBar::getAccessibilityText(std::string& result) {
|
||||
result = to_string_dec_uint(_value) + " / " + to_string_dec_uint(_max);
|
||||
}
|
||||
void ProgressBar::getWidgetName(std::string& result) {
|
||||
result = "ProgressBar";
|
||||
}
|
||||
|
||||
void ProgressBar::paint(Painter& painter) {
|
||||
int v_scaled;
|
||||
|
||||
|
@ -679,6 +709,13 @@ void Console::write(std::string message) {
|
|||
}
|
||||
}
|
||||
|
||||
void Console::getAccessibilityText(std::string& result) {
|
||||
result = "{" + buffer + "}";
|
||||
}
|
||||
void Console::getWidgetName(std::string& result) {
|
||||
result = "Console";
|
||||
}
|
||||
|
||||
void Console::writeln(std::string message) {
|
||||
write(message + "\n");
|
||||
}
|
||||
|
@ -787,6 +824,13 @@ bool Checkbox::set_value(const bool value) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Checkbox::getAccessibilityText(std::string& result) {
|
||||
result = text_ + ((value_) ? " checked" : " unchecked");
|
||||
}
|
||||
void Checkbox::getWidgetName(std::string& result) {
|
||||
result = "Checkbox";
|
||||
}
|
||||
|
||||
bool Checkbox::value() const {
|
||||
return value_;
|
||||
}
|
||||
|
@ -904,6 +948,13 @@ std::string Button::text() const {
|
|||
return text_;
|
||||
}
|
||||
|
||||
void Button::getAccessibilityText(std::string& result) {
|
||||
result = text_;
|
||||
}
|
||||
void Button::getWidgetName(std::string& result) {
|
||||
result = "Button";
|
||||
}
|
||||
|
||||
void Button::paint(Painter& painter) {
|
||||
Color bg, fg;
|
||||
const auto r = screen_rect();
|
||||
|
@ -1050,6 +1101,13 @@ std::string ButtonWithEncoder::text() const {
|
|||
return text_;
|
||||
}
|
||||
|
||||
void ButtonWithEncoder::getAccessibilityText(std::string& result) {
|
||||
result = text_;
|
||||
}
|
||||
void ButtonWithEncoder::getWidgetName(std::string& result) {
|
||||
result = "ButtonWithEncoder";
|
||||
}
|
||||
|
||||
void ButtonWithEncoder::paint(Painter& painter) {
|
||||
Color bg, fg;
|
||||
const auto r = screen_rect();
|
||||
|
@ -1205,6 +1263,13 @@ void NewButton::set_text(const std::string value) {
|
|||
set_dirty();
|
||||
}
|
||||
|
||||
void NewButton::getAccessibilityText(std::string& result) {
|
||||
result = text_;
|
||||
}
|
||||
void NewButton::getWidgetName(std::string& result) {
|
||||
result = "NewButton";
|
||||
}
|
||||
|
||||
std::string NewButton::text() const {
|
||||
return text_;
|
||||
}
|
||||
|
@ -1399,6 +1464,13 @@ ImageButton::ImageButton(
|
|||
set_focusable(true);
|
||||
}
|
||||
|
||||
void ImageButton::getAccessibilityText(std::string& result) {
|
||||
result = "image";
|
||||
}
|
||||
void ImageButton::getWidgetName(std::string& result) {
|
||||
result = "ImageButton";
|
||||
}
|
||||
|
||||
bool ImageButton::on_key(const KeyEvent key) {
|
||||
if (key == KeyEvent::Select) {
|
||||
if (on_select) {
|
||||
|
@ -1489,6 +1561,13 @@ bool ImageToggle::value() const {
|
|||
return value_;
|
||||
}
|
||||
|
||||
void ImageToggle::getAccessibilityText(std::string& result) {
|
||||
result = value_ ? "checked" : "unchecked";
|
||||
}
|
||||
void ImageToggle::getWidgetName(std::string& result) {
|
||||
result = "ImageToggle";
|
||||
}
|
||||
|
||||
void ImageToggle::set_value(bool b) {
|
||||
if (b == value_)
|
||||
return;
|
||||
|
@ -1524,6 +1603,13 @@ size_t ImageOptionsField::selected_index_value() const {
|
|||
return options[selected_index_].second;
|
||||
}
|
||||
|
||||
void ImageOptionsField::getAccessibilityText(std::string& result) {
|
||||
result = "selected index: " + to_string_dec_uint(selected_index_);
|
||||
}
|
||||
void ImageOptionsField::getWidgetName(std::string& result) {
|
||||
result = "ImageOptionsField";
|
||||
}
|
||||
|
||||
void ImageOptionsField::set_selected_index(const size_t new_index) {
|
||||
if (new_index < options.size()) {
|
||||
if (new_index != selected_index()) {
|
||||
|
@ -1623,6 +1709,20 @@ const OptionsField::value_t& OptionsField::selected_index_value() const {
|
|||
return options_[selected_index_].second;
|
||||
}
|
||||
|
||||
void OptionsField::getAccessibilityText(std::string& result) {
|
||||
result = "options: ";
|
||||
bool first = true;
|
||||
for (const auto& option : options_) {
|
||||
if (!first) result += " ,";
|
||||
first = false;
|
||||
result += option.first;
|
||||
}
|
||||
result += "; selected: " + selected_index_name();
|
||||
}
|
||||
void OptionsField::getWidgetName(std::string& result) {
|
||||
result = "OptionsField";
|
||||
}
|
||||
|
||||
void OptionsField::set_selected_index(const size_t new_index, bool trigger_change) {
|
||||
if (new_index < options_.size()) {
|
||||
if (new_index != selected_index() || trigger_change) {
|
||||
|
@ -1741,6 +1841,13 @@ const std::string& TextEdit::value() const {
|
|||
return text_;
|
||||
}
|
||||
|
||||
void TextEdit::getAccessibilityText(std::string& result) {
|
||||
result = text_;
|
||||
}
|
||||
void TextEdit::getWidgetName(std::string& result) {
|
||||
result = "TextEdit";
|
||||
}
|
||||
|
||||
void TextEdit::set_cursor(uint32_t pos) {
|
||||
cursor_pos_ = std::min<size_t>(pos, text_.length());
|
||||
set_dirty();
|
||||
|
@ -1890,6 +1997,13 @@ const std::string& TextField::get_text() const {
|
|||
return text;
|
||||
}
|
||||
|
||||
void TextField::getAccessibilityText(std::string& result) {
|
||||
result = text;
|
||||
}
|
||||
void TextField::getWidgetName(std::string& result) {
|
||||
result = "TextField";
|
||||
}
|
||||
|
||||
void TextField::set_text(std::string_view value) {
|
||||
set(value);
|
||||
if (on_change)
|
||||
|
@ -1945,6 +2059,13 @@ int32_t NumberField::value() const {
|
|||
return value_;
|
||||
}
|
||||
|
||||
void NumberField::getAccessibilityText(std::string& result) {
|
||||
result = to_string_dec_int(value_);
|
||||
}
|
||||
void NumberField::getWidgetName(std::string& result) {
|
||||
result = "NumberField";
|
||||
}
|
||||
|
||||
void NumberField::set_value(int32_t new_value, bool trigger_change) {
|
||||
if (can_loop) {
|
||||
if (new_value >= range.first)
|
||||
|
@ -2155,6 +2276,12 @@ const std::string& SymField::to_string() const {
|
|||
return value_;
|
||||
}
|
||||
|
||||
void SymField::getAccessibilityText(std::string& result) {
|
||||
result = value_;
|
||||
}
|
||||
void SymField::getWidgetName(std::string& result) {
|
||||
result = "SymField";
|
||||
}
|
||||
void SymField::paint(Painter& painter) {
|
||||
Point p = screen_pos();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue