Divide as seções da paleta em libraries de categoria
Cada seção (Eventos, Controle, Operadores, Variáveis, Aparência, Caneta) virou uma library própria, com seus blocos e eval. Foi adicionado um metadado opcional de categoria (TinyBlocks_Category) para a UI agrupar a paleta a partir das libraries registradas, sem hardcode no editor. - núcleo: tb_library_set_category() e campo category em LibraryBlock - editor: cats_rebuild/cat_of usam a library dona de cada TypeBlock; "Meus Blocos" (User./Port.) continua no editor - variáveis: armazenamento movido para tinyblocks-variables, com API de enumeração (tb_variables_count/name/value/reset_blocks) - palco: Editor.Stage continua no editor; a API de desenho (tb_stage_*) é usada pela library tinyblocks-pen - host/tests/Makefile: registram e linkam as novas libraries
This commit is contained in:
1 parent
278d3f4473
commit
1cc0ff9d02
20 files changed
+1063
-597
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* TinyBlocks - tb_appearance.c
|
||||
* Categoria "Aparência": blocos que produzem saída visível (console do editor).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "tb_appearance.h"
|
||||
|
||||
static void eval_print(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value label = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Value value = tb_block_get_input(self, rt, 1);
|
||||
const char* lbl = label.kind == TB_VALUE_TEXT ? label.as.text : "resultado";
|
||||
if (value.kind == TB_VALUE_INTEGER)
|
||||
printf("%s = %lld\n", lbl, (long long)value.as.integer);
|
||||
else if (value.kind == TB_VALUE_REAL)
|
||||
printf("%s = %g\n", lbl, value.as.real);
|
||||
else if (value.kind == TB_VALUE_TEXT)
|
||||
printf("%s = %s\n", lbl, value.as.text ? value.as.text : "");
|
||||
else
|
||||
printf("%s\n", lbl);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_print_int(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, 0);
|
||||
int64_t n = v.kind == TB_VALUE_INTEGER ? v.as.integer : 0;
|
||||
printf("%lld\n", (long long)n);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static bool appearance_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_Category cat = {
|
||||
"Aparência",
|
||||
{153/255.f, 102/255.f, 255/255.f, 1.f},
|
||||
{119/255.f, 77/255.f, 203/255.f, 1.f},
|
||||
};
|
||||
tb_library_set_category(lib, &cat);
|
||||
|
||||
static const TinyBlocks_SlotDesc print_in[] = {{"label", TB_VALUE_TEXT}, {"value", TB_VALUE_NONE}};
|
||||
static const TinyBlocks_SlotDesc one_int[] = {{"n", TB_VALUE_INTEGER}};
|
||||
|
||||
TinyBlocks_TypeBlock* t;
|
||||
t = tb_type_block_create(rt, "IO.Print", print_in, 2, NULL, 0, eval_print);
|
||||
if (!t || !tb_library_add(lib, &t->base)) return false;
|
||||
t = tb_type_block_create(rt, "IO.PrintInt", one_int, 1, NULL, 0, eval_print_int);
|
||||
if (!t || !tb_library_add(lib, &t->base)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void appearance_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
(void)rt; (void)lib;
|
||||
}
|
||||
|
||||
TINYBLOCKS_DEFINE_LIBRARY(appearance,
|
||||
"tinyblocks-appearance",
|
||||
"1.0.0",
|
||||
appearance_init,
|
||||
appearance_deinit)
|
||||
|
||||
const TinyBlocks_LibraryDescriptor* tb_appearance_get_library(void) {
|
||||
return &_tb_lib_desc_appearance;
|
||||
}
|
||||
Reference in new issue
Block a user