Editor: botao de extensoes no fim da coluna de categorias (estilo Scratch)

- quadrado vermelho com "+" e livrinhos, fixo no rodape do painel de
  categorias; abre a tela do libman (mesma acao do menu Bibliotecas / Ctrl+L).
- harness: teste que clica o botao no painel e confirma a abertura do libman.
This commit is contained in:
mguinhos committed 2026-10-20 20:26:23 -03:00
1 parent dcc20985c5
commit a9ab2d6a05
2 files changed
+28

No files matched your search

@@ -98,6 +98,9 @@ TB_API void tb_editor_preload(const char* path) {
#define LIB_BTN_X 500 #define LIB_BTN_X 500
#define LIB_BTN_W 200 #define LIB_BTN_W 200
/* Botao de buscar/adicionar library no fim da coluna de categorias */
#define LIBMAN_BTN_H 56
/* == Geometria dos blocos === */ /* == Geometria dos blocos === */
#define FS 12 /* texto dos blocos */ #define FS 12 /* texto dos blocos */
#define FS_UI 13 /* texto da interface */ #define FS_UI 13 /* texto da interface */
@@ -166,6 +169,8 @@ static const Col COL_WHITE = C(255,255,255);
static const Col COL_MISSING = C(170,170,170); static const Col COL_MISSING = C(170,170,170);
static const Col COL_EXT = C( 15,189,140); /* extensões */ static const Col COL_EXT = C( 15,189,140); /* extensões */
static const Col COL_EXT_DARK = C( 11,142,105); static const Col COL_EXT_DARK = C( 11,142,105);
static const Col COL_LIBBTN = C(255, 76, 76); /* botao de extensoes */
static const Col COL_LIBBTN_DARK = C(211, 47, 47);
static const Col COL_VAR = C(255,140, 26); static const Col COL_VAR = C(255,140, 26);
static const Col COL_MON_BG = C(230,240,255); static const Col COL_MON_BG = C(230,240,255);
static const Col COL_MON_BORDER = C(195,204,217); static const Col COL_MON_BORDER = C(195,204,217);
@@ -449,6 +454,7 @@ static void libman_key(Ed* ed, int sc);
static void libman_text(Ed* ed, const char* typed); static void libman_text(Ed* ed, const char* typed);
static void libman_scroll_by(Ed* ed, float dy); static void libman_scroll_by(Ed* ed, float dy);
static void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb); static void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb);
static bool hit_libman_foot(Ed* ed, float mx, float my);
/* === /* ===
* Helpers de desenho - emitem TinyBlocks_DrawCmd em um RenderableBlock * Helpers de desenho - emitem TinyBlocks_DrawCmd em um RenderableBlock
@@ -2585,6 +2591,15 @@ static void render_categories(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float w = tw(ed->cats[c].name, 10); float w = tw(ed->cats[c].name, 10);
rb_text_c(rb, CAT_W*0.5f - w*0.5f, iy + ih*0.76f, ed->cats[c].name, COL_TEXT, 10); rb_text_c(rb, CAT_W*0.5f - w*0.5f, iy + ih*0.76f, ed->cats[c].name, COL_TEXT, 10);
} }
/* Botao de buscar/adicionar library, no fim do painel (como o Scratch) */
float by = WIN_H - LIBMAN_BTN_H;
bool hov = (ed->mouse_x < CAT_W && ed->mouse_y >= by && ed->mouse_y < WIN_H);
rb_fill_rect(rb, 0, by, CAT_W-1, LIBMAN_BTN_H, hov ? COL_LIBBTN_DARK : COL_LIBBTN);
float cx = CAT_W*0.5f, 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);
rb_fill_rect(rb, cx+5, cy-6, 12, 3, COL_WHITE); /* "+" no canto */
rb_fill_rect(rb, cx+9.5f, cy-10, 3, 11, COL_WHITE);
} }
static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) { static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) {
@@ -2859,6 +2874,10 @@ static void libman_close(Ed* ed) {
ed->libman_search_focus = false; ed->libman_search_focus = false;
} }
static bool hit_libman_foot(Ed* ed, float mx, float my) {
return mx < CAT_W && my >= WIN_H - LIBMAN_BTN_H;
}
static void libman_show(Ed* ed) { static void libman_show(Ed* ed) {
ed->libman_open = true; ed->libman_open = true;
ed->libman_query[0] = 0; ed->libman_query[0] = 0;
@@ -3375,6 +3394,7 @@ static void on_lmb_down(Ed* ed, float mx, float my) {
/* Categorias */ /* Categorias */
if (mx < CAT_W) { if (mx < CAT_W) {
if (hit_libman_foot(ed, mx, my)) { libman_show(ed); return; }
int c = (int)((my - PAL_Y) / cat_item_h(ed)); int c = (int)((my - PAL_Y) / cat_item_h(ed));
if (c >= 0 && c < ed->cat_n) { if (c >= 0 && c < ed->cat_n) {
ed->fly_scroll = ed->cats[c].fly_y - 4; ed->fly_scroll = ed->cats[c].fly_y - 4;
+8
View File
@@ -377,6 +377,14 @@ int main(void) {
CHECK(!find("Escolha uma Extensão", R_ANY, 0, &x, &y), "libman fecha apos carregar"); CHECK(!find("Escolha uma Extensão", R_ANY, 0, &x, &y), "libman fecha apos carregar");
CHECK(find("Blueprint", R_CAT, 0, &x, &y), "library carregada aparece na paleta"); CHECK(find("Blueprint", R_CAT, 0, &x, &y), "library carregada aparece na paleta");
/* 17. Botao de extensoes no fim do painel (estilo Scratch) */
frame(0, 0, 0, 0, 0, 0, NULL);
click(34, 720 - 28);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(find("Escolha uma Extensão", R_ANY, 0, &x, &y), "botao de extensoes no painel abre o libman");
key(TB_KEY_ESCAPE, 0, 0);
frame(0, 0, 0, 0, 0, 0, NULL);
printf("comandos de desenho no último frame: %u\n", ncmd); printf("comandos de desenho no último frame: %u\n", ncmd);
tinyblocks_deinit(&rt); tinyblocks_deinit(&rt);
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails); printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);