Acessibilidade: arrastar e soltar como ação; harness inteiro pela árvore

tb_a11y_drop(origem, destino) e tb_a11y_drop_at(origem, destino, x, y):
o editor encaixa pelo papel do destino (campo, embaixo de um bloco,
dentro de uma boca, sobre a paleta para apagar, aba sobre aba, área
sobre área) pelo mesmo caminho do mouse (pointer_motion, extraído do
tratamento de entrada); origem ou destino fora da vista rolam antes.

A árvore passa a cobrir o explorador de arquivos (trilha, locais,
arquivos, nome, opções, confirmação de substituir), a aba de imagem
(ferramentas, folha, rodapé, cores, paleta, camadas), a dica (Alt),
as bordas entre áreas, as alças e os botões de destacar. O retângulo do
palco é a vista dele; avisos repetidos dizem quantas vezes no valor.

O harness não acha mais nada por texto desenhado nem por coordenada
fixa: categorias, blocos, campos, menus, diálogos, saída e avisos vêm
da árvore. Só pintar na folha e soltar em lugar livre usam posição, e
relativa a um componente.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 07:41:12 -03:00
1 parent 600c4fc520
commit 8f046833e7
10 files changed
+953 -747

No files matched your search

@@ -16,7 +16,8 @@ CFLAGS := -std=c11 -Wall -Wextra -pedantic \
-I../../../tinyblocks-environ/include \
-I../../../tinyblocks-api/include \
-I../../../tinyblocks-libman/include \
-I../../../tinyblocks-syntax/include
-I../../../tinyblocks-syntax/include \
-I../../../tinyblocks-a11y/include
OBJS := $(BUILD)/tb_editor_files.o
LIB_A := $(BUILD)/libtinyblocks-editor-files.a
@@ -29,6 +30,7 @@ shared: $(LIB_SO)
$(BUILD)/tb_editor_files.o: src/tb_editor_files.c include/tb_editor_files.h \
../../include/tb_editor_internal.h \
../../../tinyblocks-a11y/include/tb_a11y.h \
../tinyblocks-editor-widgets/include/tb_editor_widgets.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -fPIC -c $< -o $@
@@ -17,6 +17,7 @@
#include <unistd.h>
#include <tb_editor_internal.h>
#include <tb_a11y.h>
#include "tb_editor_files.h"
/* -- Geometria --- */
@@ -609,11 +610,91 @@ static void fd_confirm_geom(const FdL* L, float* bx, float* by, float* bw, float
*by = L->y + (L->h - *bh) * 0.5f;
}
/* Componente que se ativa com um clique (acessibilidade) */
static int fd_ax_click(TinyBlocks_A11yTree* t, TinyBlocks_A11yRole r, const char* name,
float x, float y, float w, float h) {
int n = tb_a11y_add(t, r, name, x, y, w, h);
tb_a11y_set_actions(t, n, TB_A11Y_ACT_ACTIVATE);
return n;
}
/* O explorador na arvore acessivel: dialogo com trilha, locais, arquivos,
* campo do nome, opcoes, botoes e a confirmacao de substituir */
static void fd_ax(Ed* ed, const FdL* L) {
TinyBlocks_A11yTree* t = ed_ax(ed);
if (!t) return;
FileDlg* F = &ed->fdlg;
char buf[512];
tb_a11y_set_states(t, tb_a11y_push(t, TB_A11Y_DIALOG, F->title, L->x, L->y, L->w, L->h), TB_A11Y_MODAL);
fd_ax_click(t, TB_A11Y_BUTTON, "Fechar", L->close_cx - 14, L->close_cy - 14, 28, 28);
tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_BUTTON, "Pasta acima", L->up_x, L->bar_y, 32, 30),
strcmp(F->dir, "/") != 0 ? 0 : TB_A11Y_DISABLED);
{
FdCrumbs K;
fd_crumbs(ed, L, &K);
int tr = tb_a11y_push(t, TB_A11Y_TOOLBAR, "Caminho", L->crumb_x, L->bar_y, L->crumb_w, 30);
tb_a11y_set_value(t, tr, F->dir);
for (int k = K.first; k < K.n; k++) {
fd_crumb_label(F, &K, k, buf, sizeof(buf));
fd_ax_click(t, TB_A11Y_BUTTON, buf, K.x[k], L->bar_y + 3, K.w[k], 24);
}
tb_a11y_pop(t);
}
tb_a11y_push(t, TB_A11Y_LIST, "Locais", L->side_x, L->side_y, FD_SIDE_W, L->side_h);
for (int i = 0; i < F->place_n; i++) {
int n = fd_ax_click(t, TB_A11Y_LIST_ITEM, F->place_label[i], L->side_x + 6, L->side_y + 30 + i * 32,
FD_SIDE_W - 12, 30);
tb_a11y_set_value(t, n, F->place_path[i]);
tb_a11y_set_states(t, n, strcmp(F->dir, F->place_path[i]) == 0 ? TB_A11Y_SELECTED : 0);
}
tb_a11y_pop(t);
tb_a11y_push(t, TB_A11Y_LIST, "Arquivos", L->list_x, L->list_y, L->list_w, L->list_h);
int end = F->scroll + L->rows;
if (end > F->n) end = F->n;
for (int i = F->scroll; i < end; i++) { /* as linhas visiveis */
FileEnt* e = &F->ents[i];
float ry = L->list_y + (float)(i - F->scroll) * FD_ROW_H;
int n = fd_ax_click(t, TB_A11Y_LIST_ITEM, e->is_dir == 2 ? ".." : e->name,
L->list_x + 4, ry + 1, L->list_w - 18, FD_ROW_H - 2);
if (e->is_dir) tb_a11y_set_value(t, n, e->is_dir == 2 ? "pasta acima" : "pasta");
else { fd_size_str(buf, sizeof(buf), e->size); tb_a11y_set_value(t, n, buf); }
tb_a11y_set_states(t, n, i == F->sel ? TB_A11Y_SELECTED : 0);
}
tb_a11y_pop(t);
if (F->err[0]) tb_a11y_add(t, TB_A11Y_STATUS, F->err, L->list_x + 8, L->list_y + L->list_h - 30, L->list_w - 24, 24);
int nm = tb_a11y_add(t, TB_A11Y_TEXT_FIELD, "Nome", L->name_x, L->name_y, L->name_w, 30);
tb_a11y_set_value(t, nm, F->name);
tb_a11y_set_states(t, nm, TB_A11Y_EDITABLE | (F->confirm ? 0 : TB_A11Y_FOCUSED | TB_A11Y_EDITING));
float r2 = L->row2_y;
if (F->filter[0])
tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_CHECKBOX, "Todos os arquivos", L->chk_all_x, r2, 180, FD_BTN_H),
F->all_files ? TB_A11Y_CHECKED : 0);
tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_CHECKBOX, "Mostrar ocultos", L->chk_hid_x, r2, 170, FD_BTN_H),
F->show_hidden ? TB_A11Y_CHECKED : 0);
fd_ax_click(t, TB_A11Y_BUTTON, "Cancelar", L->cancel_x, L->row2_y, FD_BTN_W, FD_BTN_H);
fd_ax_click(t, TB_A11Y_BUTTON, F->ok_label, L->ok_x, L->row2_y, FD_BTN_W, FD_BTN_H);
if (F->confirm) {
float bx, by, bw, bh;
fd_confirm_geom(L, &bx, &by, &bw, &bh);
tb_a11y_set_states(t, tb_a11y_push(t, TB_A11Y_DIALOG, "Substituir arquivo", bx, by, bw, bh), TB_A11Y_MODAL);
const char* b = strrchr(F->name, '/');
snprintf(buf, sizeof(buf), "\"%s\" já existe. Deseja substituir o arquivo?", b ? b + 1 : F->name);
tb_a11y_add(t, TB_A11Y_LABEL, buf, bx + 20, by + 20, bw - 40, 50);
float yb = by + bh - FD_BTN_H - 16;
float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W;
fd_ax_click(t, TB_A11Y_BUTTON, "Cancelar", xc, yb, FD_BTN_W, FD_BTN_H);
fd_ax_click(t, TB_A11Y_BUTTON, "Substituir", xo, yb, FD_BTN_W, FD_BTN_H);
tb_a11y_pop(t);
}
tb_a11y_pop(t);
}
void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
FileDlg* F = &ed->fdlg;
if (!F->open) return;
FdL L;
fd_layout(ed, &L);
fd_ax(ed, &L);
float mx = ed->mouse_x, my = ed->mouse_y;
bool modal_free = !F->confirm;
char buf[512];
@@ -16,7 +16,8 @@ CFLAGS := -std=c11 -Wall -Wextra -pedantic \
-I../../../tinyblocks-environ/include \
-I../../../tinyblocks-api/include \
-I../../../tinyblocks-libman/include \
-I../../../tinyblocks-syntax/include
-I../../../tinyblocks-syntax/include \
-I../../../tinyblocks-a11y/include
OBJS := $(BUILD)/tb_editor_image.o
LIB_A := $(BUILD)/libtinyblocks-editor-image.a
@@ -29,6 +30,7 @@ shared: $(LIB_SO)
$(BUILD)/tb_editor_image.o: src/tb_editor_image.c include/tb_editor_image.h \
../../include/tb_editor_internal.h \
../../../tinyblocks-a11y/include/tb_a11y.h \
../tinyblocks-editor-widgets/include/tb_editor_widgets.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -fPIC -c $< -o $@
@@ -10,6 +10,7 @@
* editor ficam pendentes e sao resolvidos na carga.
*/
#include <tb_editor_internal.h>
#include <tb_a11y.h>
#include "tb_editor_image.h"
/* Helpers internos desta library (definidos mais abaixo) */
@@ -673,9 +674,127 @@ static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, fl
}
/* Render --- */
/* Nomes das cores da paleta rapida (para o narrador) */
static const char* IMG_PALETTE_NAME[12] = {
"Preto", "Branco", "Vermelho", "Laranja", "Amarelo", "Verde",
"Azul-claro", "Azul", "Roxo", "Rosa", "Marrom", "Cinza"
};
static int img_ax_click(TinyBlocks_A11yTree* t, TinyBlocks_A11yRole r, const char* name,
float x, float y, float w, float h) {
int n = tb_a11y_add(t, r, name, x, y, w, h);
tb_a11y_set_actions(t, n, TB_A11Y_ACT_ACTIVATE);
return n;
}
/* A aba de imagem na arvore acessivel: ferramentas, arquivo, folha, rodape,
* cores e camadas. A folha aceita arrastar (pintar) sobre ela mesma. */
static void img_ax(Ed* ed, Tab* T) {
TinyBlocks_A11yTree* t = ed_ax(ed);
if (!t) return;
char buf[160];
tb_a11y_push(t, TB_A11Y_TOOLBAR, "Ferramentas", WS_X, WS_Y, IMG_TOOL_W, WS_H);
for (int i = 0; i < IT_N; i++) {
float bx, by;
img_tool_rect(ed, i, &bx, &by);
tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_RADIO, img_tool_tip(i), bx, by, IMG_TH, IMG_TH),
T->img_tool == i ? TB_A11Y_CHECKED : 0);
}
tb_a11y_pop(t);
{
float bx = WS_X + IMG_TOOL_W + 10;
tb_a11y_push(t, TB_A11Y_TOOLBAR, "Arquivo", WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H);
img_ax_click(t, TB_A11Y_BUTTON, "Abrir", bx, WS_Y + 5, 62, 24);
img_ax_click(t, TB_A11Y_BUTTON, "Salvar", bx + 70, WS_Y + 5, 62, 24);
tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Arquivo", bx + 144, WS_Y + 5, 200, 24),
T->img_path[0] ? T->img_path : "sem arquivo");
tb_a11y_pop(t);
}
{
float dx, dy, dw, dh;
img_view(ed, T, &dx, &dy, &dw, &dh);
int f = tb_a11y_push(t, TB_A11Y_CANVAS, "Folha", dx, dy, dw, dh);
snprintf(buf, sizeof(buf), "%d x %d, %s", T->img_w, T->img_h, img_tool_tip(T->img_tool));
tb_a11y_set_value(t, f, buf);
tb_a11y_set_actions(t, f, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_DRAG | TB_A11Y_ACT_DROP);
if (T->img_sel.on) {
ImgSel* S = &T->img_sel;
float sx = dx + S->x * T->img_zoom, sy = dy + S->y * T->img_zoom;
tb_a11y_add(t, TB_A11Y_GROUP, "Seleção", sx, sy, S->w * T->img_zoom, S->h * T->img_zoom);
img_ax_click(t, TB_A11Y_BUTTON, "Excluir seleção", sx + S->w * T->img_zoom - 20.f, sy + 2.f, 18, 18);
}
tb_a11y_pop(t);
}
{
static const char* labels[2] = { "Desfazer", "Limpar" };
for (int i = 0; i < 2; i++) {
float bx, by, bw, bh;
img_foot_btn(ed, i, &bx, &by, &bw, &bh);
tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_BUTTON, labels[i], bx, by, bw, bh),
i == 0 && T->img_undo_n == 0 ? TB_A11Y_DISABLED : 0);
}
float sx, sy, sw, sh;
img_zoom_slider(ed, &sx, &sy, &sw, &sh);
snprintf(buf, sizeof(buf), "%d%%", (int)(T->img_zoom * 100.f + 0.5f));
tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Zoom", sx, sy - 10, sw, sh + 20), buf);
}
{
float px = img_color_x(ed);
tb_a11y_push(t, TB_A11Y_GROUP, "Cores", px, WS_Y, IMG_RIGHT_W, img_layers_title_y(ed) - 14 - WS_Y);
snprintf(buf, sizeof(buf), "#%02X%02X%02X", T->img_rgb[0], T->img_rgb[1], T->img_rgb[2]);
tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Cor atual", px + IMG_RIGHT_W - 44, WS_Y + 5, 30, 30), buf);
float cx, cy, ro, ri;
img_wheel_rect(ed, &cx, &cy, &ro, &ri);
snprintf(buf, sizeof(buf), "%.0f graus", T->img_hue);
int wh = tb_a11y_add(t, TB_A11Y_CANVAS, "Matiz", cx - ro, cy - ro, 2 * ro, 2 * ro);
tb_a11y_set_value(t, wh, buf);
tb_a11y_set_point(t, wh, cx + (ri + ro) * 0.5f, cy);
float qx, qy, qw, qh;
img_sv_rect(ed, &qx, &qy, &qw, &qh);
snprintf(buf, sizeof(buf), "saturação %.0f%%, valor %.0f%%", T->img_sat * 100.f, T->img_val * 100.f);
tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_CANVAS, "Saturação e valor", qx, qy, qw, qh), buf);
tb_a11y_push(t, TB_A11Y_LIST, "Paleta de cores", px, img_pal_y(ed), IMG_RIGHT_W, 4 * 30);
for (int i = 0; i < 12; i++) {
float sx, sy;
img_swatch_rect(ed, i, &sx, &sy);
tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_RADIO, IMG_PALETTE_NAME[i], sx, sy, 34, 22),
i == T->img_swatch ? TB_A11Y_CHECKED : 0);
}
tb_a11y_pop(t);
tb_a11y_pop(t);
}
{
float px = img_color_x(ed);
tb_a11y_push(t, TB_A11Y_LIST, "Camadas", px, img_layers_title_y(ed), IMG_RIGHT_W,
WS_Y + WS_H - img_layers_title_y(ed));
for (int i = 0; i < T->img_layer_n; i++) {
float rx, ry, rw, rh;
img_layer_row(ed, i, &rx, &ry, &rw, &rh);
int it = tb_a11y_push(t, TB_A11Y_LIST_ITEM, T->img_layers[i].name[0] ? T->img_layers[i].name : "camada",
rx, ry, rw, rh);
tb_a11y_set_point(t, it, rx + rw * 0.6f, ry + rh * 0.5f);
tb_a11y_set_actions(t, it, TB_A11Y_ACT_ACTIVATE);
tb_a11y_set_value(t, it, T->img_layers[i].kind == IMG_L_VECTOR ? "vetor" : "raster");
tb_a11y_set_states(t, it, i == T->img_layer_cur ? TB_A11Y_SELECTED : 0);
tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_CHECKBOX, "Visível", rx + 5, ry + rh * 0.5f - 6, 12, 12),
T->img_layers[i].visible ? TB_A11Y_CHECKED : 0);
tb_a11y_pop(t);
}
static const char* labels[3] = { "Excluir camada", "Nova camada raster", "Nova camada vetorial" };
for (int i = 0; i < 3; i++) {
float bx2, by2, bw2, bh2;
img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2);
tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_BUTTON, labels[i], bx2, by2, bw2, bh2),
i == 0 && T->img_layer_n <= 1 ? TB_A11Y_DISABLED : 0);
}
tb_a11y_pop(t);
}
}
void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
Tab* T = &CT;
img_ensure(ed, T);
img_ax(ed, T);
rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG);