Editor: redesign visual no Material 3 (Roboto, Material Symbols, cores de sempre)

- Fontes em assets/fonts (Roboto Regular/Medium, Material Symbols contorno e
  preenchido; Apache 2.0). TB_DRAW_TEXT escolhe a fonte pelo param
  (tb_draw_text_font, TB_FONT_*); backend SDL2 com cache por familia e
  DejaVu de reserva. Pacotes AppImage/Android/Windows levam as fontes.
- tb_editor_m3.h: papeis de cor do M3 sobre a paleta do editor, formas,
  tipografia, camadas de estado, elevacao, icones e componentes (botoes,
  icon button, menu, campo, dialogo, chip, snackbar, switch).
- Top app bar, abas primarias, navigation rail das categorias, FAB de
  extensoes, palco, saida, menus, snackbars, dialogos, explorador,
  Bibliotecas, Configuracoes, previa scratchblocks, editores de codigo e
  de imagem no estilo M3.
- Widgets: icon, text_f e shadow. Backend: TINYBLOCKS_SHOT salva a janela
  (conferir o visual); editor: TINYBLOCKS_OPEN abre uma tela no inicio.
- Console: linhas roladas continuam na arvore acessivel (OFFSCREEN).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-28 21:34:04 -03:00
1 parent f180eaf75a
commit 0cb2019704
22 files changed
+1451 -516

No files matched your search

