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:
mguinhosandClaude Opus 5.5 committed 2026-10-23 07:24:19 -03:00
1 parent 80bd330766
commit 600c4fc520
12 files changed
+1557 -103

No files matched your search

+470 -33
View File
@@ -47,6 +47,7 @@
#include <tb_scratchblocks.h>
#include <strings.h>
#include <tb_stage_widget.h>
#include <tb_a11y.h>
#include "../include/tb_editor.h"
@@ -877,6 +878,145 @@ static void draw_slot(TinyBlocks_RenderableBlock* rb, const EdBlock* b, int s,
if (editing) rb_fill_rect(rb, end_x + 1, ly - SLOT_LINE_H - 7, 1.5f, 14, txt);
}
/* == Acessibilidade (tb_a11y.h) ===
* Como os widgets do GTK implementam GtkAccessible, cada parte da tela se
* descreve na arvore acessivel no mesmo lugar em que se desenha: papel,
* nome, valor, estados, acoes e retangulo. A arvore serve ao narrador (por
* uma ponte) e aos testes (acham componentes por papel + nome). So o
* desenho da janela principal monta a arvore (ed->ax_on). */
static TinyBlocks_A11yTree* ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; }
static int ax_push(Ed* ed, TinyBlocks_A11yRole r, const char* name, float x, float y, float w, float h) {
return tb_a11y_push(ax(ed), r, name, x, y, w, h);
}
static int ax_add(Ed* ed, TinyBlocks_A11yRole r, const char* name, float x, float y, float w, float h) {
return tb_a11y_add(ax(ed), r, name, x, y, w, h);
}
static void ax_pop(Ed* ed) { tb_a11y_pop(ax(ed)); }
/* Componente que se ativa com um clique (botao, aba, item de menu...) */
static int ax_click(Ed* ed, TinyBlocks_A11yRole r, const char* name, float x, float y, float w, float h) {
int n = ax_add(ed, r, name, x, y, w, h);
tb_a11y_set_actions(ax(ed), n, TB_A11Y_ACT_ACTIVATE);
return n;
}
static int ax_button(Ed* ed, const char* name, float x, float y, float w, float h) {
return ax_click(ed, TB_A11Y_BUTTON, name, x, y, w, h);
}
/* Campo de texto; `editing` = recebe o teclado agora */
static int ax_field(Ed* ed, const char* name, const char* value, bool editing,
float x, float y, float w, float h) {
int n = ax_add(ed, TB_A11Y_TEXT_FIELD, name, x, y, w, h);
tb_a11y_set_value(ax(ed), n, value);
tb_a11y_set_actions(ax(ed), n, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_EDIT);
tb_a11y_set_states(ax(ed), n, TB_A11Y_EDITABLE | (editing ? TB_A11Y_FOCUSED | TB_A11Y_EDITING : 0));
return n;
}
static void ax_cat(char* out, size_t cap, size_t* len, const char* s) {
if (!s[0] || *len + 1 >= cap) return;
int w = snprintf(out + *len, cap - *len, "%s%s", *len ? " " : "", s);
if (w > 0) *len = *len + (size_t)w < cap ? *len + (size_t)w : cap - 1;
}
/* Rotulo falado de um bloco, com o que esta nos campos:
* "repita (10) vezes", "se <(x) > (5)> então", "defina desenhe (x)" */
static void ax_block_label(Tab* T, int bi, char* out, size_t cap, int depth) {
EdBlock* b = &T->ws[bi];
size_t len = 0;
out[0] = 0;
for (int i = 0; i < b->part_n; i++) {
const Part* p = &b->parts[i];
char piece[192], buf[96];
piece[0] = 0;
if (p->arg == PART_PROTO) {
ProtoLayout L;
proto_layout(b, &L);
size_t m = 0;
for (int k = 0; k < L.n; k++) {
char it[80];
snprintf(it, sizeof(it), L.param[k] ? "(%.60s)" : "%.60s", L.txt[k]);
ax_cat(piece, sizeof(piece), &m, it);
}
} else if (p->arg < 0) {
snprintf(piece, sizeof(piece), "%s", part_str(p, buf, sizeof(buf)));
} else {
bool bl = slot_is_bool(b->type, p->arg);
if (b->args[p->arg] >= 0 && depth < 4) {
char sub[160];
ax_block_label(T, b->args[p->arg], sub, sizeof(sub), depth + 1);
snprintf(piece, sizeof(piece), bl ? "<%.150s>" : "(%.150s)", sub);
} else {
snprintf(piece, sizeof(piece), bl ? "<>" : "(%.150s)", slot_src(b, p->arg));
}
}
ax_cat(out, cap, &len, piece);
}
}
static void ax_chain(Ed* ed, Tab* T, int head, float ox, float oy, uint32_t acts);
/* Um bloco: no BLOCK com os campos (TEXT_FIELD / SLOT), os reporteres
* encaixados, os parametros do "defina" e as bocas (GROUP com a pilha) */
static void ax_block(Ed* ed, Tab* T, int bi, float ox, float oy, uint32_t acts) {
TinyBlocks_A11yTree* t = ax(ed);
if (!t) return;
EdBlock* b = &T->ws[bi];
char label[TB_A11Y_NAME_MAX];
ax_block_label(T, bi, label, sizeof(label), 0);
float x = b->ax + ox, y = b->ay + oy;
int n = tb_a11y_push(t, TB_A11Y_BLOCK, label, x, y, b->w, b->h);
tb_a11y_set_key(t, n, b->type_name); /* o id nao muda ao editar */
tb_a11y_set_point(t, n, x + fminf(8.f, b->w * 0.5f), y + b->row_y + b->row_h * 0.5f);
tb_a11y_set_actions(t, n, acts);
if (T == &CT && (x + b->w < WS_X || x > WS_X + WS_W || y + b->h < WS_Y || y > WS_Y + WS_H))
tb_a11y_add_states(t, n, TB_A11Y_OFFSCREEN); /* existe, mas a aba esta rolada */
const TinyBlocks_BlockMeta* meta = tb_meta_find(b->type_name);
if (meta && meta->doc) tb_a11y_set_description(t, n, meta->doc);
float cy = y + b->row_y + b->row_h * 0.5f;
for (int i = 0; i < b->part_n; i++) {
const Part* p = &b->parts[i];
if (p->arg == PART_PROTO) { /* parametros arrastaveis */
ProtoLayout L;
proto_layout(b, &L);
for (int k = 0; k < L.n; k++) {
if (!L.param[k]) continue;
int q = tb_a11y_add(t, TB_A11Y_BLOCK, L.txt[k], x + p->x + L.x[k], cy - PILL_H * 0.5f,
L.w[k], PILL_H);
tb_a11y_set_description(t, q, "parâmetro: arraste para usar no corpo");
tb_a11y_set_actions(t, q, TB_A11Y_ACT_DRAG);
}
continue;
}
if (p->arg < 0) continue;
int s = p->arg;
if (b->args[s] >= 0) { ax_block(ed, T, b->args[s], ox, oy, acts); continue; }
const char* sname = b->type->input_descs[s].name ? b->type->input_descs[s].name : "";
float sx = x + b->slot_x[s], sy = y + b->slot_y[s];
if (slot_is_bool(b->type, s)) {
int q = tb_a11y_add(t, TB_A11Y_SLOT, sname, sx, sy, b->slot_w[s], b->slot_h[s]);
tb_a11y_set_actions(t, q, TB_A11Y_ACT_DROP);
} else {
bool editing = ed->editing && T == &CT && ed->edit_bi == bi && ed->edit_in == s;
int q = ax_field(ed, sname, slot_src(b, s), editing, sx, sy, b->slot_w[s], b->slot_h[s]);
tb_a11y_set_actions(t, q, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_EDIT | TB_A11Y_ACT_DROP);
}
}
for (int k = 0; k < shape_mouths(shape_of(b->type)); k++) {
const char* mn = k == 0 ? "dentro" : mouth_label(b->type, k - 1);
tb_a11y_push(t, TB_A11Y_GROUP, mn, x + ARM_W, y + b->sub_y[k], b->w - ARM_W, b->sub_h[k]);
if (b->sub[k] >= 0) ax_chain(ed, T, b->sub[k], ox, oy, acts);
tb_a11y_pop(t);
}
tb_a11y_pop(t);
}
static void ax_chain(Ed* ed, Tab* T, int head, float ox, float oy, uint32_t acts) {
for (int c = head; c >= 0; c = T->ws[c].next) ax_block(ed, T, c, ox, oy, acts);
}
static void render_chain(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int head, float ox, float oy);
static void render_block(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int bi, float ox, float oy) {
@@ -1870,7 +2010,7 @@ static void lay_default(Ed* ed) {
ed->lay_root = lay_node(ed, LN_HSPLIT, pal, mid, -1, 0, PALETTE_W);
}
/* -- Layout salvo nas configuracoes (chave "editor.layout") ---------------
/* -- Layout salvo nas configuracoes (chave "editor.layout") ---
* Texto curto: folha = letra da view (p paleta, s scripts, t palco,
* o saida); divisao = H|V<lado fixo>:<px>(a,b). O padrao e
* "H0:318(p,H1:360(s,V0:310(t,o)))". */
@@ -2018,7 +2158,7 @@ static void lay_place(Ed* ed, int n, float x, float y, float w, float h) {
else { lay_place(ed, N->a, x, y, w, sa); lay_place(ed, N->b, x, y + sa, w, h - sa); }
}
/* Abas destacadas -------------------------------------------------------- */
/* Abas destacadas --- */
static bool tab_detached(Ed* ed, int i) {
for (int k = 0; k < TABWIN_MAX; k++) if (ed->twin[k].win && ed->twin[k].tab == i) return true;
return false;
@@ -2914,7 +3054,7 @@ static bool sb_import_text(Ed* ed, const char* text, const char* name) {
return true;
}
/* -- Previa da exportacao: o texto que vai para o forum ----------------- */
/* -- Previa da exportacao: o texto que vai para o forum --- */
#define SBP_HEAD_H 46
#define SBP_FOOT_H 58
#define SBP_LINE_H 19
@@ -2988,11 +3128,13 @@ static void sbp_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
char title[96];
snprintf(title, sizeof(title), "Prévia scratchblocks - %s", CT.name);
rb_text_c(rb, x + 18, y + SBP_HEAD_H * 0.5f, title, COL_WHITE, 17);
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, title, x, y, w, h), TB_A11Y_MODAL);
/* texto, numa area escura como a aba de codigo */
float cx = x + 14, cy = y + SBP_HEAD_H + 12, cw = w - 28, ch = h - SBP_HEAD_H - SBP_FOOT_H - 18;
rb_fill_rrect(rb, cx, cy, cw, ch, 8, COLA(30, 30, 30, 255));
clip_set(ed, rb, cx + 4, cy + 4, cw - 8, ch - 8);
tb_a11y_set_value(ax(ed), ax_add(ed, TB_A11Y_TEXT_FIELD, "scratchblocks", cx, cy, cw, ch), ed->sbp_text);
int total = sbp_lines(ed->sbp_text);
int visible = (int)((ch - 16) / SBP_LINE_H);
if (ed->sbp_scroll > total - visible) ed->sbp_scroll = total - visible;
@@ -3033,7 +3175,9 @@ static void sbp_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float bx, by, bw;
sbp_button_pos(ed, i, &bx, &by, &bw);
sbp_button(rb, bx, by, bw, labels[i], i == 0, in_rect(ed->mouse_x, ed->mouse_y, bx, by, bw, 34));
ax_button(ed, labels[i], bx, by, bw, 34);
}
ax_pop(ed);
}
static void sbp_copy(Ed* ed) {
@@ -3281,6 +3425,8 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rect(rb, dx, dy + DLG_HEAD_H - 12, DLG_W, 12, accent);
const char* title = ed->comp_dialog_def >= 0 ? "Editar Bloco" : "Criar um Bloco";
rb_text_c(rb, dx + (DLG_W - tw(title, 18)) * 0.5f, dy + DLG_HEAD_H * 0.5f, title, COL_WHITE, 18);
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, title, dx, dy, DLG_W, DLG_H), TB_A11Y_MODAL);
ax_button(ed, "Fechar", dx + DLG_W - 44, dy, 44, DLG_HEAD_H);
{ /* fechar: um X desenhado */
float qx = dx + DLG_W - 26, qy = dy + DLG_HEAD_H * 0.5f;
rb_fill_circle(rb, qx, qy, 12, COLA(255, 255, 255, 60));
@@ -3306,6 +3452,9 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
ed->comp_dialog_name[0] ? COL_TEXT : COL_TEXT_DIM, FS);
if (ed->comp_dialog_editing && ed->comp_dialog_edit_part < 0)
rb_fill_rect(rb, nfx + (nfw + lw) * 0.5f + 2, nfy + 4, 1.5f, nfh - 8, COL_TEXT);
ax_push(ed, TB_A11Y_BLOCK, "Protótipo", bx, by, bw, bh);
ax_field(ed, "Nome do bloco", ed->comp_dialog_name,
ed->comp_dialog_editing && ed->comp_dialog_edit_part < 0, nfx, nfy, nfw, nfh);
}
/* Partes do protótipo */
@@ -3329,15 +3478,27 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
p->name[0] ? COL_TEXT : COL_TEXT_DIM, FS);
}
if (sel) rb_stroke_rect(rb, px - 2, py - 2, pw + 4, ph + 4, 2, COL_TEXT);
{ /* cada parte: campo com o nome da entrada (ou do rotulo) */
const char* kind = p->kind == PARAM_LABEL ? "Rótulo" : p->kind == PARAM_BOOL ? "Entrada booleana"
: "Entrada";
bool ed_here = ed->comp_dialog_editing && ed->comp_dialog_edit_part == i;
int an = ax_field(ed, kind, p->name, ed_here, px, py, pw, ph);
if (sel) tb_a11y_add_states(ax(ed), an, TB_A11Y_SELECTED);
}
if (ed->comp_dialog_editing && ed->comp_dialog_edit_part == i && p->kind != PARAM_LABEL) {
float lw = tw(label, FS);
rb_fill_rect(rb, px + (pw + lw) * 0.5f + 2, py + 5, 1.5f, ph - 10, COL_TEXT);
}
}
ax_pop(ed); /* prototipo */
/* Controles - apagar - da parte selecionada */
if (ed->comp_dialog_sel >= 0) {
float ctr = bx + bw * 0.5f, cty = by - 26;
ax_button(ed, "Mover para a esquerda", ctr - 60, cty - 16, 34, 32);
ax_button(ed, "Apagar a parte", ctr - 16, cty - 16, 32, 32);
ax_button(ed, "Mover para a direita", ctr + 26, cty - 16, 34, 32);
/* setas: mover a parte para a esquerda/direita */
rb_line(rb, ctr - 38, cty - 6, ctr - 44, cty, 2.f, COL_TEXT);
rb_line(rb, ctr - 44, cty, ctr - 38, cty + 6, 2.f, COL_TEXT);
@@ -3360,6 +3521,11 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
for (int i = 0; i < 3; i++) {
float cx = cx0 + i * (cw + 16.f);
bool hover = in_rect(ed->mouse_x, ed->mouse_y, cx, cy0, cw, ch);
{
static const char* names[3] = { "Adicionar entrada de número ou texto",
"Adicionar entrada booleana", "Adicionar rótulo" };
ax_button(ed, names[i], cx, cy0, cw, ch);
}
rb_fill_rrect(rb, cx, cy0, cw, ch, 8, hover ? COL_HOVER : COL_PANEL);
rb_stroke_rect(rb, cx + 0.5f, cy0 + 0.5f, cw - 1, ch - 1, 1, hover ? COL_MENU : COL_BORDER);
float iy = cy0 + 14.f;
@@ -3383,12 +3549,19 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float sx = dx + 28.f + ci * 30.f;
if (ed->comp_dialog_color == ci) rb_fill_rrect(rb, sx - 2, fy - 2, 26, 26, 6, COL_TEXT);
rb_fill_rrect(rb, sx, fy, 22, 22, 5, s_user_colors[ci]);
char cn[16];
snprintf(cn, sizeof(cn), "Cor %d", ci + 1);
tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_RADIO, cn, sx, fy, 22, 22),
ed->comp_dialog_color == ci ? TB_A11Y_CHECKED : 0);
}
float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f;
rb_fill_rrect(rb, cax, fy - 8, 84, 36, 8, COL_BORDER);
rb_text_c(rb, cax + (84 - tw("Cancelar", FS_UI)) * 0.5f, fy + 10, "Cancelar", COL_TEXT, FS_UI);
rb_fill_rrect(rb, okx, fy - 8, 84, 36, 8, accent);
rb_text_c(rb, okx + (84 - tw("OK", FS_UI)) * 0.5f, fy + 10, "OK", COL_WHITE, FS_UI);
ax_button(ed, "Cancelar", cax, fy - 8, 84, 36);
ax_button(ed, "OK", okx, fy - 8, 84, 36);
ax_pop(ed);
}
bool dlg_click(Ed* ed, float mx, float my) {
@@ -3512,6 +3685,13 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
menu_button(rb, EXP_BTN_X, EXP_BTN_W, "Exportar", (ed->ctx_menu_open && ed->ctx_export) || hit_export_btn(mx, my));
menu_button(rb, LIBM_BTN_X, LIBM_BTN_W, "Bibliotecas", ed->libman_open || hit_libman_btn(mx, my));
menu_button(rb, CFG_BTN_X, CFG_BTN_W, "Config", ed->settings_open || hit_settings_btn(ed, mx, my));
ax_push(ed, TB_A11Y_TOOLBAR, "Menu", 0, 0, WIN_W, MENU_H);
ax_button(ed, "Abrir", OPEN_BTN_X, 7, OPEN_BTN_W, MENU_H - 14);
ax_button(ed, "Salvar", SAVE_BTN_X, 7, SAVE_BTN_W, MENU_H - 14);
tb_a11y_set_states(ax(ed), ax_button(ed, "Exportar", EXP_BTN_X, 7, EXP_BTN_W, MENU_H - 14),
ed->ctx_menu_open && ed->ctx_export ? TB_A11Y_EXPANDED : 0);
ax_button(ed, "Bibliotecas", LIBM_BTN_X, 7, LIBM_BTN_W, MENU_H - 14);
ax_button(ed, "Config", CFG_BTN_X, 7, CFG_BTN_W, MENU_H - 14);
/* views destacadas: um botao para cada (clicar recolhe de volta) */
float cx = CFG_BTN_X - 10;
for (int v = V_COUNT - 1; v >= 0; v--) {
@@ -3525,6 +3705,8 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rrect(rb, cx, 7, w, MENU_H - 14, 6, hov ? COL_MENU_DARK : COLA(255, 255, 255, 34));
draw_window_icon(rb, cx + 2, 7 + (MENU_H - 14 - 22) * 0.5f, 22, true, COL_WHITE);
rb_text_c(rb, cx + 30, MENU_H * 0.5f, nm, COL_WHITE, FS_UI);
tb_a11y_set_description(ax(ed), ax_button(ed, nm, cx, 7, w, MENU_H - 14),
"janela destacada: ative para recolher");
cx -= 8;
}
for (int k = TABWIN_MAX - 1; k >= 0; k--) { /* abas destacadas */
@@ -3539,12 +3721,15 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rrect(rb, cx, 7, w, MENU_H - 14, 6, hov ? COL_MENU_DARK : COLA(255, 255, 255, 34));
draw_window_icon(rb, cx + 2, 7 + (MENU_H - 14 - 22) * 0.5f, 22, true, COL_WHITE);
rb_text_c(rb, cx + 30, MENU_H * 0.5f, nm, COL_WHITE, FS_UI);
tb_a11y_set_description(ax(ed), ax_button(ed, nm, cx, 7, w, MENU_H - 14),
"aba destacada: ative para recolher");
cx -= 8;
}
if (ed->lib_hover || (active && ed->path_mode == PM_LIB))
rb_fill_rect(rb, LIB_BTN_X, 0, LIB_BTN_W, MENU_H, COL_MENU_DARK);
rb_text_c(rb, LIB_BTN_X + 14, MENU_H*0.5f, "Carregar library...", COL_WHITE, FS_UI);
ax_button(ed, "Carregar library...", LIB_BTN_X, 0, LIB_BTN_W, MENU_H);
if (ed->path_input_active) {
float bx = LIB_BTN_X + LIB_BTN_W + 10, bw = WIN_W - bx - 16;
@@ -3560,7 +3745,9 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_text_c(rb, bx + 10, MENU_H*0.5f, t, ed->path_input_buf[0] ? COL_TEXT : COL_TEXT_DIM, FS_UI);
float cw = tw(ed->path_input_buf, FS_UI);
rb_fill_rect(rb, bx + 11 + cw, MENU_H*0.5f - 8, 1.5f, 16, COL_TEXT);
ax_field(ed, prompt, ed->path_input_buf, true, bx, 7, bw, MENU_H - 14);
}
ax_pop(ed);
}
/* == Notificacoes flutuantes (toasts) ===
@@ -3697,6 +3884,10 @@ static void render_toasts(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_line(rb, cx - 4, cy - 4, cx + 4, cy + 4, 1.6f, xh ? txt : dim);
rb_line(rb, cx + 4, cy - 4, cx - 4, cy + 4, 1.6f, xh ? txt : dim);
/* temporizador: barra que encolhe (para com o mouse em cima) */
int an = ax_push(ed, TB_A11Y_STATUS, t->text, t->x, t->y, w, h);
tb_a11y_set_description(ax(ed), an, t->ok ? "aviso" : "erro");
ax_button(ed, "Fechar aviso", cx - 11, cy - 11, 22, 22);
ax_pop(ed);
float k = t->total_ms > 0 ? fmaxf(0.f, t->left_ms / t->total_ms) : 0.f;
Col tb = bar;
if (hov) tb.a *= 0.45f;
@@ -3724,6 +3915,7 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rect(rb, x0, y0, WS_W, TAB_H, COL_UI_BG);
int dragged = ed->tab_drag ? ed->tab_press : -1;
int vis[MAX_TABS], vn = tabs_visible_list(ed, vis);
ax_push(ed, TB_A11Y_TAB_LIST, "Abas", x0, y0, wbar, TAB_H);
for (int pass = 0; pass < 2; pass++) /* 2a passada: a aba arrastada, por cima */
for (int sl = 0; sl < vn; sl++) {
int i = vis[sl];
@@ -3748,18 +3940,28 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) {
lx = tx + 24;
}
rb_text_c(rb, lx, cy, ed->tabs[i].name, cur ? COL_MENU : COL_TEXT, FS_UI);
int an = ax_push(ed, TB_A11Y_TAB, ed->tabs[i].name, tx, y0 + 6, TAB_W - 4, TAB_H - 6);
tb_a11y_set_point(ax(ed), an, tx + 14, cy);
tb_a11y_set_states(ax(ed), an, cur ? TB_A11Y_SELECTED : 0);
tb_a11y_set_actions(ax(ed), an, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_MENU | TB_A11Y_ACT_DRAG);
tb_a11y_set_description(ax(ed), an, tab_class(&ed->tabs[i])->name);
if (ed->tab_n > 1 && ed->tabctx < 0) { /* fechar: um X desenhado */
float qx = tx + TAB_W - 18;
rb_line(rb, qx - 3.5f, cy - 3.5f, qx + 3.5f, cy + 3.5f, 1.5f, COL_TEXT_DIM);
rb_line(rb, qx + 3.5f, cy - 3.5f, qx - 3.5f, cy + 3.5f, 1.5f, COL_TEXT_DIM);
ax_button(ed, "Fechar aba", tx + TAB_W - 28, y0 + 6, 24, TAB_H - 6);
}
ax_pop(ed);
}
float px = WS_X + 8 + vn*TAB_W;
if (ed->tabctx < 0 && px + PLUS_W <= x0 + wbar && ed->tab_n < MAX_TABS) {
float pcy = y0 + 6 + (TAB_H-6)*0.5f;
if (ed->plus_menu_open) rb_fill_circle(rb, px+13, pcy, 12, COL_HOVER);
rb_text_c(rb, px+8, pcy, "+", ed->plus_menu_open ? COL_MENU : COL_TEXT, 18);
tb_a11y_set_states(ax(ed), ax_button(ed, "Nova aba", px, y0, PLUS_W, TAB_H),
ed->plus_menu_open ? TB_A11Y_EXPANDED : 0);
}
ax_pop(ed);
if (ed->tabctx < 0) draw_grip(ed, rb, V_SCRIPTS); /* na janela de uma aba nao ha area para mover */
}
@@ -3786,11 +3988,16 @@ static void render_categories(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_circle(rb, mid, cy, r - 1, ed->cats[c].col);
float w = tw(ed->cats[c].name, fs);
rb_text_c(rb, mid - w*0.5f, iy + ih*0.78f, ed->cats[c].name, COL_TEXT, fs);
if (c == 0) ax_push(ed, TB_A11Y_TAB_LIST, "Categorias", PAL_X, PAL_Y, CAT_W, PAL_B - PAL_Y);
tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_TAB, ed->cats[c].name, PAL_X, iy, CAT_W - 1, ih),
c == cur ? TB_A11Y_SELECTED : 0);
if (c == ed->cat_n - 1) ax_pop(ed);
}
/* Botao de buscar/adicionar library, no fim do painel (como o Scratch) */
float by = PAL_B - LIBMAN_BTN_H;
bool hov = hit_libman_foot(ed, ed->mouse_x, ed->mouse_y);
rb_fill_rect(rb, PAL_X, by, CAT_W-1, LIBMAN_BTN_H, hov ? COL_LIBBTN_DARK : COL_LIBBTN);
ax_button(ed, "Adicionar extensão", PAL_X, by, CAT_W - 1, LIBMAN_BTN_H);
float cx = mid, cy = by + LIBMAN_BTN_H*0.5f;
for (int i = 0; i < 3; i++) /* livrinhos */
rb_fill_rect(rb, cx-14, cy-6 + i*5, 16, 3, COL_WHITE);
@@ -3804,9 +4011,26 @@ static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_line(rb, FLY_R-1, PAL_Y, FLY_R-1, PAL_B, 1.f, COL_BORDER);
clip_set(ed, rb, FLY_X, PAL_Y, FLY_R - FLY_X - 1, PAL_B-PAL_Y);
float oy = PAL_Y - ed->fly_scroll;
ax_push(ed, TB_A11Y_LIST, "Paleta", FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B - PAL_Y);
bool ax_grp = false;
for (int i = 0; i < ed->fly_n; i++) {
FlyItem* it = &ed->fly_items[i];
float iy = it->y + oy;
if (ax(ed)) { /* a arvore tem a paleta toda; o que esta fora fica OFFSCREEN */
uint32_t off = (iy + it->h < PAL_Y || iy > PAL_B) ? TB_A11Y_OFFSCREEN : 0;
if (it->kind == FI_HEADER) {
if (ax_grp) ax_pop(ed);
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_GROUP, ed->cats[it->cat].name,
FLY_X, iy, FLY_R - FLY_X, it->h), off);
ax_grp = true;
} else if (it->kind == FI_BUTTON) {
tb_a11y_set_states(ax(ed), ax_button(ed, "Criar um Bloco", FLY_X + FLY_PAD, iy + 4, FLY_BTN_W, 30), off);
} else {
int before = tb_a11y_count(ax(ed));
ax_block(ed, &ed->fly, it->bi, FLY_X, oy, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_DRAG);
if (off) for (int k = before; k < tb_a11y_count(ax(ed)); k++) tb_a11y_add_states(ax(ed), k, off);
}
}
if (iy + it->h < PAL_Y || iy > PAL_B) continue;
switch (it->kind) {
case FI_HEADER:
@@ -3823,6 +4047,8 @@ static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) {
break;
}
}
if (ax_grp) ax_pop(ed);
ax_pop(ed);
clip_clear(ed, rb);
}
@@ -3874,7 +4100,7 @@ static char* decode_entities(const char* s, int n) {
return out;
}
/* -- Buffer de texto da aba de codigo ---------------------------------- */
/* -- Buffer de texto da aba de codigo --- */
static bool code_reserve(Tab* T, int extra) {
if (T->code_len + extra + 1 <= T->code_cap) return true;
int cap = T->code_cap ? T->code_cap : 4096;
@@ -4100,7 +4326,7 @@ void open_code_at(Ed* ed, const char* file, int line) {
if (line > 0) code_scroll_to(ed, T, line);
}
/* -- Render da aba de codigo ------------------------------------------- */
/* -- Render da aba de codigo --- */
void render_code_tab(Ed* ed, TinyBlocks_RenderableBlock* rb) {
Tab* T = &CT;
const float x0 = WS_X, y0 = WS_Y;
@@ -4175,7 +4401,7 @@ void render_code_tab(Ed* ed, TinyBlocks_RenderableBlock* rb) {
(void)ed;
}
/* -- Entrada (mouse/teclado) da aba de codigo -------------------------- */
/* -- Entrada (mouse/teclado) da aba de codigo --- */
bool code_click(Ed* ed, float mx, float my) {
Tab* T = &CT;
const float barh = 30;
@@ -4269,7 +4495,7 @@ bool code_text(Ed* ed, const char* typed) {
}
/* A aba de imagem vive em libraries/tinyblocks-editor-image (bundle do editor). */
/* -- Menu do botao "+" -------------------------------------------------- */
/* -- Menu do botao "+" --- */
static void plus_menu_pos(Ed* ed, float* px, float* py) {
int vis[MAX_TABS];
*px = WS_X + 8 + tabs_visible_list(ed, vis) * TAB_W;
@@ -4291,17 +4517,21 @@ void render_plus_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
"editar SVG/imagem", "editar .c/.py/..." };
static const Col dots[PLUS_MENU_N] = {{0.30f,0.62f,1.f,1.f}, {1.f,0.40f,0.50f,1.f},
{0.98f,0.62f,0.25f,1.f}, {0.42f,0.72f,0.35f,1.f}};
ax_push(ed, TB_A11Y_MENU, "Nova aba", px, py, PLUS_MENU_W, h);
for (int i = 0; i < n; i++) {
float iy = py + 26 + i * PLUS_MENU_ITEM_H;
tb_a11y_set_description(ax(ed), ax_click(ed, TB_A11Y_MENU_ITEM, labels[i], px, iy,
PLUS_MENU_W, PLUS_MENU_ITEM_H), subs[i]);
bool hov = ed->plus_menu_hover == i;
if (hov) rb_fill_rrect(rb, px + 4, iy, PLUS_MENU_W - 8, PLUS_MENU_ITEM_H - 2, 6, COL_HOVER);
rb_fill_circle(rb, px + 20, iy + PLUS_MENU_ITEM_H * 0.5f - 1, 6, dots[i]);
rb_text_c(rb, px + 36, iy + 12, labels[i], COL_TEXT, FS_UI - 1);
rb_text_c(rb, px + 36, iy + 25, subs[i], COL_TEXT_DIM, 10.f);
}
ax_pop(ed);
}
/* -- Tooltip de metadados (Alt + hover) --------------------------------- */
/* -- Tooltip de metadados (Alt + hover) --- */
void render_tooltip(Ed* ed, TinyBlocks_RenderableBlock* rb) {
if (!ed->tip_open) return;
float x = ed->tip_x, y = ed->tip_y, w = ed->tip_w, h = ed->tip_h;
@@ -4395,13 +4625,37 @@ static bool image_tab_icon(TinyBlocks_RenderableBlock* rb, float x, float cy) {
return true;
}
/* Aba de codigo: um campo de texto; o valor e a linha do cursor */
static void code_tab_a11y(Ed* ed) {
const char* txt = CT.code_text ? CT.code_text : "";
int caret = CT.code_caret < 0 ? 0 : CT.code_caret > CT.code_len ? CT.code_len : CT.code_caret;
int st = caret, en = caret, line = 1;
while (st > 0 && txt[st - 1] != '\n') st--;
while (en < CT.code_len && txt[en] != '\n') en++;
for (int i = 0; i < st; i++) if (txt[i] == '\n') line++;
char val[TB_A11Y_VALUE_MAX], desc[TB_A11Y_DESC_MAX];
snprintf(val, sizeof(val), "%.*s", en - st, txt + st);
snprintf(desc, sizeof(desc), "linha %d - %.150s", line, CT.code_path[0] ? CT.code_path : "sem arquivo");
int n = ax_field(ed, "Código", val, true, WS_X, WS_Y, WS_W, WS_H);
tb_a11y_set_description(ax(ed), n, desc);
}
/* Aba de imagem: a tela de desenho, com o tamanho como valor */
static void image_tab_a11y(Ed* ed) {
char val[32];
snprintf(val, sizeof(val), "%d x %d", CT.img_w, CT.img_h);
int n = ax_add(ed, TB_A11Y_CANVAS, "Imagem", WS_X, WS_Y, WS_W, WS_H);
tb_a11y_set_value(ax(ed), n, val);
tb_a11y_set_description(ax(ed), n, CT.img_path[0] ? CT.img_path : "sem arquivo");
}
static const TabClass s_tab_classes[] = {
[TK_BLOCKS] = { "Blocos", true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
[TK_BLOCKS] = { "Blocos", true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
[TK_CODE] = { "Código", false, NULL, render_code_tab, code_tab_click, NULL, NULL,
code_key, code_text, code_tab_scroll, code_tab_icon },
code_key, code_text, code_tab_scroll, code_tab_icon, code_tab_a11y },
[TK_IMAGE] = { "Imagem", false, image_tab_init, image_tab_render, image_tab_click,
image_tab_release, image_tab_motion, image_tab_key, NULL,
image_tab_scroll, image_tab_icon },
image_tab_scroll, image_tab_icon, image_tab_a11y },
};
const TabClass* tab_class(const Tab* T) {
@@ -4534,9 +4788,14 @@ static void group_motion(Ed* ed, float mx, float my) {
layout_tab(T);
}
static void ax_workspace(Ed* ed, float ox, float oy);
static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
const TabClass* tc = tab_class(&CT);
if (tc->render) { tc->render(ed, rb); return; }
int panel = ax_push(ed, TB_A11Y_TAB_PANEL, CT.name, WS_X, WS_Y, WS_W, WS_H);
tb_a11y_set_description(ax(ed), panel, tc->name);
if (tc->a11y) tc->a11y(ed);
if (tc->render) { tc->render(ed, rb); ax_pop(ed); return; }
float ox = WS_X - CT.ws_sx, oy = WS_Y - CT.ws_sy;
rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_WS_BG);
clip_set(ed, rb, WS_X, WS_Y, WS_W, WS_H);
@@ -4562,6 +4821,14 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
render_chain(ed, rb, &CT, CT.top[i], ox, oy);
}
render_snap(ed, rb, ox, oy);
ax_workspace(ed, ox, oy);
if (ed->bubble_bi >= 0 && CT.ws[ed->bubble_bi].used) { /* balao com o valor do reporter */
EdBlock* b = &CT.ws[ed->bubble_bi];
int n = ax_add(ed, TB_A11Y_STATUS, "Resultado", b->ax + ox + 8, b->ay + oy - 44, 120, 38);
tb_a11y_set_value(ax(ed), n, ed->bubble_text);
tb_a11y_set_description(ax(ed), n, ed->bubble_type);
}
ax_pop(ed);
if (ed->bubble_bi >= 0 && CT.ws[ed->bubble_bi].used) {
EdBlock* b = &CT.ws[ed->bubble_bi];
@@ -4637,6 +4904,35 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
clip_clear(ed, rb);
}
/* Grupos coloridos e pilhas da aba de blocos (cada pilha e uma LIST com os
* blocos de cima para baixo; o rotulo do 1o bloco da nome a pilha) */
static void ax_workspace(Ed* ed, float ox, float oy) {
TinyBlocks_A11yTree* t = ax(ed);
if (!t) return;
for (int g = 0; g < CT.group_n; g++) {
WsGroup* G = &CT.groups[g];
int n = tb_a11y_add(t, TB_A11Y_GROUP, G->title[0] ? G->title : "Grupo",
ox + G->x, oy + G->y, G->w, G->h);
tb_a11y_set_key(t, n, "grupo");
tb_a11y_set_point(t, n, ox + G->x + 12, oy + G->y + GRP_HEAD_H * 0.5f);
tb_a11y_set_actions(t, n, TB_A11Y_ACT_DRAG | TB_A11Y_ACT_MENU);
if (ed->grp_edit == g) tb_a11y_set_states(t, n, TB_A11Y_FOCUSED | TB_A11Y_EDITING);
}
for (int i = 0; i < CT.top_n; i++) {
int head = CT.top[i];
if (ed->state == ES_DRAG && head == ed->drag_bi) continue;
float x0, y0, x1, y1;
stack_bounds(&CT, head, &x0, &y0, &x1, &y1);
char label[TB_A11Y_NAME_MAX], name[TB_A11Y_NAME_MAX + 8];
ax_block_label(&CT, head, label, sizeof(label), 0);
snprintf(name, sizeof(name), "Pilha: %s", label);
int n = tb_a11y_push(t, TB_A11Y_LIST, name, x0 + ox, y0 + oy, x1 - x0, y1 - y0);
tb_a11y_set_key(t, n, CT.ws[head].type_name);
ax_chain(ed, &CT, head, ox, oy, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_MENU | TB_A11Y_ACT_DRAG);
tb_a11y_pop(t);
}
}
/* == Barra do bloco composto (canto superior direito do workspace) === */
#define CP_W 440
#define CP_H 44
@@ -4664,6 +4960,10 @@ static void render_comp_panel(Ed* ed, TinyBlocks_RenderableBlock* rb) {
bx -= 96;
rb_fill_rrect(rb, bx, py+8, 88, 28, 6, COL_BORDER);
rb_text_c(rb, bx + (88 - tw("Editar bloco", FS_UI))*0.5f, py+CP_H*0.5f, "Editar bloco", COL_TEXT, FS_UI);
ax_push(ed, TB_A11Y_TOOLBAR, nm, px, py, CP_W, CP_H);
ax_button(ed, "Editar bloco", bx, py + 8, 88, 28);
ax_button(ed, "Salvar", bx + 96, py + 8, 78, 28);
ax_pop(ed);
}
/* Altura da área do palco no painel (4:3 embutido; faixa curta se destacado) */
@@ -4684,12 +4984,15 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) {
draw_hex(rb, tx+10, fy+6, 20, 20, COL_STOP_DARK);
rb_fill_circle(rb, tx+20, fy+16, 9, COL_STOP);
rb_text_c(rb, sx + 110, sy + STAGE_BAR_H*0.5f, "Palco", COL_TEXT_DIM, FS_UI);
tb_a11y_set_states(ax(ed), ax_button(ed, "Executar", fx, fy, 40, 32), ed->vm_running ? TB_A11Y_BUSY : 0);
ax_button(ed, "Parar", tx, fy, 40, 32);
draw_grip(ed, rb, V_STAGE);
/* Destacar / recolher o palco */
if (ed->stage) {
float dx = sx + A.w - 50;
if (ed->detach_hover) rb_fill_rrect(rb, dx, fy, 40, 32, 6, COL_HOVER);
draw_window_icon(rb, dx, fy, 32, A.detached, COL_TEXT);
ax_button(ed, A.detached ? "Recolher o palco" : "Destacar o palco", dx, fy, 40, 32);
}
float bx = sx + 8, by = sy + STAGE_BAR_H, bw = A.w - 16;
@@ -4698,6 +5001,7 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rrect(rb, bx, by, bw, ph, 8, COL_BORDER);
TinyBlocks_RenderableBlock* sub = NULL;
tb_stage_set_view(bw-2, ph-2);
ax_add(ed, TB_A11Y_CANVAS, "Palco", bx, by, bw, ph);
clip_set(ed, rb, bx+1, by+1, bw-2, ph-2);
if (ed->stage->type->on_draw(ed->stage, ed->rt, &sub) && sub) {
tb_draw_merge_offset(rb, sub, bx+1, by+1);
@@ -4720,6 +5024,7 @@ static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* Monitores de variáveis */
float y = by + 10;
ax_push(ed, TB_A11Y_LIST, "Variáveis", bx, by, bw, bh * 0.5f);
for (int v = 0; v < tb_variables_count() && y < by + bh*0.5f; v++) {
const char* vname = tb_variables_name(v);
const TinyBlocks_Value* vv = tb_variables_value(v);
@@ -4732,8 +5037,11 @@ static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_text_c(rb, bx+18, y+13, vname, COL_TEXT, FS);
rb_fill_rrect(rb, bx+18+nw+6, y+4, vw, 18, 4, COL_VAR);
rb_text_c(rb, bx+18+nw+6 + (vw - tw(val, FS))*0.5f, y+13, val, COL_WHITE, FS);
tb_a11y_set_value(ax(ed), ax_add(ed, TB_A11Y_LABEL, vname, bx + 10, y, mw, 26), val);
y += 32;
}
ax_pop(ed);
ax_push(ed, TB_A11Y_LIST, "Console", bx, y, bw, by + bh - y);
/* Console: mostra as últimas linhas que cabem */
const float lh = FS_SM + 5;
@@ -4749,11 +5057,23 @@ static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) {
memcpy(line, p, m); line[m] = 0;
bool err = strncmp(line, "[ERRO]", 6) == 0 || strncmp(line, "[AVISO]", 7) == 0;
rb_text_c(rb, bx + 12, y + lh*0.5f, line, err ? COL_ERR_TEXT : COL_TEXT, FS_SM);
ax_add(ed, TB_A11Y_LABEL, line, bx + 12, y, bw - 24, lh);
y += lh;
}
p += n;
if (*p == '\n') p++;
}
ax_pop(ed);
{ /* a ultima linha escrita: o narrador le quando muda */
const char* last = ed->stage_buf;
size_t L = strlen(last);
while (L > 0 && last[L - 1] == '\n') L--;
size_t st = L;
while (st > 0 && last[st - 1] != '\n') st--;
char line[TB_A11Y_VALUE_MAX];
snprintf(line, sizeof(line), "%.*s", (int)(L - st), last + st);
tb_a11y_set_value(ax(ed), ax_add(ed, TB_A11Y_STATUS, "Última saída", bx, by, bw, bh), line);
}
clip_clear(ed, rb);
draw_grip(ed, rb, V_OUTPUT);
}
@@ -4801,11 +5121,14 @@ static void render_ctx_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rrect(rb, x+2, y+3, CTX_W, mh, 6, COLA(0,0,0,40));
rb_fill_rrect(rb, x, y, CTX_W, mh, 6, COL_BORDER);
rb_fill_rrect(rb, x+1, y+1, CTX_W-2, mh-2, 5, COL_PANEL);
ax_push(ed, TB_A11Y_MENU, "Menu de contexto", x, y, CTX_W, mh);
for (int i = 0; i < ed->ctx_n; i++) {
float iy = y + 4 + i*CTX_ITEM_H;
if (ed->ctx_menu_hover == i) rb_fill_rect(rb, x+1, iy, CTX_W-2, CTX_ITEM_H, COL_UI_BG);
rb_text_c(rb, x+14, iy + CTX_ITEM_H*0.5f, ctx_label(ed->ctx_items[i]), COL_TEXT, FS_UI);
ax_click(ed, TB_A11Y_MENU_ITEM, ctx_label(ed->ctx_items[i]), x, iy, CTX_W, CTX_ITEM_H);
}
ax_pop(ed);
}
/* ===
@@ -4894,7 +5217,9 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_line(rb, bx-5, by, bx+4, by+7, 2.f, COL_WHITE);
rb_text_c(rb, bx + 28, by, "Voltar", COL_WHITE, FS_UI);
{ const char* t = "Escolha uma Extensão";
rb_text_c(rb, (WIN_W - tw(t, 20))*0.5f, by, t, COL_WHITE, 20); }
rb_text_c(rb, (WIN_W - tw(t, 20))*0.5f, by, t, COL_WHITE, 20);
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, t, 0, 0, WIN_W, WIN_H), TB_A11Y_MODAL);
ax_button(ed, "Voltar", 0, 0, 170, LM_HEAD_H); }
/* Barra de filtros */
float fh = libman_chip_layout(ed, NULL);
@@ -4910,6 +5235,7 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float cw = tw(ed->libman_query, FS_UI);
rb_fill_rect(rb, sx + 16 + cw, sy + 12, 1.5f, 20, COL_TEXT);
}
ax_field(ed, "Buscar", ed->libman_query, ed->libman_search_focus, sx, sy, LM_SEARCH_W, 44);
}
{
const char* labels[LM_MAX_CHIPS];
@@ -4922,12 +5248,15 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
sel ? COL_MENU : COL_UI_BG);
rb_text_c(rb, rects[i][0] + 14, rects[i][1] + LM_CHIP_H*0.5f, labels[i],
sel ? COL_WHITE : COL_TEXT, FS_UI);
tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_RADIO, labels[i], rects[i][0], rects[i][1],
rects[i][2], rects[i][3]), sel ? TB_A11Y_CHECKED : 0);
}
}
/* Grade de cartoes (com recorte e rolagem) */
rb_fill_rect(rb, 0, gridY, WIN_W, WIN_H - gridY, COL_UI_BG);
clip_set(ed, rb, 0, gridY, WIN_W, WIN_H - gridY);
ax_push(ed, TB_A11Y_LIST, "Libraries", 0, gridY, WIN_W, WIN_H - gridY);
for (int k = 0; k < nh; k++) {
int col = k % 2, row = k / 2;
float x = LM_MARGIN + col*(LM_CARD_W + LM_CARD_GAP);
@@ -4949,11 +5278,18 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_text_c(rb, x + LM_CARD_W - 110, y + LM_CARD_H - 22, "carregada", COL_FLAG, FS_SM);
}
if (ed->libman_hover == k) rb_stroke_rect(rb, x-1, y-1, LM_CARD_W+2, LM_CARD_H+2, 2.f, COL_MENU);
int an = ax_click(ed, TB_A11Y_LIST_ITEM, e->name, x, y, LM_CARD_W, LM_CARD_H);
tb_a11y_set_description(ax(ed), an, e->description);
tb_a11y_set_value(ax(ed), an, tb_libman_loaded(hits[k]) ? "carregada" : "");
}
ax_pop(ed);
clip_clear(ed, rb);
if (nh == 0)
if (nh == 0) {
rb_text_c(rb, LM_MARGIN, gridY + 40, "Nenhuma library encontrada.", COL_TEXT_DIM, FS_UI);
ax_add(ed, TB_A11Y_LABEL, "Nenhuma library encontrada.", LM_MARGIN, gridY + 30, 300, 20);
}
ax_pop(ed);
}
void libman_click(Ed* ed, float mx, float my) {
@@ -5128,7 +5464,9 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_line(rb, bx-5, by, bx+4, by+7, 2.f, COL_WHITE);
rb_text_c(rb, bx + 28, by, "Voltar", COL_WHITE, FS_UI);
{ const char* t = "Configurações";
rb_text_c(rb, (WIN_W - tw(t, 20)) * 0.5f, by, t, COL_WHITE, 20); }
rb_text_c(rb, (WIN_W - tw(t, 20)) * 0.5f, by, t, COL_WHITE, 20);
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, t, 0, 0, WIN_W, WIN_H), TB_A11Y_MODAL);
ax_button(ed, "Voltar", 0, 0, 170, ST_HEAD_H); }
/* Opcoes: toggle de deteccao do caminho pela variavel de ambiente */
rb_fill_rect(rb, 0, ST_OPT_Y, WIN_W, ST_OPT_H, COL_FLY);
@@ -5142,6 +5480,8 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_line(rb, ST_MARGIN + 8, cb + 15, ST_MARGIN + 16, cb + 5, 2.5f, COL_WHITE);
}
rb_text_c(rb, ST_MARGIN + 30, ST_OPT_Y + ST_OPT_H*0.5f, ST_ENV_LABEL, COL_TEXT, FS_UI);
tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_CHECKBOX, ST_ENV_LABEL, ST_MARGIN, ST_OPT_Y, 540, ST_OPT_H),
ed->settings_use_env ? TB_A11Y_CHECKED : 0);
const char* e = tb_environ_env_path();
const char* hint = e[0] ? e : "TINYBLOCKS_SETTINGS nao definida";
rb_text_c(rb, WIN_W - ST_MARGIN - tw(hint, FS_SM), ST_OPT_Y + ST_OPT_H*0.5f,
@@ -5159,17 +5499,23 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float cw = tw(ed->settings_path, FS_UI);
rb_fill_rect(rb, px + 13 + cw, py + ph*0.5f - 9, 1.5f, 18, COL_TEXT);
}
ax_field(ed, "Arquivo de configurações", ed->settings_path, ed->settings_path_focus, px, py, pw, ph);
}
for (int i = 0; i < 3; i++) {
float x, y, w, h; settings_btn_rect(ed, i, &x, &y, &w, &h);
bool hov = in_rect(ed->mouse_x, ed->mouse_y, x, y, w, h);
st_button(rb, x, y, w, h,
i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "+ Nova", hov);
ax_button(ed, i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "Nova configuração", x, y, w, h);
}
/* Lista */
rb_fill_rect(rb, 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y, COL_UI_BG);
clip_set(ed, rb, 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y);
ax_push(ed, TB_A11Y_LIST, "Configurações", 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y);
if (ed->settings_new_key)
ax_field(ed, "Nome da nova chave", ed->settings_key, true,
ST_MARGIN, ST_LIST_Y - ed->settings_scroll, WIN_W - 2*ST_MARGIN, ST_ROW_H);
if (ed->settings_new_key) {
float y = ST_LIST_Y - ed->settings_scroll;
@@ -5201,12 +5547,19 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
} else {
rb_text_c(rb, vx, y + h*0.5f, tb_environ_value_at(i), COL_TEXT_DIM, FS_UI);
}
bool editing = sel && ed->settings_value_edit;
int an = ax_click(ed, TB_A11Y_LIST_ITEM, tb_environ_key(i), x, y, w, h);
tb_a11y_set_value(ax(ed), an, editing ? ed->settings_edit : tb_environ_value_at(i));
tb_a11y_set_states(ax(ed), an, (sel ? TB_A11Y_SELECTED : 0) | TB_A11Y_EDITABLE |
(editing ? TB_A11Y_FOCUSED | TB_A11Y_EDITING : 0));
}
ax_pop(ed);
clip_clear(ed, rb);
if (n == 0 && !ed->settings_new_key)
rb_text_c(rb, ST_MARGIN, ST_LIST_Y + 24,
"Nenhuma configuracao. Use \"+ Nova\".", COL_TEXT_DIM, FS_UI);
ax_pop(ed);
}
void settings_click(Ed* ed, float mx, float my) {
@@ -5832,7 +6185,14 @@ static void libman_scroll_m(Ed* ed, float dy) { libman_scroll_by(ed, dy); }
/* o explorador vem do modulo do editor (pode faltar) */
static bool files_is_open(Ed* ed) { return ed->fdlg.open; }
static void files_render_m(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (files_view) files_view(ed, rb); }
static void files_render_m(Ed* ed, TinyBlocks_RenderableBlock* rb) {
if (!files_view) return;
files_view(ed, rb);
/* o modulo desenha; aqui so o dialogo e o caminho (o conteudo fica para o modulo) */
tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, ed->fdlg.mode == PM_LOAD ? "Abrir" : "Salvar",
0, 0, WIN_W, WIN_H), TB_A11Y_MODAL);
ax_pop(ed);
}
static void files_click_m(Ed* ed, float mx, float my) { if (files_click) files_click(ed, mx, my); }
static void files_key_m(Ed* ed, int sc, bool ctrl) { if (files_key) files_key(ed, sc, ctrl); else ed->fdlg.open = false; }
static void files_text_m(Ed* ed, const char* t) { if (files_text) files_text(ed, t); }
@@ -6415,6 +6775,72 @@ static bool any_window_detached(Ed* ed) {
/* Entrada de uma janela do editor: a principal (from = -1) ou a de uma view
destacada (from = V_*). Pontos viram coordenadas da janela principal. */
/* O que esta sob o mouse (botoes realcados, item de menu) */
static void hover_update(Ed* ed, float mx, float my) {
ed->flag_hover = hit_flag(ed, mx, my);
ed->stop_hover = hit_stop(ed, mx, my);
ed->lib_hover = hit_lib_btn(mx, my);
ed->detach_hover = hit_detach(ed, mx, my);
ed->ctx_menu_hover = ed->ctx_menu_open ? ctx_hit(ed, mx, my) : -1;
ed->plus_menu_hover = -1;
if (ed->plus_menu_open) {
float px, py;
plus_menu_pos(ed, &px, &py);
for (int i = 0; i < PLUS_MENU_N; i++)
if (in_rect(mx, my, px, py + 26 + i * PLUS_MENU_ITEM_H, PLUS_MENU_W, PLUS_MENU_ITEM_H))
ed->plus_menu_hover = i;
}
}
/* Acoes da arvore acessivel: agem como o mouse no ponto do componente
* (o mesmo caminho do clique, entao narrador, testes e mouse nao divergem) */
static bool ax_perform(void* user, const TinyBlocks_A11yTree* t, int node, TinyBlocks_A11yAction a) {
Ed* ed = user;
float x, y;
tb_a11y_point(t, node, &x, &y);
g_active_ed = ed;
lay_compute(ed);
if (tb_a11y_node(t, node)->states & TB_A11Y_OFFSCREEN) {
/* fora da vista: rola ate ele antes (como o GTK faz) */
TinyBlocks_A11yRole area = TB_A11Y_NONE;
for (int p = node; p >= 0 && area == TB_A11Y_NONE; p = tb_a11y_node(t, p)->parent) {
const TinyBlocks_A11yNode* nd = tb_a11y_node(t, p);
if (nd->role == TB_A11Y_TAB_PANEL || (nd->role == TB_A11Y_LIST && !strcmp(nd->name, "Paleta")))
area = nd->role;
}
if (area == TB_A11Y_TAB_PANEL) {
float dx = x - (WS_X + WS_W * 0.5f), dy = y - (WS_Y + WS_H * 0.5f);
CT.ws_sx += dx; CT.ws_sy += dy;
x -= dx; y -= dy;
} else if (area == TB_A11Y_LIST) {
float before = ed->fly_scroll;
ed->fly_scroll += y - (PAL_Y + (PAL_B - PAL_Y) * 0.5f);
if (ed->fly_scroll > fly_max_scroll(ed)) ed->fly_scroll = fly_max_scroll(ed);
if (ed->fly_scroll < 0) ed->fly_scroll = 0;
y -= ed->fly_scroll - before;
}
}
ed->mouse_x = x; ed->mouse_y = y;
layout_tab(&CT);
hover_update(ed, x, y);
switch (a) {
case TB_A11Y_ACT_ACTIVATE:
case TB_A11Y_ACT_EDIT:
ed->capture_view = -1;
on_lmb_down(ed, x, y);
on_lmb_up(ed, x, y);
ed->capture_view = -2;
return true;
case TB_A11Y_ACT_MENU:
on_rmb_down(ed, x, y);
return true;
default:
return false; /* arrastar precisa de um destino: use o retangulo */
}
}
static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) {
g_active_ed = ed;
if (from < 0) {
@@ -6479,22 +6905,7 @@ static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) {
if (from < 0) toasts_update(ed);
layout_tab(&CT);
/* == Hover === */
ed->flag_hover = hit_flag(ed, mx, my);
ed->stop_hover = hit_stop(ed, mx, my);
ed->lib_hover = hit_lib_btn(mx, my);
ed->detach_hover = hit_detach(ed, mx, my);
ed->ctx_menu_hover = ed->ctx_menu_open ? ctx_hit(ed, mx, my) : -1;
ed->plus_menu_hover = -1;
if (ed->plus_menu_open) {
float px, py;
plus_menu_pos(ed, &px, &py);
for (int i = 0; i < PLUS_MENU_N; i++)
if (in_rect(mx, my, px, py + 26 + i * PLUS_MENU_ITEM_H, PLUS_MENU_W, PLUS_MENU_ITEM_H))
ed->plus_menu_hover = i;
}
hover_update(ed, mx, my);
update_tooltip(ed, (ev_int(evb, GFX_IN_MOD_STATE) & TB_MOD_ALT) != 0);
@@ -6762,7 +7173,14 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
bool saved[V_COUNT];
areas_only(ed, -1, saved); /* as destacadas desenham na janela delas */
for (int v = 0; v < V_COUNT; v++) view_class(v)->render(ed, rb); /* as escondidas nao desenham */
ed->ax_on = ed->ax_enabled && ed->ax_tree;
tb_a11y_begin(ax(ed), "TinyBlocks", WIN_W, WIN_H);
for (int v = 0; v < V_COUNT; v++) { /* as escondidas nao desenham */
bool shown = AREA(v).shown;
if (shown) ax_push(ed, TB_A11Y_PANE, view_name(v), AREA(v).x, AREA(v).y, AREA(v).w, AREA(v).h);
view_class(v)->render(ed, rb);
if (shown) ax_pop(ed);
}
render_menu(ed, rb);
/* A pilha arrastada fica por cima de tudo (pode passar sobre a paleta) */
@@ -6775,6 +7193,8 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
render_ctx_menu(ed, rb);
modals_render(ed, rb); /* de baixo para cima; configuracoes por cima de tudo */
render_toasts(ed, rb); /* avisos flutuam por cima de tudo */
tb_a11y_end(ax(ed));
ed->ax_on = false;
areas_restore(ed, saved);
*dst = rb;
@@ -6828,6 +7248,16 @@ static bool editor_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
ed->split_hover = ed->split_drag = ed->area_drag = ed->area_drop = -1;
ed->swap_pending[0] = ed->swap_pending[1] = -1;
ed->mouse_owner = -1;
ed->ax_tree = tb_a11y_tree_new();
tb_a11y_set_perform(ed->ax_tree, ax_perform, ed);
{ /* TINYBLOCKS_A11Y=0 desliga; =log escreve os eventos no stderr (um narrador de texto) */
const char* env = getenv("TINYBLOCKS_A11Y");
ed->ax_enabled = !(env && strcmp(env, "0") == 0);
if (env && strcmp(env, "log") == 0) {
TinyBlocks_A11yBridge b = tb_a11y_log_bridge(stderr);
tb_a11y_set_bridge(ed->ax_tree, &b);
}
}
ed->capture_view = -2;
ed->tab_press = -1;
ed->tabctx = -1;
@@ -6905,11 +7335,18 @@ static void editor_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
free(ed->run_blocks);
for (int u = 0; u < ed->user_block_n; u++) free(ed->user_blocks[u].snap);
tb_libman_shutdown();
tb_a11y_tree_free(ed->ax_tree);
if (g_active_ed == ed) g_active_ed = NULL;
free(ed);
*(Ed**)self->userdata = NULL;
}
TB_API TinyBlocks_A11yTree* tb_editor_accessible(TinyBlocks_Block* scene) {
if (!scene || !scene->userdata) return NULL;
Ed* ed = *(Ed**)scene->userdata;
return ed && ed->ax_enabled ? ed->ax_tree : NULL;
}
/* ===
* Registra a library
* === */