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
+15
-21
@@ -8,6 +8,12 @@
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_editor.h>
|
||||
#include <tb_graphics.h>
|
||||
#include <tb_events.h>
|
||||
#include <tb_control.h>
|
||||
#include <tb_operators.h>
|
||||
#include <tb_variables.h>
|
||||
#include <tb_appearance.h>
|
||||
#include <tb_pen.h>
|
||||
|
||||
static TinyBlocks* rt;
|
||||
static TinyBlocks_Block *ev, *scene;
|
||||
@@ -15,19 +21,6 @@ static TinyBlocks_DrawCmd cmds[TB_DRAW_CMD_CAP];
|
||||
static uint32_t ncmd;
|
||||
static int fails = 0;
|
||||
|
||||
static void eval_print(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value l = tb_block_get_input(self, rt, 0), v = tb_block_get_input(self, rt, 1);
|
||||
const char* lbl = l.kind==TB_VALUE_TEXT ? l.as.text : "resultado";
|
||||
if (v.kind==TB_VALUE_INTEGER) printf("%s = %lld\n", lbl, (long long)v.as.integer);
|
||||
else if (v.kind==TB_VALUE_REAL) printf("%s = %g\n", lbl, v.as.real);
|
||||
else if (v.kind==TB_VALUE_TEXT) printf("%s = %s\n", lbl, v.as.text);
|
||||
else printf("%s\n", lbl);
|
||||
}
|
||||
static void eval_add(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value a = tb_block_get_input(self, rt, 0), b = tb_block_get_input(self, rt, 1);
|
||||
long long x = a.kind==TB_VALUE_INTEGER ? a.as.integer : 0, y = b.kind==TB_VALUE_INTEGER ? b.as.integer : 0;
|
||||
tb_block_set_output(self, 0, tb_value_integer(x + y));
|
||||
}
|
||||
static void eval_ev(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; self->dirty = false; }
|
||||
|
||||
static void draw(void) {
|
||||
@@ -122,12 +115,13 @@ static bool need(const char* s, int region, int nth, float* x, float* y) {
|
||||
|
||||
int main(void) {
|
||||
tinyblocks_init(&rt, NULL);
|
||||
static const TinyBlocks_SlotDesc print_in[] = {{"label", TB_VALUE_TEXT}, {"value", TB_VALUE_NONE}};
|
||||
static const TinyBlocks_SlotDesc two_int[] = {{"a", TB_VALUE_INTEGER}, {"b", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc int_out[] = {{"result", TB_VALUE_INTEGER}};
|
||||
tb_type_block_create(rt, "Math.Add", two_int, 2, int_out, 1, eval_add);
|
||||
tb_type_block_create(rt, "IO.Print", print_in, 2, NULL, 0, eval_print);
|
||||
tb_graphics_set_backend(tb_graphics_null_backend());
|
||||
tb_library_register(rt, tb_events_get_library());
|
||||
tb_library_register(rt, tb_control_get_library());
|
||||
tb_library_register(rt, tb_operators_get_library());
|
||||
tb_library_register(rt, tb_variables_get_library());
|
||||
tb_library_register(rt, tb_appearance_get_library());
|
||||
tb_library_register(rt, tb_pen_get_library());
|
||||
tb_library_register(rt, tb_graphics_get_library());
|
||||
tb_library_register(rt, tb_editor_get_library());
|
||||
(void)eval_ev;
|
||||
@@ -154,8 +148,8 @@ int main(void) {
|
||||
|
||||
/* 3. Encaixar o "escreva Olá!" logo abaixo do chapéu */
|
||||
float hx, hy;
|
||||
if (need("quando ⚑ for clicado", R_WS, 0, &hx, &hy) && need("escreva", R_WS, 1, &x, &y)) {
|
||||
/* hat: rótulo em (bx+10, by+18+18); fundo em by+54 → alvo: topo do bloco em by+54 */
|
||||
if (need("quando a bandeira for clicado", R_WS, 0, &hx, &hy) && need("escreva", R_WS, 1, &x, &y)) {
|
||||
/* hat: rótulo em (bx+10, by+18+18); fundo em by+54 - alvo: topo do bloco em by+54 */
|
||||
float bx = hx - 3 - 10, by = hy - 18 - 18;
|
||||
float gx = x - 3 - 10, gy = y - 18; /* canto do bloco arrastado */
|
||||
drag(x, y, x + (bx - gx), y + (by + 54 - gy) + 6);
|
||||
@@ -169,7 +163,7 @@ int main(void) {
|
||||
}
|
||||
CHECK(oy1 > 0 && oy2 > oy1, "ordem de execução: Olá! antes de x vale");
|
||||
|
||||
/* 4. Repórter "+": solto, editar campos, clicar → balão */
|
||||
/* 4. Repórter "+": solto, editar campos, clicar - balão */
|
||||
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, 640, 470);
|
||||
if (need("+", R_WS, 0, &x, &y)) {
|
||||
|
||||
Reference in new issue
Block a user