mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-26 08:16:02 -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
|
@ -41,6 +41,7 @@
|
|||
#include "chprintf.h"
|
||||
#include "chqueues.h"
|
||||
#include "untar.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
|
@ -730,6 +731,87 @@ static void cpld_info(BaseSequentialStream* chp, int argc, char* argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
// walks throught the given widget's childs in recurse to get all support text and pass it to a callback function
|
||||
static void widget_collect_accessibility(BaseSequentialStream* chp, ui::Widget* w, void (*callback)(BaseSequentialStream*, const std::string&, const std::string&), ui::Widget* focusedWidget) {
|
||||
for (auto child : w->children()) {
|
||||
if (!child->hidden()) {
|
||||
std::string res = "";
|
||||
child->getAccessibilityText(res);
|
||||
std::string strtype = "";
|
||||
child->getWidgetName(strtype);
|
||||
if (child == focusedWidget) strtype += "*";
|
||||
if (callback != NULL && !res.empty()) callback(chp, res, strtype);
|
||||
widget_collect_accessibility(chp, child, callback, focusedWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// callback when it found any response from a widget
|
||||
static void accessibility_callback(BaseSequentialStream* chp, const std::string& strResult, const std::string& wgType) {
|
||||
if (!wgType.empty()) {
|
||||
chprintf(chp, "[");
|
||||
chprintf(chp, wgType.c_str());
|
||||
chprintf(chp, "] ");
|
||||
}
|
||||
chprintf(chp, "%s\r\n", strResult.c_str());
|
||||
}
|
||||
|
||||
// gets all widget's accessibility helper text
|
||||
static void cmd_accessibility_readall(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
auto evtd = getEventDispatcherInstance();
|
||||
if (evtd == NULL) {
|
||||
chprintf(chp, "error Can't get Event Dispatcherr\n");
|
||||
return;
|
||||
}
|
||||
auto wg = evtd->getTopWidget();
|
||||
if (wg == NULL) {
|
||||
chprintf(chp, "error Can't get top Widget\r\n");
|
||||
return;
|
||||
}
|
||||
auto focused = evtd->getFocusedWidget();
|
||||
widget_collect_accessibility(chp, wg, accessibility_callback, focused);
|
||||
chprintf(chp, "ok\r\n");
|
||||
}
|
||||
|
||||
// gets focused widget's accessibility helper text
|
||||
static void cmd_accessibility_readcurr(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
auto evtd = getEventDispatcherInstance();
|
||||
if (evtd == NULL) {
|
||||
chprintf(chp, "error Can't get Event Dispatcher\r\n");
|
||||
return;
|
||||
}
|
||||
auto wg = evtd->getFocusedWidget();
|
||||
if (wg == NULL) {
|
||||
chprintf(chp, "error Can't get focused Widget\r\n");
|
||||
return;
|
||||
}
|
||||
std::string res = "";
|
||||
wg->getAccessibilityText(res);
|
||||
if (res.empty()) {
|
||||
// try with parent
|
||||
wg = wg->parent();
|
||||
if (wg == NULL) {
|
||||
chprintf(chp, "error Widget not providing accessibility info\r\n");
|
||||
return;
|
||||
}
|
||||
wg->getAccessibilityText(res);
|
||||
if (res.empty()) {
|
||||
chprintf(chp, "error Widget not providing accessibility info\r\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::string strtype = "";
|
||||
wg->getWidgetName(strtype);
|
||||
accessibility_callback(chp, res, strtype);
|
||||
chprintf(chp, "\r\nok\r\n");
|
||||
}
|
||||
|
||||
static void cmd_cpld_read(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
const char* usage =
|
||||
"usage: cpld_read <device> <target>\r\n"
|
||||
|
@ -915,6 +997,8 @@ static const ShellCommand commands[] = {
|
|||
{"filesize", cmd_sd_filesize},
|
||||
{"cpld_info", cpld_info},
|
||||
{"cpld_read", cmd_cpld_read},
|
||||
{"accessibility_readall", cmd_accessibility_readall},
|
||||
{"accessibility_readcurr", cmd_accessibility_readcurr},
|
||||
{NULL, NULL}};
|
||||
|
||||
static const ShellConfig shell_cfg1 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue