Interface de acessibilidade do editor (tinyblocks-a11y)
Library nova, no papel do ATK/GtkAccessible: cada quadro o editor monta uma árvore acessível (papel, nome, descrição, valor, estados, ações, retângulo), com ids estáveis, eventos entre quadros (foco, estado, nome, valor, componente novo, aviso) e uma ponte para o narrador (TINYBLOCKS_A11Y=log liga uma ponte de texto no stderr). Cada parte da tela se descreve onde é desenhada: menu, áreas, categorias, paleta, abas, blocos (rótulo falado, campos, bocas, parâmetros do defina), grupos, palco, saída, menus e diálogos. As ações agem pelo mesmo caminho do mouse e rolam até o componente se ele estiver fora da vista. API: tb_editor_accessible(scene). O harness acha componentes pela árvore (categorias, cenários 8 e 27) e tem um cenário só de acessibilidade; test-a11y testa a library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
80bd330766
commit
600c4fc520
12 files changed
+1557
-103
No files matched your search
@@ -0,0 +1,127 @@
|
||||
/* Teste da tinyblocks-a11y: arvore acessivel, busca, ids, eventos e acoes */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tb_a11y.h>
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; } } while (0)
|
||||
|
||||
static int performed = -1;
|
||||
static bool perform(void* user, const TinyBlocks_A11yTree* t, int node, TinyBlocks_A11yAction a) {
|
||||
(void)user; (void)t;
|
||||
if (a != TB_A11Y_ACT_ACTIVATE) return false;
|
||||
performed = node;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int bridge_events = 0;
|
||||
static void on_event(void* user, const TinyBlocks_A11yTree* t, const TinyBlocks_A11yEvent* ev) {
|
||||
(void)user; (void)t; (void)ev;
|
||||
bridge_events++;
|
||||
}
|
||||
|
||||
/* Um quadro de uma interface pequena; `sel` = aba selecionada, `edit` = campo com foco */
|
||||
static void build(TinyBlocks_A11yTree* t, int sel, bool edit, const char* value, bool dialog) {
|
||||
tb_a11y_begin(t, "App", 800, 600);
|
||||
tb_a11y_push(t, TB_A11Y_TOOLBAR, "Menu", 0, 0, 800, 40);
|
||||
int b = tb_a11y_add(t, TB_A11Y_BUTTON, "Abrir", 10, 5, 60, 30);
|
||||
tb_a11y_set_actions(t, b, TB_A11Y_ACT_ACTIVATE);
|
||||
tb_a11y_add(t, TB_A11Y_BUTTON, "Salvar", 80, 5, 60, 30);
|
||||
tb_a11y_pop(t);
|
||||
tb_a11y_push(t, TB_A11Y_TAB_LIST, "Abas", 0, 40, 800, 30);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
char nm[16];
|
||||
snprintf(nm, sizeof(nm), "Aba %d", i + 1);
|
||||
int a = tb_a11y_add(t, TB_A11Y_TAB, nm, 10 + i * 100, 40, 90, 30);
|
||||
tb_a11y_set_states(t, a, i == sel ? TB_A11Y_SELECTED : 0);
|
||||
}
|
||||
tb_a11y_pop(t);
|
||||
int blk = tb_a11y_push(t, TB_A11Y_BLOCK, value, 100, 100, 200, 40); /* nome muda com o valor */
|
||||
tb_a11y_set_key(t, blk, "Control.Repeat");
|
||||
tb_a11y_set_point(t, blk, 108, 120);
|
||||
int f = tb_a11y_add(t, TB_A11Y_TEXT_FIELD, "vezes", 150, 108, 30, 24);
|
||||
tb_a11y_set_value(t, f, value);
|
||||
tb_a11y_set_states(t, f, TB_A11Y_EDITABLE | (edit ? TB_A11Y_FOCUSED | TB_A11Y_EDITING : 0));
|
||||
tb_a11y_pop(t);
|
||||
if (dialog) {
|
||||
tb_a11y_push(t, TB_A11Y_DIALOG, "Configurações", 100, 100, 600, 400);
|
||||
tb_a11y_add(t, TB_A11Y_BUTTON, "Voltar", 100, 100, 80, 40);
|
||||
tb_a11y_pop(t);
|
||||
}
|
||||
tb_a11y_end(t);
|
||||
}
|
||||
|
||||
static bool has_event(TinyBlocks_A11yTree* t, TinyBlocks_A11yEventKind k) {
|
||||
for (int i = 0; i < tb_a11y_event_count(t); i++) if (tb_a11y_event(t, i)->kind == k) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
TinyBlocks_A11yTree* t = tb_a11y_tree_new();
|
||||
tb_a11y_set_perform(t, perform, NULL);
|
||||
|
||||
build(t, 0, false, "repita (10) vezes", false);
|
||||
CHECK(tb_a11y_count(t) == 10, "árvore com a raiz e 9 componentes");
|
||||
int menu = tb_a11y_find(t, 0, TB_A11Y_TOOLBAR, "Menu", 0);
|
||||
int abrir = tb_a11y_find(t, menu, TB_A11Y_BUTTON, "Abrir", 0);
|
||||
CHECK(menu > 0 && abrir > menu && tb_a11y_node(t, abrir)->parent == menu, "busca por papel + nome, dentro do pai");
|
||||
CHECK(tb_a11y_find(t, menu, TB_A11Y_TAB, NULL, 0) < 0, "a busca fica na subárvore");
|
||||
CHECK(tb_a11y_find(t, 0, TB_A11Y_TAB, NULL, 2) >= 0 && tb_a11y_find(t, 0, TB_A11Y_TAB, NULL, 3) < 0,
|
||||
"n-ésimo componente");
|
||||
CHECK(tb_a11y_find_part(t, 0, TB_A11Y_BLOCK, "repita", 0) >= 0, "busca por parte do nome");
|
||||
CHECK(tb_a11y_event_count(t) == 0, "primeiro quadro não gera eventos");
|
||||
|
||||
char buf[256];
|
||||
CHECK(!strcmp(tb_a11y_path(t, abrir, buf, sizeof(buf)), "Menu > Abrir"), "caminho \"Menu > Abrir\"");
|
||||
int aba1 = tb_a11y_find(t, 0, TB_A11Y_TAB, "Aba 1", 0);
|
||||
CHECK(!strcmp(tb_a11y_describe(t, aba1, buf, sizeof(buf)), "Aba 1, aba, selecionado"), "frase do narrador com estado");
|
||||
|
||||
float x, y;
|
||||
int blk = tb_a11y_find(t, 0, TB_A11Y_BLOCK, NULL, 0);
|
||||
tb_a11y_point(t, blk, &x, &y);
|
||||
CHECK(x == 108 && y == 120, "ponto de ação próprio");
|
||||
tb_a11y_center(t, abrir, &x, &y);
|
||||
CHECK(x == 40 && y == 20, "centro do retângulo");
|
||||
|
||||
CHECK(tb_a11y_do_action(t, abrir, TB_A11Y_ACT_ACTIVATE) && performed == abrir, "ação executada por quem desenha");
|
||||
int salvar = tb_a11y_find(t, 0, TB_A11Y_BUTTON, "Salvar", 0);
|
||||
CHECK(!tb_a11y_do_action(t, salvar, TB_A11Y_ACT_ACTIVATE), "ação não declarada é recusada");
|
||||
|
||||
uint32_t id_aba2 = tb_a11y_node(t, tb_a11y_find(t, 0, TB_A11Y_TAB, "Aba 2", 0))->id;
|
||||
uint32_t id_blk = tb_a11y_node(t, blk)->id;
|
||||
|
||||
TinyBlocks_A11yBridge br = { "teste", on_event, NULL, NULL };
|
||||
tb_a11y_set_bridge(t, &br);
|
||||
|
||||
/* quadro 2: outra aba, campo editando com valor novo, dialogo aberto */
|
||||
build(t, 1, true, "repita (25) vezes", true);
|
||||
int aba2 = tb_a11y_find(t, 0, TB_A11Y_TAB, "Aba 2", 0);
|
||||
blk = tb_a11y_find(t, 0, TB_A11Y_BLOCK, NULL, 0);
|
||||
CHECK(tb_a11y_node(t, aba2)->id == id_aba2, "id estável entre quadros");
|
||||
CHECK(tb_a11y_node(t, blk)->id == id_blk, "set_key: o id não muda quando o nome muda");
|
||||
CHECK(has_event(t, TB_A11Y_EV_STATE), "evento de estado (seleção mudou)");
|
||||
CHECK(has_event(t, TB_A11Y_EV_FOCUS), "evento de foco (campo editando)");
|
||||
CHECK(tb_a11y_focus(t) == tb_a11y_find(t, 0, TB_A11Y_TEXT_FIELD, "vezes", 0), "foco = campo editando");
|
||||
CHECK(has_event(t, TB_A11Y_EV_VALUE) && has_event(t, TB_A11Y_EV_NAME), "eventos de valor e de nome");
|
||||
CHECK(has_event(t, TB_A11Y_EV_SHOWN), "evento: diálogo apareceu");
|
||||
CHECK(bridge_events == tb_a11y_event_count(t), "a ponte recebe todos os eventos");
|
||||
|
||||
/* quadro 3: igual ao 2 -> nada muda */
|
||||
build(t, 1, true, "repita (25) vezes", true);
|
||||
CHECK(tb_a11y_event_count(t) == 0, "quadro igual não gera eventos");
|
||||
|
||||
tb_a11y_announce(t, "ignorado fora de begin/end"); /* o begin seguinte limpa */
|
||||
tb_a11y_begin(t, "App", 800, 600);
|
||||
tb_a11y_announce(t, "Projeto salvo");
|
||||
tb_a11y_end(t);
|
||||
CHECK(tb_a11y_event_count(t) == 1 && tb_a11y_event(t, 0)->kind == TB_A11Y_EV_ANNOUNCE &&
|
||||
!strcmp(tb_a11y_event(t, 0)->text, "Projeto salvo"), "aviso para ler em voz alta");
|
||||
|
||||
/* robustez: arvore NULL e indices invalidos */
|
||||
CHECK(tb_a11y_push(NULL, TB_A11Y_BUTTON, "x", 0, 0, 1, 1) == -1 && tb_a11y_node(t, 999) == NULL &&
|
||||
tb_a11y_find(t, 999, TB_A11Y_NONE, NULL, 0) == -1, "NULL e índices inválidos não quebram");
|
||||
|
||||
tb_a11y_tree_free(t);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
return fails != 0;
|
||||
}
|
||||
+209
-59
@@ -23,6 +23,7 @@
|
||||
#include <tb_ppm.h>
|
||||
#include <tb_input_lib.h>
|
||||
#include <tb_environ.h>
|
||||
#include <tb_a11y.h>
|
||||
|
||||
static TinyBlocks* rt;
|
||||
static TinyBlocks_Block *ev, *scene;
|
||||
@@ -80,8 +81,36 @@ static bool in_region(float x, int r) {
|
||||
}
|
||||
}
|
||||
|
||||
/* == Interface de acessibilidade: componentes por papel + nome ===
|
||||
* (nao depende do texto desenhado nem de coordenadas fixas) */
|
||||
static TinyBlocks_A11yTree* A(void) { return tb_editor_accessible(scene); }
|
||||
static const TinyBlocks_A11yNode* N(int n) { return tb_a11y_node(A(), n); }
|
||||
static int ax_in(int from, TinyBlocks_A11yRole r, const char* name) { return tb_a11y_find(A(), from, r, name, 0); }
|
||||
static int ax_part(int from, TinyBlocks_A11yRole r, const char* part) { return tb_a11y_find_part(A(), from, r, part, 0); }
|
||||
static int ax_need(int from, TinyBlocks_A11yRole r, const char* name) {
|
||||
int n = ax_in(from, r, name);
|
||||
if (n < 0) { printf("FAIL não achei o %s \"%s\" na árvore acessível\n", tb_a11y_role_name(r), name); fails++; }
|
||||
return n;
|
||||
}
|
||||
static const char* ax_value(int n) { return n >= 0 ? N(n)->value : ""; }
|
||||
static int ax_count(int from, TinyBlocks_A11yRole r, const char* name) {
|
||||
int k = 0;
|
||||
while (tb_a11y_find(A(), from, r, name, k) >= 0) k++;
|
||||
return k;
|
||||
}
|
||||
|
||||
/* Categoria (aba da coluna "Categorias") */
|
||||
static bool find_cat(const char* s, int nth, float* x, float* y) {
|
||||
int list = ax_in(0, TB_A11Y_TAB_LIST, "Categorias");
|
||||
int n = list >= 0 ? tb_a11y_find(A(), list, TB_A11Y_TAB, s, nth) : -1;
|
||||
if (n < 0) return false;
|
||||
tb_a11y_point(A(), n, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Centro (aprox.) do n-ésimo texto igual a s na região */
|
||||
static bool find(const char* s, int region, int nth, float* x, float* y) {
|
||||
if (region == R_CAT) return find_cat(s, nth, x, y);
|
||||
for (uint32_t i = 0; i < ncmd; i++) {
|
||||
TinyBlocks_DrawCmd* c = &cmds[i];
|
||||
if (c->kind != TB_DRAW_TEXT || strcmp(c->text, s) != 0 || !in_region(c->x, region)) continue;
|
||||
@@ -210,6 +239,23 @@ static void type(const char* s) { frame(0, 0, 0, 0, 0, 0, s); }
|
||||
static void key(int sc, float x, float y) { frame(x, y, 0, 0, 0, sc, NULL); }
|
||||
static void flag(void) { click(920 + 30, 44 + 22); }
|
||||
|
||||
/* Executa uma acao acessivel e roda um quadro (a arvore e redesenhada) */
|
||||
static bool ax_do(int n, TinyBlocks_A11yAction a) {
|
||||
if (n < 0) return false;
|
||||
float x, y;
|
||||
tb_a11y_point(A(), n, &x, &y);
|
||||
bool ok = tb_a11y_do_action(A(), n, a);
|
||||
frame(x, y, 0, 0, 0, 0, NULL);
|
||||
return ok;
|
||||
}
|
||||
/* Arrasta o componente pelo seu ponto, levando o canto dele para (tx, ty) */
|
||||
static void ax_drag_to(int n, float tx, float ty) {
|
||||
if (n < 0) return;
|
||||
float px, py;
|
||||
tb_a11y_point(A(), n, &px, &py);
|
||||
drag(px, py, tx + (px - N(n)->x), ty + (py - N(n)->y));
|
||||
}
|
||||
|
||||
static bool need(const char* s, int region, int nth, float* x, float* y) {
|
||||
if (find(s, region, nth, x, y)) return true;
|
||||
printf("FAIL não achei \"%s\"\n", s); fails++;
|
||||
@@ -314,74 +360,82 @@ int main(void) {
|
||||
int after = 0; while (find("escreva", R_WS, after, &x2, &y2)) after++;
|
||||
CHECK(after == before - 1, "soltar bloco sobre a paleta apaga");
|
||||
|
||||
/* 8. Bloco composto "dobro(n)" criado pelo diálogo; corpo: devolva n + 1 */
|
||||
/* 8. Bloco composto "dobro(n)" criado pelo diálogo; corpo: devolva n + 1.
|
||||
* Tudo achado pela interface de acessibilidade (papel + nome). */
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
||||
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
||||
ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||
{
|
||||
int dlg = ax_need(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||
int nome = ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco");
|
||||
CHECK(dlg >= 0 && (N(dlg)->states & TB_A11Y_MODAL), "diálogo \"Criar um Bloco\" na árvore, modal");
|
||||
CHECK(nome >= 0 && tb_a11y_focus(A()) == nome, "o foco abre no campo \"Nome do bloco\"");
|
||||
}
|
||||
type("dobro");
|
||||
if (need("número ou texto", R_WS, 0, &x, &y)) click(x, y);
|
||||
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Nome do bloco")), "dobro"), "o nome digitado é o valor do campo");
|
||||
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "Adicionar entrada de número ou texto"),
|
||||
TB_A11Y_ACT_ACTIVATE);
|
||||
type("n");
|
||||
key(TB_KEY_RETURN, 0, 0); /* OK no diálogo */
|
||||
/* como no Scratch: o "defina" aparece na própria aba, com o parâmetro ao lado */
|
||||
CHECK(ws_has("defina") && ws_count("n") == 1, "Criar um Bloco põe \"defina dobro\" na mesma aba (sem parâmetros soltos)");
|
||||
CHECK(ws_has("quando a bandeira for clicado"), "sem abrir aba nova: os scripts continuam ali");
|
||||
hx = 0; hy = 0;
|
||||
need("defina", R_WS, 0, &hx, &hy);
|
||||
{ float nx, ny; CHECK(find_near("dobro", hx, hy, &nx, &ny) && find_near("n", nx, ny, &nx, &ny),
|
||||
"o protótipo \"dobro (n)\" aparece dentro do defina"); }
|
||||
CHECK(!strcmp(ax_value(tb_a11y_focus(A())), "n"), "a entrada nova recebe o foco e o nome n");
|
||||
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "OK"), TB_A11Y_ACT_ACTIVATE);
|
||||
CHECK(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco") < 0, "OK fecha o diálogo");
|
||||
|
||||
int panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
||||
int def = ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)");
|
||||
/* como no Scratch: o "defina" aparece na própria aba, e o parâmetro só dentro dele */
|
||||
CHECK(def >= 0, "Criar um Bloco põe \"defina dobro (n)\" na mesma aba");
|
||||
CHECK(ax_count(panel, TB_A11Y_BLOCK, "n") == 1 && ax_in(def, TB_A11Y_BLOCK, "n") >= 0,
|
||||
"sem parâmetros soltos: o \"n\" está no protótipo do defina");
|
||||
CHECK(ax_in(panel, TB_A11Y_BLOCK, "quando a bandeira for clicado") >= 0, "sem abrir aba nova: os scripts continuam ali");
|
||||
float dfx = def >= 0 ? N(def)->x : 0, dfy = def >= 0 ? N(def)->y : 0, dfh = def >= 0 ? N(def)->h : 0;
|
||||
|
||||
/* devolva embaixo do "defina"; um "+" solto ao lado */
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("devolva", R_FLY, 0, &x, &y)) drag(x, y, hx, hy + 44); /* embaixo do "defina" */
|
||||
ax_drag_to(ax_part(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BLOCK, "devolva"), dfx, dfy + dfh);
|
||||
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, hx + 300, hy + 110);
|
||||
/* encaixa o parâmetro n no slot esquerdo do "+" */
|
||||
{
|
||||
float px, py, zx, zy;
|
||||
/* o parâmetro sai arrastando de dentro do "defina" */
|
||||
float dx0, dy0;
|
||||
if (find_near("dobro", hx, hy, &dx0, &dy0) && find_near("n", dx0, dy0, &px, &py) &&
|
||||
block_plus(&x, &y, hy + 20)) {
|
||||
int k = 0; bool got = false;
|
||||
while (find("0", R_WS, k++, &zx, &zy))
|
||||
if (zy > y - 4 && zy < y + 4 && zx < x) { got = true; break; }
|
||||
if (!got) { printf("FAIL slot esquerdo do + (+ em %.0f,%.0f)\n", x, y); fails++; }
|
||||
else drag(px, py, zx - 3, zy);
|
||||
}
|
||||
CHECK(ws_count("n") == 2, "arrastar o parâmetro do defina cria o reporter \"n\"");
|
||||
int ops = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Operadores");
|
||||
ax_drag_to(ax_part(ops, TB_A11Y_BLOCK, ") + ("), dfx + 300, dfy + 110);
|
||||
}
|
||||
/* digita 1 no slot direito do "+" */
|
||||
if (block_plus(&x, &y, hy + 20)) {
|
||||
float zx, zy; int k = 0;
|
||||
while (find("0", R_WS, k++, &zx, &zy))
|
||||
if (zy > y - 4 && zy < y + 4 && zx > x) {
|
||||
click(zx, zy); type("1"); key(TB_KEY_RETURN, 0, 0); break;
|
||||
}
|
||||
/* o parâmetro sai arrastando de dentro do "defina" para o 1o campo do "+" */
|
||||
{
|
||||
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
||||
int plus = ax_in(ax_in(panel, TB_A11Y_LIST, "Pilha: (0) + (0)"), TB_A11Y_BLOCK, "(0) + (0)");
|
||||
int slot = ax_in(plus, TB_A11Y_TEXT_FIELD, NULL);
|
||||
if (slot >= 0) ax_drag_to(ax_in(ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)"), TB_A11Y_BLOCK, "n"),
|
||||
N(slot)->x, N(slot)->y);
|
||||
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
||||
CHECK(ax_in(panel, TB_A11Y_BLOCK, "(n) + (0)") >= 0, "arrastar o parâmetro do defina põe \"n\" no +");
|
||||
}
|
||||
if (block_plus(&x, &y, hy + 20) && need("=", R_WS, 0, &x2, &y2)) {
|
||||
float rep_left = x - 3 - 10;
|
||||
/* o reporter "n" (o outro "n" esta no defina) */
|
||||
{ float px, py; for (int k = 0; find("n", R_WS, k, &px, &py); k++)
|
||||
if (py > hy + 10) { rep_left = px - 3 - 10; break; } }
|
||||
drag(x, y, x + ((x2 + 12) - rep_left), y + (y2 - y));
|
||||
/* 1 no outro campo do "+" */
|
||||
ax_do(ax_in(ax_in(0, TB_A11Y_BLOCK, "(n) + (0)"), TB_A11Y_TEXT_FIELD, NULL), TB_A11Y_ACT_EDIT);
|
||||
key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type("1"); key(TB_KEY_RETURN, 0, 0);
|
||||
/* o "+" no campo de valor do devolva (o 2o campo) */
|
||||
{
|
||||
int dev = ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "devolva");
|
||||
int val = dev >= 0 ? tb_a11y_find(A(), dev, TB_A11Y_TEXT_FIELD, NULL, 1) : -1;
|
||||
if (val >= 0) ax_drag_to(ax_need(0, TB_A11Y_BLOCK, "(n) + (1)"), N(val)->x, N(val)->y);
|
||||
CHECK(ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "= ((n) + (1))") >= 0,
|
||||
"corpo: devolva (n) + (1)");
|
||||
}
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
CHECK(find("dobro", R_FLY, 0, &x, &y), "bloco dobro aparece em Meus Blocos");
|
||||
if (need("dobro", R_FLY, 0, &x, &y)) drag(x, y, hx + 330, hy - 30);
|
||||
{
|
||||
float sx, sy;
|
||||
float dx2 = 0, dy2 = 0;
|
||||
for (int k = 0; find("dobro", R_WS, k, &x, &y); k++) if (y < hy) { dx2 = x; dy2 = y; }
|
||||
if (dx2 > 0 && find_near("n", dx2, dy2, &sx, &sy)) {
|
||||
click(sx, sy);
|
||||
key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type("21"); key(TB_KEY_RETURN, 0, 0);
|
||||
}
|
||||
int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos");
|
||||
int call = ax_in(mine, TB_A11Y_BLOCK, "dobro (n)");
|
||||
CHECK(call >= 0, "bloco dobro aparece em Meus Blocos");
|
||||
ax_drag_to(call, dfx + 330, dfy - 60);
|
||||
}
|
||||
{ int k = 0; float bx = 0, by = 0;
|
||||
while (find("dobro", R_WS, k, &x, &y)) { if (y < hy) { bx = x; by = y; } k++; } /* a chamada, não o "defina" */
|
||||
if (bx > 0) { click(bx, by); click(bx, by); } }
|
||||
CHECK(ws_has("22"), "bloco composto dobro(21) = 22");
|
||||
if (!ws_has("22")) { for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind==TB_DRAW_TEXT && in_region(cmds[i].x,R_WS)) printf(" ws: %s (%.0f,%.0f)\n", cmds[i].text, cmds[i].x, cmds[i].y); }
|
||||
{
|
||||
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
||||
int call = ax_in(panel, TB_A11Y_BLOCK, "dobro (n)");
|
||||
ax_do(ax_in(call, TB_A11Y_TEXT_FIELD, NULL), TB_A11Y_ACT_EDIT);
|
||||
key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type("21"); key(TB_KEY_RETURN, 0, 0);
|
||||
call = ax_in(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "dobro (21)");
|
||||
ax_do(call, TB_A11Y_ACT_ACTIVATE);
|
||||
ax_do(call, TB_A11Y_ACT_ACTIVATE); /* clique duplo: balão com o valor */
|
||||
}
|
||||
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_STATUS, "Resultado")), "22"), "bloco composto dobro(21) = 22");
|
||||
|
||||
/* 9. Laço infinito é interrompido */
|
||||
if (need("Controle", R_CAT, 0, &x, &y)) click(x, y);
|
||||
@@ -1123,16 +1177,112 @@ int main(void) {
|
||||
const char* nomes[2] = { "render", "draw button" };
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
||||
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
||||
type(nomes[k]);
|
||||
ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||
type(nomes[k]); /* o foco abre no nome do bloco */
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
}
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
CHECK(find("render", R_FLY, 0, &x, &y) && find("draw button", R_FLY, 0, &x, &y),
|
||||
int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos");
|
||||
CHECK(ax_in(mine, TB_A11Y_BLOCK, "render") >= 0 && ax_in(mine, TB_A11Y_BLOCK, "draw button") >= 0,
|
||||
"dois blocos definidos aparecem na paleta");
|
||||
}
|
||||
|
||||
/* 28. Interface de acessibilidade: estrutura, estados, eventos, acoes */
|
||||
{
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
int menu = ax_in(0, TB_A11Y_TOOLBAR, "Menu");
|
||||
CHECK(menu >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Abrir") >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Salvar") >= 0 &&
|
||||
ax_in(menu, TB_A11Y_BUTTON, "Config") >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Carregar library...") >= 0,
|
||||
"a11y: barra de menu com os botões");
|
||||
CHECK(ax_in(0, TB_A11Y_PANE, "Blocos") >= 0 && ax_in(0, TB_A11Y_PANE, "Scripts") >= 0 &&
|
||||
ax_in(0, TB_A11Y_PANE, "Palco") >= 0 && ax_in(0, TB_A11Y_PANE, "Saída") >= 0,
|
||||
"a11y: as quatro áreas são painéis");
|
||||
|
||||
int run = ax_in(ax_in(0, TB_A11Y_PANE, "Palco"), TB_A11Y_BUTTON, "Executar");
|
||||
uint32_t run_id = run >= 0 ? N(run)->id : 0;
|
||||
char d[256];
|
||||
CHECK(run >= 0 && !strcmp(tb_a11y_describe(A(), run, d, sizeof(d)), "Executar, botão"),
|
||||
"a11y: o narrador diz \"Executar, botão\"");
|
||||
|
||||
/* categoria: ativar seleciona (e gera evento de estado) */
|
||||
int cats = ax_in(0, TB_A11Y_TAB_LIST, "Categorias");
|
||||
ax_do(ax_in(cats, TB_A11Y_TAB, "Controle"), TB_A11Y_ACT_ACTIVATE);
|
||||
int ctl = ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Categorias"), TB_A11Y_TAB, "Controle");
|
||||
bool ev_state = false;
|
||||
for (int i = 0; i < tb_a11y_event_count(A()); i++) {
|
||||
const TinyBlocks_A11yEvent* e = tb_a11y_event(A(), i);
|
||||
if (e->kind == TB_A11Y_EV_STATE && e->node == ctl) ev_state = true;
|
||||
}
|
||||
CHECK(ctl >= 0 && (N(ctl)->states & TB_A11Y_SELECTED) && ev_state,
|
||||
"a11y: ativar a categoria a seleciona (evento de estado)");
|
||||
int sel = 0;
|
||||
for (int k = 0; tb_a11y_find(A(), cats, TB_A11Y_TAB, NULL, k) >= 0; k++)
|
||||
if (N(tb_a11y_find(A(), cats, TB_A11Y_TAB, NULL, k))->states & TB_A11Y_SELECTED) sel++;
|
||||
CHECK(sel == 1, "a11y: uma categoria selecionada por vez");
|
||||
run = ax_in(0, TB_A11Y_BUTTON, "Executar");
|
||||
CHECK(run >= 0 && N(run)->id == run_id, "a11y: ids estáveis entre quadros");
|
||||
|
||||
/* blocos da paleta fora da vista ficam OFFSCREEN, mas estão na árvore */
|
||||
int pal = ax_in(0, TB_A11Y_LIST, "Paleta");
|
||||
int far = ax_in(pal, TB_A11Y_GROUP, "Meus Blocos");
|
||||
CHECK(far >= 0 && (N(far)->states & TB_A11Y_OFFSCREEN) && ax_in(pal, TB_A11Y_GROUP, "Controle") >= 0 &&
|
||||
!(N(ax_in(pal, TB_A11Y_GROUP, "Controle"))->states & TB_A11Y_OFFSCREEN),
|
||||
"a11y: a paleta toda está na árvore; o que não aparece é OFFSCREEN");
|
||||
|
||||
/* dialogo: abrir pelo botão, evento SHOWN, voltar fecha */
|
||||
ax_do(ax_in(0, TB_A11Y_BUTTON, "Config"), TB_A11Y_ACT_ACTIVATE);
|
||||
int dlg = ax_in(0, TB_A11Y_DIALOG, "Configurações");
|
||||
bool shown = false;
|
||||
for (int i = 0; i < tb_a11y_event_count(A()); i++)
|
||||
if (tb_a11y_event(A(), i)->kind == TB_A11Y_EV_SHOWN && tb_a11y_event(A(), i)->node == dlg) shown = true;
|
||||
CHECK(dlg >= 0 && (N(dlg)->states & TB_A11Y_MODAL) && shown, "a11y: Config abre um diálogo modal (evento)");
|
||||
ax_do(ax_in(dlg, TB_A11Y_BUTTON, "Voltar"), TB_A11Y_ACT_ACTIVATE);
|
||||
CHECK(ax_in(0, TB_A11Y_DIALOG, "Configurações") < 0, "a11y: Voltar fecha o diálogo");
|
||||
|
||||
/* menu "+": o botão fica EXPANDED e o menu tem os itens */
|
||||
ax_do(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_BUTTON, "Nova aba"), TB_A11Y_ACT_ACTIVATE);
|
||||
int pm = ax_in(0, TB_A11Y_MENU, "Nova aba");
|
||||
CHECK(pm >= 0 && ax_in(pm, TB_A11Y_MENU_ITEM, "Editor de Código") >= 0 &&
|
||||
(N(ax_in(0, TB_A11Y_BUTTON, "Nova aba"))->states & TB_A11Y_EXPANDED),
|
||||
"a11y: o menu \"Nova aba\" abre com os itens");
|
||||
ax_do(ax_in(pm, TB_A11Y_MENU_ITEM, "Editor de Código"), TB_A11Y_ACT_ACTIVATE);
|
||||
int code = ax_in(0, TB_A11Y_TEXT_FIELD, "Código");
|
||||
CHECK(code >= 0 && tb_a11y_focus(A()) == code, "a11y: aba de código é um campo de texto com o foco");
|
||||
type("int x;");
|
||||
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Código")), "int x;"), "a11y: valor = linha do cursor");
|
||||
{ /* fecha a aba de codigo (a selecionada) */
|
||||
int tabs = ax_in(0, TB_A11Y_TAB_LIST, "Abas"), cur = -1;
|
||||
for (int k = 0, t; (t = tb_a11y_find(A(), tabs, TB_A11Y_TAB, NULL, k)) >= 0; k++)
|
||||
if (N(t)->states & TB_A11Y_SELECTED) cur = t;
|
||||
ax_do(ax_in(cur, TB_A11Y_BUTTON, "Fechar aba"), TB_A11Y_ACT_ACTIVATE);
|
||||
CHECK(ax_in(0, TB_A11Y_TEXT_FIELD, "Código") < 0, "a11y: \"Fechar aba\" fecha a aba");
|
||||
}
|
||||
|
||||
/* menu de contexto num bloco */
|
||||
int hat = ax_in(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "quando a bandeira for clicado");
|
||||
CHECK(hat >= 0 && (N(hat)->states & TB_A11Y_OFFSCREEN), "a11y: bloco fora da vista é OFFSCREEN");
|
||||
ax_do(hat, TB_A11Y_ACT_MENU); /* rola até ele e abre o menu */
|
||||
int cm = ax_in(0, TB_A11Y_MENU, "Menu de contexto");
|
||||
CHECK(cm >= 0 && ax_in(cm, TB_A11Y_MENU_ITEM, "Duplicar") >= 0, "a11y: menu de contexto do bloco");
|
||||
key(TB_KEY_ESCAPE, 0, 0);
|
||||
|
||||
/* ponte de texto (um narrador simples) */
|
||||
FILE* log = tmpfile();
|
||||
if (log) {
|
||||
TinyBlocks_A11yBridge b = tb_a11y_log_bridge(log);
|
||||
tb_a11y_set_bridge(A(), &b);
|
||||
ax_do(ax_in(0, TB_A11Y_BUTTON, "Config"), TB_A11Y_ACT_ACTIVATE);
|
||||
ax_do(ax_in(ax_in(0, TB_A11Y_DIALOG, "Configurações"), TB_A11Y_BUTTON, "Voltar"), TB_A11Y_ACT_ACTIVATE);
|
||||
tb_a11y_set_bridge(A(), NULL);
|
||||
char lb[2048] = "";
|
||||
rewind(log);
|
||||
size_t n = fread(lb, 1, sizeof(lb) - 1, log);
|
||||
lb[n] = 0;
|
||||
fclose(log);
|
||||
CHECK(strstr(lb, "[a11y] abriu: Configurações, diálogo") != NULL, "a11y: a ponte recebe os eventos");
|
||||
}
|
||||
}
|
||||
|
||||
tinyblocks_deinit(&rt);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
return fails != 0;
|
||||
|
||||
Reference in new issue
Block a user