@@ -57,15 +57,16 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
* === */
#define WIN_W_DEFAULT 1280
#define WIN_H_DEFAULT 720
#define MENU_H 44
#define TAB_H 36
#define MENU_H 56 /* top app bar do M3 (densidade -2) */
#define TAB_H 40 /* cabecalho das areas / abas (M3, densidade -2) */
#define CAT_W 68
#define FLY_W 250
#define FLY_PAD 12
#define FLY_BTN_W 150
#define PALETTE_W (CAT_W + FLY_W) /* largura padrao da paleta */
#define STAGE_W 360 /* largura padrao da coluna do palco */
#define STAGE_BAR_H 44
#define STAGE_BAR_H TAB_H
#define STAGE_TOP (STAGE_BAR_H + 4) /* onde a vista do palco comeca */
#define WIN_W (ed->win_w)
#define WIN_H (ed->win_h)
@@ -88,8 +89,8 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
#define PLUS_W 28
/* Menu do botao "+" (nova aba) */
#define PLUS_MENU_W 208
#define PLUS_MENU_ITEM_H 36
#define PLUS_MENU_W 260
#define PLUS_MENU_ITEM_H 52 /* item de duas linhas (M3) */
#define PLUS_MENU_N 4
/* Editor de codigo (aba de codigo) */
@@ -143,8 +144,8 @@ enum { IT_SEL = 0, IT_BRUSH, IT_LINE, IT_RECT, IT_ELLIPSE,
(menu_layout em tb_editor.c): o que nao cabe vai para o menu "☰". */
enum { MB_OPEN, MB_SAVE, MB_EXPORT, MB_LIBMAN, MB_LIB, MB_CFG, MB_COUNT };
typedef struct { float x, w; bool shown; } MenuBtn;
#define MENU_BTN_Y 7
#define MENU_BTN_H (MENU_H - 14)
#define MENU_BTN_H 36
#define MENU_BTN_Y ((MENU_H - MENU_BTN_H) / 2)
#define MENU_MORE_W 40
/* Modo compacto (janela estreita / celular): uma area de cada vez.
@@ -245,6 +246,9 @@ typedef struct {
#define rb_text_c tb_ed_w.text_c
#define tw tb_ed_w.text_width
#define in_rect tb_ed_w.in_rect
#define rb_text_f tb_ed_w.text_f
#define rb_icon tb_ed_w.icon
#define rb_shadow tb_ed_w.shadow
static const Col COL_MENU TB_EW_UNUSED = C( 76,151,255); /* #4C97FF */
static const Col COL_MENU_DARK TB_EW_UNUSED = C( 61,121,204);
@@ -296,6 +300,8 @@ static const Col s_user_colors[USER_COLOR_COUNT] TB_EW_UNUSED = {
C(255,191, 0), C(255,171, 25), C( 89,192, 89), C( 15,189,140),
};
#include "tb_editor_m3.h" /* Material 3 sobre a paleta acima */
/* == Rótulos dos blocos (%N - campo de entrada N) === */
typedef struct {
const char* type;
@@ -0,0 +1,287 @@
/*
* TinyBlocks - tb_editor_m3.h
*
* Linguagem visual do editor: Material 3 (m3.material.io) com as cores que o
* editor ja usava. Papeis de cor do M3 apontam para a paleta do TinyBlocks;
* formas, tipografia (Roboto), icones (Material Symbols), camadas de estado
* e elevacao seguem o M3. Densidade -2 do M3 (desktop): alturas 4 px menores.
*
* Incluido por tb_editor_internal.h (usa Col, C(), COLA() e rb_*).
*/
#ifndef TB_EDITOR_M3_H
#define TB_EDITOR_M3_H
/* == Papeis de cor (M3) -> paleta do editor === */
#define M3_PRIMARY COL_MENU /* #4C97FF */
#define M3_ON_PRIMARY COL_WHITE
#define M3_PRIMARY_DARK COL_MENU_DARK
#define M3_PRIMARY_CONTAINER COL_HOVER /* #D6E4F8 */
#define M3_SECONDARY_CONTAINER COL_TAB_OFF /* #D9E3F2 */
#define M3_SURFACE COL_PANEL /* branco */
#define M3_SURFACE_LOW COL_FLY /* #F9F9F9 */
#define M3_SURFACE_CONTAINER COL_UI_BG /* #E5F0FF */
#define M3_ON_SURFACE COL_TEXT /* #575E75 */
#define M3_ON_SURFACE_VAR COL_TEXT_DIM
#define M3_OUTLINE COL_TEXT_DIM
#define M3_OUTLINE_VAR COL_BORDER
#define M3_INVERSE_SURFACE COL_TIP_BG
#define M3_INVERSE_ON_SURFACE COL_CODE_TEXT
#define M3_INVERSE_PRIMARY COL_TIP_LINK
#define M3_ERROR COL_STOP
/* == Formas (raio dos cantos) === */
#define M3_SHAPE_XS 4.f
#define M3_SHAPE_S 8.f
#define M3_SHAPE_M 12.f
#define M3_SHAPE_L 16.f
#define M3_SHAPE_XL 28.f
/* == Tipografia (tamanho em px; titulos e rotulos em Roboto Medium) === */
#define M3_HEADLINE_S 24.f
#define M3_TITLE_L 22.f
#define M3_TITLE_M 16.f
#define M3_TITLE_S 14.f
#define M3_LABEL_L 14.f
#define M3_LABEL_M 12.f
#define M3_LABEL_S 11.f
#define M3_BODY_L 16.f
#define M3_BODY_M 14.f
#define M3_BODY_S 12.f
/* == Camadas de estado (opacidade da cor do conteudo) === */
#define M3_HOVER 0.08f
#define M3_PRESSED 0.10f
#define M3_DRAGGED 0.16f
/* == Componentes: alturas (densidade -2) === */
#define M3_BUTTON_H 36.f /* botoes comuns (40 no M3 padrao) */
#define M3_ICON_BTN 36.f /* icon button: alvo (40 no padrao) */
#define M3_ICON 20.f /* icone dentro de botoes */
#define M3_MENU_ITEM 40.f /* item de menu (48 no padrao) */
/* == Icones (Material Symbols, codepoints) === */
#define MI_ADD 0xe145
#define MI_ARROW_BACK 0xe5c4
#define MI_ARROW_FORWARD 0xe5c8
#define MI_ARROW_UPWARD 0xe5d8
#define MI_ARROW_RIGHT 0xe5df
#define MI_BRUSH 0xe3ae
#define MI_CANCEL 0xe888
#define MI_CHECK 0xe668
#define MI_CHECK_CIRCLE 0xf0be
#define MI_CHEVRON_LEFT 0xe5cb
#define MI_CHEVRON_RIGHT 0xe5cc
#define MI_CIRCLE 0xef4a
#define MI_CLOSE 0xe5cd
#define MI_CODE 0xe86f
#define MI_COLORIZE 0xe3b8
#define MI_CONTENT_COPY 0xe14d
#define MI_CONTENT_CUT 0xe14e
#define MI_CONTENT_PASTE 0xe14f
#define MI_CREATE_FOLDER 0xe2cc
#define MI_DELETE 0xe92e
#define MI_DESCRIPTION 0xe873
#define MI_DRAFT 0xe66d
#define MI_DRAG_INDICATOR 0xe945
#define MI_EDIT 0xf097
#define MI_ERROR 0xf8b6
#define MI_EXPAND_MORE 0xe5cf
#define MI_EXTENSION 0xe87b
#define MI_FILL 0xe23a
#define MI_FLAG 0xf0c6
#define MI_FOLDER 0xe2c7
#define MI_GRID_VIEW 0xe9b0
#define MI_DATA_OBJECT 0xead3
#define MI_TABLE 0xf191
#define MI_ACCOUNT_TREE 0xe97a
#define MI_SELECT_ALL 0xe162
#define MI_ADD_BOX 0xe146
#define MI_FOLDER_OPEN 0xe2c8
#define MI_HOME 0xe9b2
#define MI_IMAGE 0xe3f4
#define MI_INFO 0xe88e
#define MI_ERASER 0xe6d0
#define MI_IOS_SHARE 0xe6b8
#define MI_LIBRARY_ADD 0xe03c
#define MI_LIBRARY_BOOKS 0xe02f
#define MI_MENU 0xe5d2
#define MI_MORE_VERT 0xe5d4
#define MI_OPEN_IN_NEW 0xe89e
#define MI_CLOSE_FULLSCR 0xf1cf
#define MI_PALETTE 0xe40a
#define MI_PAN_TOOL 0xe925
#define MI_PLAY_ARROW 0xe037
#define MI_RECTANGLE 0xeb54
#define MI_REDO 0xe15a
#define MI_REFRESH 0xe5d5
#define MI_SAVE 0xe161
#define MI_SEARCH 0xef7a
#define MI_SELECT 0xf74d
#define MI_SETTINGS 0xe8b8
#define MI_STOP 0xe047
#define MI_STOP_CIRCLE 0xef71
#define MI_SWAP_HORIZ 0xe8d4
#define MI_TERMINAL 0xeb8e
#define MI_TEXT_FIELDS 0xe262
#define MI_UNDO 0xe166
#define MI_UPLOAD_FILE 0xe9fc
#define MI_WARNING 0xf083
#define MI_WIDGETS 0xe1bd
#define MI_ZOOM_IN 0xe8ff
#define MI_ZOOM_OUT 0xe900
/* == Utilitarios === */
static inline Col m3_alpha(Col c, float a) { c.a = a; return c; }
/* c sobre o fundo bg com opacidade a (cor solida resultante) */
static inline Col m3_mix(Col bg, Col c, float a) {
Col r = { bg.r + (c.r - bg.r) * a, bg.g + (c.g - bg.g) * a, bg.b + (c.b - bg.b) * a, 1.f };
return r;
}
/* Largura de um rotulo em Roboto Medium (a medicao do backend e da Regular) */
static inline float m3_tw_m(const char* s, float fs) { return tw(s, fs) * 1.04f; }
/* Camada de estado: a cor do conteudo, translucida, sobre o componente */
static inline void m3_state(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad,
Col on, bool hover, bool pressed) {
float a = pressed ? M3_PRESSED : hover ? M3_HOVER : 0.f;
if (a > 0.f) rb_fill_rrect(rb, x, y, w, h, rad, m3_alpha(on, a));
}
/* == Botoes (pilula): filled, tonal, outlined, text === */
enum { M3_FILLED, M3_TONAL, M3_OUTLINED, M3_TEXT };
static inline float m3_button_w(const char* label, unsigned icon) {
return m3_tw_m(label, M3_LABEL_L) + (icon ? 16.f + 18.f + 8.f + 24.f : 48.f);
}
/* accent = cor do papel "primary" deste botao (a do editor ou a do dialogo) */
static inline void m3_button(TinyBlocks_RenderableBlock* rb, int kind, float x, float y, float w, float h,
const char* label, unsigned icon, Col accent, bool hover, bool pressed) {
float r = h * 0.5f;
Col on = accent;
if (kind == M3_FILLED) {
rb_fill_rrect(rb, x, y, w, h, r, accent);
on = M3_ON_PRIMARY;
} else if (kind == M3_TONAL) {
rb_fill_rrect(rb, x, y, w, h, r, m3_mix(M3_SURFACE, accent, 0.16f));
on = col_mul(accent, 0.8f);
} else if (kind == M3_OUTLINED) {
rb_fill_rrect(rb, x, y, w, h, r, M3_OUTLINE_VAR);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, r - 1, M3_SURFACE);
}
m3_state(rb, x, y, w, h, r, on, hover, pressed);
float lw = m3_tw_m(label, M3_LABEL_L);
float cx = x + w * 0.5f, cy = y + h * 0.5f;
if (icon) {
float total = 18.f + 8.f + lw;
float ix = cx - total * 0.5f;
rb_icon(rb, ix + 9.f, cy, icon, 18.f, on, false);
rb_text_f(rb, ix + 26.f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
} else {
rb_text_f(rb, cx - lw * 0.5f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
}
}
/* Icon button (padrao): so o icone; o circulo aparece no hover/pressionado.
selected = toggle ligado (container tonal) */
static inline void m3_icon_button(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned icon, Col c,
bool hover, bool selected) {
float s = M3_ICON_BTN;
if (selected) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, 0.16f));
if (hover) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, M3_HOVER));
rb_icon(rb, cx, cy, icon, M3_ICON, c, selected);
}
/* == Superficies === */
/* Menu: canto XS, elevacao 2 */
static inline void m3_menu_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 2);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_SURFACE);
}
/* Item de menu: icone opcional a esquerda, rotulo Label Large */
static inline void m3_menu_item(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
const char* label, unsigned icon, bool hover, Col fg) {
m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, hover, false);
float tx = x + 12.f;
if (icon) { rb_icon(rb, tx + 10.f, y + h * 0.5f, icon, M3_ICON, M3_ON_SURFACE_VAR, false); tx += 20.f + 12.f; }
rb_text_f(rb, tx, y + h * 0.5f, label, fg, M3_LABEL_L, TB_FONT_REGULAR);
}
/* Dialogo: canto XL, elevacao 3 */
static inline void m3_dialog_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XL, 3);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XL, M3_SURFACE);
}
/* Scrim atras de dialogos modais */
static inline void m3_scrim(TinyBlocks_RenderableBlock* rb, float w, float h) {
rb_fill_rect(rb, 0, 0, w, h, COLA(0, 0, 0, 82));
}
/* Campo de texto "outlined": canto XS, contorno 1 px (2 px na cor
primaria quando em foco) */
static inline void m3_field(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
bool focused, Col accent) {
if (focused) {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, accent);
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, M3_SHAPE_XS - 1, M3_SURFACE);
} else {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_OUTLINE);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_XS - 0.5f, M3_SURFACE);
}
}
/* Barra de busca: pilula, icone de lupa a esquerda */
static inline void m3_search_bar(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
bool focused, Col accent) {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_SURFACE_CONTAINER);
if (focused) {
rb_fill_rrect(rb, x - 1, y - 1, w + 2, h + 2, h * 0.5f + 1, accent);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, M3_SURFACE_CONTAINER);
}
rb_icon(rb, x + 16.f + 12.f, y + h * 0.5f, MI_SEARCH, 24.f, M3_ON_SURFACE_VAR, false);
}
/* Indicador da aba ativa (aba primaria): 3 px com cantos de cima redondos */
static inline void m3_tab_indicator(TinyBlocks_RenderableBlock* rb, float x, float y_bottom, float w, Col c) {
rb_fill_rrect(rb, x, y_bottom - 3.f, w, 6.f, 3.f, c);
}
/* Chip (assist/filter): canto S, 32 px */
static inline void m3_chip(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label,
unsigned icon, bool selected, bool hover) {
if (selected) rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
else {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_OUTLINE_VAR);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_S - 1, M3_SURFACE);
}
m3_state(rb, x, y, w, h, M3_SHAPE_S, M3_ON_SURFACE, hover, false);
float tx = x + 12.f;
if (icon) { rb_icon(rb, x + 8.f + 9.f, y + h * 0.5f, icon, 18.f, M3_PRIMARY, false); tx = x + 8.f + 18.f + 8.f; }
rb_text_f(rb, tx, y + h * 0.5f, label, M3_ON_SURFACE, M3_LABEL_L, TB_FONT_MEDIUM);
}
/* Snackbar: superficie inversa, canto XS, elevacao 3 */
static inline void m3_snackbar_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 3);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_INVERSE_SURFACE);
}
/* Interruptor (switch) do M3: trilho 52x32, alca 16 (24 ligado) */
static inline void m3_switch(TinyBlocks_RenderableBlock* rb, float x, float y, bool on, Col accent) {
const float w = 52.f, h = 32.f;
if (on) {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, accent);
rb_fill_circle(rb, x + w - 16.f, y + h * 0.5f, 12.f, M3_ON_PRIMARY);
rb_icon(rb, x + w - 16.f, y + h * 0.5f, MI_CHECK, 16.f, accent, false);
} else {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_OUTLINE);
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, h * 0.5f - 2, M3_SURFACE_CONTAINER);
rb_fill_circle(rb, x + 16.f, y + h * 0.5f, 8.f, M3_OUTLINE);
}
}
#endif /* TB_EDITOR_M3_H */
@@ -48,6 +48,9 @@ typedef struct {
void (*text_c) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float);
float (*text_width) (const char*, float);
bool (*in_rect) (float, float, float, float, float, float);
void (*text_f) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float, int);
void (*icon) (TinyBlocks_RenderableBlock*, float, float, unsigned, float, TbEwColor, bool);
void (*shadow) (TinyBlocks_RenderableBlock*, float, float, float, float, float, int);
} TbEdWidgetsApi;
/* API da library privada tinyblocks-editor-image */