Tipo diz o texto do seu bloco-handle; paleta sem teto de 192 itens

value_text no TypeBlock: um bloco-handle (TB_VALUE_BLOCK) aparece como
a library quiser ("tensor [3, 32, 32]") em vez de "[bloco Tipo]".
fly_items vira vetor que cresce: as libraries de categoria ja ocupavam
185 dos 192 itens e as variaveis empurravam categorias inteiras para fora.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 22:44:21 -03:00
1 parent 34c9a39c2c
commit 3dd132d12d
6 files changed
+52 -9

No files matched your search

+8
View File
@@ -91,6 +91,11 @@ struct TinyBlocks_TypeBlock {
int pure; int pure;
double (*pure_num)(const double* x); double (*pure_num)(const double* x);
uint32_t pure_arity; uint32_t pure_arity;
/* Texto de um valor que referencia uma instancia deste tipo (um bloco-
handle viajando como TB_VALUE_BLOCK): semantica do snprintf. NULL =
"[bloco Tipo.Nome]". Ex.: "tensor [3, 32, 32]" no monitor e no balao. */
size_t (*value_text)(TinyBlocks_Block* self, char* out, size_t cap);
}; };
/* Semanticas puras que um executor sabe compilar. Quem declara garante que o /* Semanticas puras que um executor sabe compilar. Quem declara garante que o
@@ -124,6 +129,9 @@ TB_API void tb_type_block_set_event(TinyBlocks_TypeBlock* tb, const char* event)
TB_API void tb_type_block_set_label(TinyBlocks_TypeBlock* tb, const char* label, const char* defaults); TB_API void tb_type_block_set_label(TinyBlocks_TypeBlock* tb, const char* label, const char* defaults);
/* Declara a semantica pura do bloco (TB_PURE_*); num/arity so para NUM */ /* Declara a semantica pura do bloco (TB_PURE_*); num/arity so para NUM */
TB_API void tb_type_block_set_pure(TinyBlocks_TypeBlock* tb, int pure, double (*num)(const double* x), uint32_t arity); TB_API void tb_type_block_set_pure(TinyBlocks_TypeBlock* tb, int pure, double (*num)(const double* x), uint32_t arity);
/* Texto das instancias quando viajam como valor (ver value_text) */
TB_API void tb_type_block_set_value_text(TinyBlocks_TypeBlock* tb,
size_t (*fn)(TinyBlocks_Block* self, char* out, size_t cap));
TB_API void tb_type_block_set_input_flags (TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags); TB_API void tb_type_block_set_input_flags (TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags);
TB_API void tb_type_block_set_output_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags); TB_API void tb_type_block_set_output_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags);
TB_API uint32_t tb_type_block_input_flags (const TinyBlocks_TypeBlock* tb, uint32_t i); TB_API uint32_t tb_type_block_input_flags (const TinyBlocks_TypeBlock* tb, uint32_t i);
@@ -187,7 +187,6 @@ enum { IT_SEL = 0, IT_BRUSH, IT_LINE, IT_RECT, IT_ELLIPSE,
#define MAX_GROUPS 32 #define MAX_GROUPS 32
#define GRP_HEAD_H 28 /* faixa do titulo (arrastar = mover tudo) */ #define GRP_HEAD_H 28 /* faixa do titulo (arrastar = mover tudo) */
#define GRP_GRIP 16 /* canto de baixo a direita: redimensionar */ #define GRP_GRIP 16 /* canto de baixo a direita: redimensionar */
#define MAX_FLY 192
#define MAX_CATS 24 #define MAX_CATS 24
#define MAX_CALL_DEPTH 32 #define MAX_CALL_DEPTH 32
#define MAX_RUN_BLOCKS 200000 #define MAX_RUN_BLOCKS 200000
@@ -791,8 +790,8 @@ typedef struct Ed {
int cat_n; int cat_n;
int myblocks_cat; /* índice da categoria "Meus Blocos" */ int myblocks_cat; /* índice da categoria "Meus Blocos" */
Tab fly; /* blocos-modelo do flyout */ Tab fly; /* blocos-modelo do flyout */
FlyItem fly_items[MAX_FLY]; FlyItem* fly_items; /* itens da paleta (vetor que cresce) */
int fly_n; int fly_n, fly_cap;
float fly_scroll, fly_total_h; float fly_scroll, fly_total_h;
Tab tabs[MAX_TABS]; Tab tabs[MAX_TABS];
+18 -6
View File
@@ -2052,15 +2052,26 @@ static void cats_rebuild(Ed* ed) {
} }
} }
/* Mais um item na paleta (o vetor cresce: libraries e variaveis nao tem teto) */
static bool fly_push(Ed* ed, FlyItem it) {
if (ed->fly_n == ed->fly_cap) {
int nc = ed->fly_cap ? ed->fly_cap * 2 : 256;
FlyItem* p = realloc(ed->fly_items, (size_t)nc * sizeof(*p));
if (!p) return false;
ed->fly_items = p; ed->fly_cap = nc;
}
ed->fly_items[ed->fly_n++] = it;
return true;
}
static void fly_add_block(Ed* ed, int cat, TinyBlocks_TypeBlock* t, const char* first, float* y) { static void fly_add_block(Ed* ed, int cat, TinyBlocks_TypeBlock* t, const char* first, float* y) {
if (ed->fly_n >= MAX_FLY) return;
int bi = blk_new(&ed->fly, t); int bi = blk_new(&ed->fly, t);
if (bi < 0) return; if (bi < 0) return;
if (first) strncpy(ed->fly.ws[bi].in_text[0], first, 63); if (first) strncpy(ed->fly.ws[bi].in_text[0], first, 63);
measure(&ed->fly, bi); measure(&ed->fly, bi);
place(&ed->fly, bi, FLY_PAD, *y); place(&ed->fly, bi, FLY_PAD, *y);
float h = ed->fly.ws[bi].h; float h = ed->fly.ws[bi].h;
ed->fly_items[ed->fly_n++] = (FlyItem){FI_BLOCK, cat, bi, *y, h + NOTCH_D}; fly_push(ed, (FlyItem){FI_BLOCK, cat, bi, *y, h + NOTCH_D});
*y += h + 14; *y += h + 14;
} }
@@ -2079,12 +2090,12 @@ void palette_rebuild(Ed* ed) {
float y = 8; float y = 8;
TinyBlocks_TypeBlock* var_get = tb_type_block_find(ed->rt, "Variables.Get"); TinyBlocks_TypeBlock* var_get = tb_type_block_find(ed->rt, "Variables.Get");
int var_cat = cat_of(ed, "Variables.Get"); int var_cat = cat_of(ed, "Variables.Get");
for (int c = 0; c < ed->cat_n && ed->fly_n < MAX_FLY; c++) { for (int c = 0; c < ed->cat_n; c++) {
ed->cats[c].fly_y = y; ed->cats[c].fly_y = y;
ed->fly_items[ed->fly_n++] = (FlyItem){FI_HEADER, c, -1, y, 34}; fly_push(ed, (FlyItem){FI_HEADER, c, -1, y, 34});
y += 34; y += 34;
if (c == ed->myblocks_cat && ed->fly_n < MAX_FLY) { if (c == ed->myblocks_cat) {
ed->fly_items[ed->fly_n++] = (FlyItem){FI_BUTTON, c, -1, y, 42}; fly_push(ed, (FlyItem){FI_BUTTON, c, -1, y, 42});
y += 42; y += 42;
} }
for (uint32_t i = 0; i < tb_rt_type_count(ed->rt); i++) { for (uint32_t i = 0; i < tb_rt_type_count(ed->rt); i++) {
@@ -7705,6 +7716,7 @@ static void editor_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
bubble_clear(ed); bubble_clear(ed);
for (int i = 0; i < ed->tab_n; i++) tab_doc_free(&ed->tabs[i]); for (int i = 0; i < ed->tab_n; i++) tab_doc_free(&ed->tabs[i]);
tab_doc_free(&ed->fly); /* pool da paleta */ tab_doc_free(&ed->fly); /* pool da paleta */
free(ed->fly_items);
free(ed->fdlg.ents); free(ed->fdlg.ents);
free(ed->sbp_text); free(ed->sbp_text);
free(ed->run_blocks); free(ed->run_blocks);
+7
View File
@@ -49,6 +49,7 @@ static TinyBlocks_Block* type_clone(const TinyBlocks_Block* self, TinyBlocks* rt
t->lazy_inputs = src->lazy_inputs; t->lazy_inputs = src->lazy_inputs;
t->label = src->label; t->label = src->label;
t->label_defaults = src->label_defaults; t->label_defaults = src->label_defaults;
t->value_text = src->value_text;
for (uint32_t i = 0; i < src->input_desc_count; i++) for (uint32_t i = 0; i < src->input_desc_count; i++)
tb_type_block_set_input_flags(t, i, tb_type_block_input_flags(src, i)); tb_type_block_set_input_flags(t, i, tb_type_block_input_flags(src, i));
for (uint32_t i = 0; i < src->output_desc_count; i++) for (uint32_t i = 0; i < src->output_desc_count; i++)
@@ -82,6 +83,12 @@ void tb_type_block_set_pure(TinyBlocks_TypeBlock* tb, int pure, double (*num)(co
tb->pure_arity = arity; tb->pure_arity = arity;
} }
void tb_type_block_set_value_text(TinyBlocks_TypeBlock* tb,
size_t (*fn)(TinyBlocks_Block* self, char* out, size_t cap))
{
if (tb) tb->value_text = fn;
}
void tb_type_block_set_input_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags) void tb_type_block_set_input_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags)
{ if (tb && tb->input_flags && i < tb->input_desc_count) tb->input_flags[i] = flags; } { if (tb && tb->input_flags && i < tb->input_desc_count) tb->input_flags[i] = flags; }
void tb_type_block_set_output_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags) void tb_type_block_set_output_flags(TinyBlocks_TypeBlock* tb, uint32_t i, uint32_t flags)
+2
View File
@@ -153,6 +153,8 @@ static const TinyBlocks_ValueClass s_text = {
static size_t block_text(TinyBlocks_Value v, char* out, size_t cap) static size_t block_text(TinyBlocks_Value v, char* out, size_t cap)
{ {
if (v.as.block && v.as.block->type && v.as.block->type->value_text)
return v.as.block->type->value_text(v.as.block, out, cap);
const char* n = v.as.block && v.as.block->type ? v.as.block->type->type_name : "?"; const char* n = v.as.block && v.as.block->type ? v.as.block->type->type_name : "?";
return (size_t)snprintf(out, cap, "[bloco %s]", n); return (size_t)snprintf(out, cap, "[bloco %s]", n);
} }
+15
View File
@@ -16,6 +16,11 @@ static bool text_is(TinyBlocks_Value v, const char* s) {
return strcmp(buf, s) == 0; return strcmp(buf, s) == 0;
} }
static size_t handle_text(TinyBlocks_Block* self, char* out, size_t cap) {
(void)self;
return (size_t)snprintf(out, cap, "tensor [3, 32, 32]");
}
int main(void) { int main(void) {
/* toda kind tem classe; desconhecida cai em "nada" */ /* toda kind tem classe; desconhecida cai em "nada" */
bool all = true; bool all = true;
@@ -65,6 +70,16 @@ int main(void) {
CHECK(tb_value_equals(ve, ve2) && !tb_value_equals(ve, vo), "resultados iguais pela tag e pelo conteúdo"); CHECK(tb_value_equals(ve, ve2) && !tb_value_equals(ve, vo), "resultados iguais pela tag e pelo conteúdo");
tb_value_free(&vo); tb_value_free(&ve); tb_value_free(&ve2); tb_value_free(&jl); tb_value_free(&t); tb_value_free(&vo); tb_value_free(&ve); tb_value_free(&ve2); tb_value_free(&jl); tb_value_free(&t);
/* Bloco-handle: o tipo diz como o valor vira texto (value_text) */
TinyBlocks* rt = NULL;
tinyblocks_init(&rt, NULL);
TinyBlocks_TypeBlock* th = tb_type_block_create(rt, "Teste._Handle", NULL, 0, NULL, 0, NULL);
TinyBlocks_Block* hb = tb_block_create(rt, th);
CHECK(text_is(tb_value_block(hb), "[bloco Teste._Handle]"), "bloco sem value_text: \"[bloco Tipo]\"");
tb_type_block_set_value_text(th, handle_text);
CHECK(text_is(tb_value_block(hb), "tensor [3, 32, 32]"), "bloco com value_text: o texto do tipo");
tinyblocks_deinit(&rt);
if (fails) printf("\n%d FALHA(S)\n", fails); if (fails) printf("\n%d FALHA(S)\n", fails);
else printf("\nTUDO OK\n"); else printf("\nTUDO OK\n");
return fails != 0; return fails != 0;