Files
tinyblocks/libraries/tinyblocks-editor/include/tb_editor_m3.h
T
mguinhosandClaude Opus 5.5 70c819393c Editor: ripple do M3, formas lisas e encaixes como no Scratch
- Ripple (gota que cresce do toque/clique) em todo componente com camada
  de estado; recortado no formato do componente (tb_ew_ripple).
- TB_DRAW_FILL_POLY: poligono convexo com antialias (pontos no espaco do
  text). Hexagono e encaixe deixam de ser faixas de 1 px (sumiam em linhas
  com zoom e na densidade do celular).
- Encaixe macho com cantos arredondados; encaixe femea recortado no topo
  dos comandos e dos blocos C (e nos bracos de baixo/"senao").
- Destaque ao soltar um reporter num campo segue a forma do campo; sombra
  de encaixe da pilha com a forma de bloco.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 22:23:32 -03:00

290 lines
12 KiB
C

/*
* 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));
rb_ripple(rb, x, y, w, h, rad, on); /* gota do toque/clique */
}
/* == 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_ripple(rb, cx - s * 0.5f, cy - s * 0.5f, s, s, s * 0.5f, c);
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 */