diff --git a/Makefile b/Makefile index 4d35a5f..fccd333 100644 --- a/Makefile +++ b/Makefile @@ -358,6 +358,7 @@ appdir: editor ## Monta o AppDir (build/TinyBlocks.AppDir) para o AppImage cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/usr/share/applications/tinyblocks.desktop cp $(PKG_DIR)/AppRun $(APPDIR)/AppRun chmod +x $(APPDIR)/AppRun + cp -r assets/fonts $(APPDIR)/fonts # Roboto + Material Symbols (TINYBLOCKS_APPDIR/fonts) @echo "Empacotando bibliotecas (exceto as do sistema)..." @ldd $(BUILD)/editor | awk '/=> \//{print $$1, $$3}' | while read name path; do \ skip=0; \ diff --git a/assets/fonts/LICENSE-MaterialSymbols.txt b/assets/fonts/LICENSE-MaterialSymbols.txt new file mode 100644 index 0000000..7a4a3ea --- /dev/null +++ b/assets/fonts/LICENSE-MaterialSymbols.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/assets/fonts/LICENSE-Roboto.txt b/assets/fonts/LICENSE-Roboto.txt new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/assets/fonts/LICENSE-Roboto.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/assets/fonts/MaterialSymbolsFilled.ttf b/assets/fonts/MaterialSymbolsFilled.ttf new file mode 100644 index 0000000..3ed1e13 Binary files /dev/null and b/assets/fonts/MaterialSymbolsFilled.ttf differ diff --git a/assets/fonts/MaterialSymbolsOutlined.ttf b/assets/fonts/MaterialSymbolsOutlined.ttf new file mode 100644 index 0000000..534394e Binary files /dev/null and b/assets/fonts/MaterialSymbolsOutlined.ttf differ diff --git a/assets/fonts/Roboto-Medium.ttf b/assets/fonts/Roboto-Medium.ttf new file mode 100644 index 0000000..307e1ba Binary files /dev/null and b/assets/fonts/Roboto-Medium.ttf differ diff --git a/assets/fonts/Roboto-Regular.ttf b/assets/fonts/Roboto-Regular.ttf new file mode 100644 index 0000000..54a284d Binary files /dev/null and b/assets/fonts/Roboto-Regular.ttf differ diff --git a/include/tinyblocks/tb_renderable_block.h b/include/tinyblocks/tb_renderable_block.h index 1421da1..084220b 100644 --- a/include/tinyblocks/tb_renderable_block.h +++ b/include/tinyblocks/tb_renderable_block.h @@ -41,7 +41,8 @@ typedef struct { TinyBlocks_DrawCmdKind kind; float x, y, w, h; /* geometria (significado varia por kind) */ float r, g, b, a; /* cor RGBA [0..1] */ - float param; /* radius (rrect/circle), espessura (linha/stroke) */ + float param; /* radius (rrect/circle), espessura (linha/stroke); * + * no TB_DRAW_TEXT, a fonte (TB_FONT_*) */ float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */ char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */ const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */ @@ -105,6 +106,19 @@ TB_API void tb_draw_text (TinyBlocks_RenderableBlock* rb, float x, float y, const char* text, float font_size, float r, float g, float b, float a); +/* Fontes do texto (param do TB_DRAW_TEXT). Os icones sao glifos do Material + * Symbols (codepoints da area privada, ex.: U+E8B8 = "settings"); o backend + * sem a fonte de icones nao desenha nada. */ +#define TB_FONT_REGULAR 0 /* Roboto Regular */ +#define TB_FONT_MEDIUM 1 /* Roboto Medium (rotulos, titulos) */ +#define TB_FONT_ICON 2 /* Material Symbols Outlined */ +#define TB_FONT_ICON_FILLED 3 /* Material Symbols (preenchido) */ +#define TB_FONT_COUNT 4 + +TB_API void tb_draw_text_font (TinyBlocks_RenderableBlock* rb, + float x, float y, const char* text, float font_size, int font, + float r, float g, float b, float a); + /* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é * ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a * imagem precisa continuar viva até o backend renderizar o frame. */ diff --git a/libraries/tinyblocks-editor/include/tb_editor_internal.h b/libraries/tinyblocks-editor/include/tb_editor_internal.h index 82324dd..b463452 100644 --- a/libraries/tinyblocks-editor/include/tb_editor_internal.h +++ b/libraries/tinyblocks-editor/include/tb_editor_internal.h @@ -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; diff --git a/libraries/tinyblocks-editor/include/tb_editor_m3.h b/libraries/tinyblocks-editor/include/tb_editor_m3.h new file mode 100644 index 0000000..65db778 --- /dev/null +++ b/libraries/tinyblocks-editor/include/tb_editor_m3.h @@ -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 */ diff --git a/libraries/tinyblocks-editor/include/tb_editor_modules.h b/libraries/tinyblocks-editor/include/tb_editor_modules.h index d412d94..7a26829 100644 --- a/libraries/tinyblocks-editor/include/tb_editor_modules.h +++ b/libraries/tinyblocks-editor/include/tb_editor_modules.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 */ diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c index e5d4459..803c5b7 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c @@ -21,15 +21,15 @@ #include "tb_editor_files.h" /* -- Geometria --- */ -#define FD_HEAD_H 46 +#define FD_HEAD_H 60 #define FD_BAR_H 44 #define FD_SIDE_W 196 #define FD_COLH_H 26 -#define FD_ROW_H 26 +#define FD_ROW_H 32 #define FD_FOOT_H 100 #define FD_PAD 14 #define FD_BTN_W 104 -#define FD_BTN_H 32 +#define FD_BTN_H 36 static const Col COL_FD_FOLDER = C(255,191, 38); static const Col COL_FD_FOLDER_DARK = C(222,150, 10); @@ -66,8 +66,8 @@ static void fd_layout(Ed* ed, FdL* L) { L->w = w; L->h = h; L->x = (WIN_W - w) * 0.5f; L->y = (WIN_H - h) * 0.5f; - L->close_cx = L->x + w - 26.f; - L->close_cy = L->y + FD_HEAD_H * 0.5f; + L->close_cx = L->x + w - 32.f; + L->close_cy = L->y + FD_HEAD_H * 0.5f + 2.f; L->bar_y = L->y + FD_HEAD_H + 7.f; L->up_x = L->x + FD_PAD; L->crumb_x = L->up_x + 40.f; @@ -565,11 +565,11 @@ void tb_editor_files_open(Ed* ed, int mode, const char* def) { /* -- Desenho --- */ +/* Icones do Material Symbols (x, y = canto do quadrado de 20 px) */ static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) { - Col c = COL_FD_FOLDER, d = COL_FD_FOLDER_DARK; - if (dim) { c.a = 0.55f; d.a = 0.55f; } - rb_fill_rrect(rb, x, y + 1, 9, 6, 2, d); - rb_fill_rrect(rb, x, y + 4, 19, 13, 2, c); + Col c = COL_FD_FOLDER; + if (dim) c.a = 0.55f; + rb_icon(rb, x + 10, y + 9, dim ? MI_ARROW_UPWARD : MI_FOLDER, 20.f, dim ? M3_ON_SURFACE_VAR : c, !dim); } static Col fd_type_col(const char* name) { @@ -583,37 +583,38 @@ static Col fd_type_col(const char* name) { return COL_TEXT_DIM; } -static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band) { - rb_fill_rrect(rb, x + 2, y, 15, 18, 2, COL_BORDER); - rb_fill_rrect(rb, x + 3, y + 1, 13, 16, 1.5f, COL_WHITE); - rb_fill_rect(rb, x + 3, y + 11, 13, 5, band); - rb_line(rb, x + 6, y + 5, x + 13, y + 5, 1, COL_BORDER); - rb_line(rb, x + 6, y + 8, x + 13, y + 8, 1, COL_BORDER); +static unsigned fd_type_icon(const char* name) { + const char* e = fd_ext(name); + if (!strcasecmp(e, ".json") || !strcasecmp(e, ".xml") || !strcasecmp(e, ".csv")) return MI_DATA_OBJECT; + if (!strcasecmp(e, ".png") || !strcasecmp(e, ".jpg") || !strcasecmp(e, ".jpeg") || + !strcasecmp(e, ".bmp") || !strcasecmp(e, ".ppm") || !strcasecmp(e, ".svg")) return MI_IMAGE; + if (!strcasecmp(e, ".so")) return MI_EXTENSION; + if (!strcasecmp(e, ".c") || !strcasecmp(e, ".h") || !strcasecmp(e, ".py") || + !strcasecmp(e, ".md") || !strcasecmp(e, ".toml")) return MI_CODE; + return MI_DRAFT; } +static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band, const char* name) { + rb_icon(rb, x + 10, y + 9, fd_type_icon(name), 20.f, band, false); +} + +/* Caixa de selecao do M3 (16 px aqui, canto 2) com o rotulo */ static void fd_checkbox(TinyBlocks_RenderableBlock* rb, float x, float cy, bool on, const char* label) { - float s = 16; + float s = 18; if (on) { - rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_MENU); - rb_line(rb, x + 4, cy, x + 7, cy + 4, 2, COL_WHITE); - rb_line(rb, x + 7, cy + 4, x + 12, cy - 4, 2, COL_WHITE); + rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_PRIMARY); + rb_icon(rb, x + s * 0.5f, cy, MI_CHECK, 16.f, M3_ON_PRIMARY, false); } else { - rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_BORDER); - rb_fill_rrect(rb, x + 1.5f, cy - s * 0.5f + 1.5f, s - 3, s - 3, 2, COL_WHITE); + rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_ON_SURFACE_VAR); + rb_fill_rrect(rb, x + 2, cy - s * 0.5f + 2, s - 4, s - 4, 1, M3_SURFACE); } - rb_text_c(rb, x + s + 8, cy, label, COL_TEXT, FS_UI); + rb_text_f(rb, x + s + 10, cy, label, M3_ON_SURFACE, M3_BODY_M, TB_FONT_REGULAR); } +/* Acoes do dialogo: a principal e "filled", a outra e botao de texto */ static void fd_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label, bool primary, bool hov, Col accent) { - if (primary) { - rb_fill_rrect(rb, x, y, w, h, h * 0.5f, hov ? col_mul(accent, 0.86f) : accent); - rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_WHITE, FS_UI); - } else { - rb_fill_rrect(rb, x, y, w, h, h * 0.5f, COL_BORDER); - rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, hov ? COL_HOVER : COL_WHITE); - rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_TEXT, FS_UI); - } + m3_button(rb, primary ? M3_FILLED : M3_TEXT, x, y, w, h, label, 0, accent, hov, false); } /* Caixa de confirmacao "substituir?" (geometria compartilhada com o clique) */ @@ -712,34 +713,26 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { bool modal_free = !F->confirm; char buf[512]; - rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120)); - rb_fill_rrect(rb, L.x + 3, L.y + 4, L.w, L.h, 12, COLA(0, 0, 0, 70)); - rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COL_PANEL); + m3_scrim(rb, WIN_W, WIN_H); + m3_dialog_surface(rb, L.x, L.y, L.w, L.h); - /* Cabecalho */ - rb_fill_rrect(rb, L.x, L.y, L.w, FD_HEAD_H, 12, COL_MENU); - rb_fill_rect(rb, L.x, L.y + FD_HEAD_H - 12, L.w, 12, COL_MENU); - rb_text_c(rb, L.x + (L.w - tw(F->title, 18)) * 0.5f, L.y + FD_HEAD_H * 0.5f, F->title, COL_WHITE, 18); - { - bool hov = modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 14.f; - rb_fill_circle(rb, L.close_cx, L.close_cy, 13, COLA(255, 255, 255, hov ? 110 : 60)); - rb_line(rb, L.close_cx - 5, L.close_cy - 5, L.close_cx + 5, L.close_cy + 5, 2, COL_WHITE); - rb_line(rb, L.close_cx + 5, L.close_cy - 5, L.close_cx - 5, L.close_cy + 5, 2, COL_WHITE); - } + /* Cabecalho: icone + titulo (headline) a esquerda, fechar a direita */ + rb_icon(rb, L.x + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->save ? MI_SAVE : MI_FOLDER_OPEN, 24.f, M3_PRIMARY, false); + rb_text_f(rb, L.x + 24 + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->title, M3_ON_SURFACE, M3_HEADLINE_S, + TB_FONT_REGULAR); + m3_icon_button(rb, L.close_cx, L.close_cy, MI_CLOSE, M3_ON_SURFACE_VAR, + modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 16.f, false); /* Barra: pasta acima + trilha */ { float by = L.bar_y, bh = 30; bool hov = modal_free && in_rect(mx, my, L.up_x, by, 32, bh); bool can_up = strcmp(F->dir, "/") != 0; - rb_fill_rrect(rb, L.up_x, by, 32, bh, 6, hov && can_up ? COL_HOVER : COL_UI_BG); - Col ac = can_up ? COL_TEXT : COL_TEXT_DIM; float cx = L.up_x + 16, cy = by + bh * 0.5f; - rb_line(rb, cx, cy + 7, cx, cy - 7, 2, ac); - rb_line(rb, cx - 6, cy - 1, cx, cy - 7, 2, ac); - rb_line(rb, cx + 6, cy - 1, cx, cy - 7, 2, ac); + m3_icon_button(rb, cx, cy, MI_ARROW_UPWARD, can_up ? M3_ON_SURFACE_VAR : m3_alpha(M3_ON_SURFACE, 0.38f), + hov && can_up, false); - rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, 6, COL_UI_BG); + rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, bh * 0.5f, M3_SURFACE_CONTAINER); FdCrumbs K; fd_crumbs(ed, &L, &K); if (K.ellipsis) @@ -750,37 +743,39 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { fd_fit(fit, sizeof(fit), lb, FS_UI, K.w[k] - 16.f); bool last = k == K.n - 1; bool h = modal_free && !last && in_rect(mx, my, K.x[k], by + 3, K.w[k], bh - 6); - if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_WHITE); - else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_HOVER); - rb_text_c(rb, K.x[k] + 8, cy, fit, last ? COL_TEXT : COL_MENU_DARK, FS_UI); - if (!last && k > 0) rb_text_c(rb, K.x[k] + K.w[k] + 3, cy, "/", COL_TEXT_DIM, FS_UI); + if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f, M3_SECONDARY_CONTAINER); + else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f, + m3_alpha(M3_ON_SURFACE, M3_HOVER)); + rb_text_f(rb, K.x[k] + 8, cy, fit, last ? M3_ON_SURFACE : M3_PRIMARY_DARK, M3_LABEL_L, TB_FONT_MEDIUM); + if (!last && k > 0) rb_icon(rb, K.x[k] + K.w[k] + 7, cy, MI_CHEVRON_RIGHT, 16.f, M3_ON_SURFACE_VAR, false); } } /* Barra lateral: locais */ - rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, COL_BORDER); + rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, M3_OUTLINE_VAR); if (L.side_w > 0) { - rb_fill_rect(rb, L.side_x, L.side_y, L.side_w, L.side_h, COL_FD_SIDE); - rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, COL_BORDER); - rb_text_c(rb, L.side_x + FD_PAD, L.side_y + 16, "Locais", COL_TEXT_DIM, FS_SM); + rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, M3_OUTLINE_VAR); + rb_text_f(rb, L.side_x + FD_PAD + 4, L.side_y + 16, "Locais", M3_ON_SURFACE_VAR, M3_TITLE_S, TB_FONT_MEDIUM); } - for (int i = 0; L.side_w > 0 && i < F->place_n; i++) { + for (int i = 0; L.side_w > 0 && i < F->place_n; i++) { /* itens da gaveta de navegacao */ float iy = L.side_y + 30 + i * 32; bool cur = strcmp(F->dir, F->place_path[i]) == 0; bool h = modal_free && in_rect(mx, my, L.side_x + 6, iy, L.side_w - 12, 30); - if (cur || h) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 6, cur ? COL_HOVER : COLA(214, 228, 248, 140)); - if (cur) rb_fill_rrect(rb, L.side_x + 6, iy + 6, 3, 18, 1.5f, COL_MENU); - fd_icon_folder(rb, L.side_x + 16, iy + 6, false); + if (cur) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_SECONDARY_CONTAINER); + m3_state(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_ON_SURFACE, h, false); + rb_icon(rb, L.side_x + 16 + 10, iy + 15, MI_FOLDER, 20.f, cur ? M3_ON_SURFACE : M3_ON_SURFACE_VAR, cur); fd_fit(buf, sizeof(buf), F->place_label[i], FS_UI, L.side_w - 60); - rb_text_c(rb, L.side_x + 42, iy + 15, buf, cur ? COL_MENU_DARK : COL_TEXT, FS_UI); + rb_text_f(rb, L.side_x + 44, iy + 15, buf, M3_ON_SURFACE, M3_LABEL_L, cur ? TB_FONT_MEDIUM : TB_FONT_REGULAR); } /* Cabecalho das colunas */ float col_size = L.col_size, col_time = L.col_time; - rb_text_c(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", COL_TEXT_DIM, FS_SM); - if (col_size) rb_text_c(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", COL_TEXT_DIM, FS_SM); - if (col_time) rb_text_c(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", COL_TEXT_DIM, FS_SM); - rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, COL_BORDER); + rb_text_f(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM); + if (col_size) rb_text_f(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", M3_ON_SURFACE_VAR, M3_LABEL_M, + TB_FONT_MEDIUM); + if (col_time) rb_text_f(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", M3_ON_SURFACE_VAR, M3_LABEL_M, + TB_FONT_MEDIUM); + rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, M3_OUTLINE_VAR); /* Linhas */ int end = F->scroll + L.rows; @@ -790,12 +785,14 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { float ry = L.list_y + (float)(i - F->scroll) * FD_ROW_H; bool sel = i == F->sel; bool h = modal_free && in_rect(mx, my, L.list_x, ry, L.list_w - 12, FD_ROW_H); - if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_MENU); - else if (h) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_HOVER); - Col tc = sel ? COL_WHITE : COL_TEXT; - Col dc = sel ? COLA(255, 255, 255, 210) : COL_TEXT_DIM; - if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, ry + 4, e->is_dir == 2); - else fd_icon_file(rb, L.list_x + 14, ry + 4, fd_type_col(e->name)); + if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S, + M3_SECONDARY_CONTAINER); + m3_state(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S, M3_ON_SURFACE, h, false); + Col tc = M3_ON_SURFACE; + Col dc = M3_ON_SURFACE_VAR; + float iy = ry + (FD_ROW_H - 18) * 0.5f; + if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, iy, e->is_dir == 2); + else fd_icon_file(rb, L.list_x + 14, iy, fd_type_col(e->name), e->name); fd_fit(buf, sizeof(buf), e->is_dir == 2 ? ".. (pasta acima)" : e->name, FS_UI, L.name_end - (L.list_x + 44) - 16); rb_text_c(rb, L.list_x + 44, ry + FD_ROW_H * 0.5f, buf, tc, FS_UI); @@ -821,8 +818,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { float kh = th * (float)L.rows / (float)F->n; if (kh < 24) kh = 24; float ky = L.list_y + 4 + (th - kh) * (float)F->scroll / (float)(F->n - L.rows); - rb_fill_rrect(rb, tx, L.list_y + 4, 6, th, 3, COL_UI_BG); - rb_fill_rrect(rb, tx, ky, 6, kh, 3, COL_TEXT_DIM); + rb_fill_rrect(rb, tx + 1, ky, 4, kh, 2, m3_alpha(M3_ON_SURFACE, 0.38f)); } if (F->err[0]) { float ey = L.list_y + L.list_h - 30; @@ -833,10 +829,9 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* Rodape: nome + opcoes + botoes */ float foot = L.name_y - 14.f; - rb_line(rb, L.x, foot, L.x + L.w, foot, 1, COL_BORDER); - rb_text_c(rb, L.x + FD_PAD, L.name_y + 15, "Nome:", COL_TEXT, FS_UI); - rb_fill_rrect(rb, L.name_x, L.name_y, L.name_w, 30, 6, COL_MENU); - rb_fill_rrect(rb, L.name_x + 1.5f, L.name_y + 1.5f, L.name_w - 3, 27, 5, COL_WHITE); + rb_line(rb, L.x, foot, L.x + L.w, foot, 1, M3_OUTLINE_VAR); + rb_text_f(rb, L.x + FD_PAD + 4, L.name_y + 15, "Nome:", M3_ON_SURFACE, M3_BODY_M, TB_FONT_MEDIUM); + m3_field(rb, L.name_x, L.name_y - 3, L.name_w, 36, true, M3_PRIMARY); { float maxw = L.name_w - 24; const char* s = F->name; @@ -860,7 +855,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { char f2[120]; snprintf(f2, sizeof(f2), "(%s)", F->filter); fd_fit(buf, sizeof(buf), f2, FS_SM, L.chk_hid_x - L.chk_all_x - 160); - rb_text_c(rb, L.chk_all_x + 24 + tw("Todos os arquivos", FS_UI) + 8, r2, buf, COL_TEXT_DIM, FS_SM); + rb_text_f(rb, L.chk_all_x + 28 + tw("Todos os arquivos", M3_BODY_M) + 10, r2, buf, M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR); } } fd_checkbox(rb, L.chk_hid_x, r2, F->show_hidden, "Mostrar ocultos"); @@ -871,18 +866,17 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* Confirmacao de substituicao */ if (F->confirm) { - rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COLA(0, 0, 0, 60)); + rb_fill_rrect(rb, L.x, L.y, L.w, L.h, M3_SHAPE_XL, COLA(0, 0, 0, 60)); float bx, by, bw, bh; fd_confirm_geom(&L, &bx, &by, &bw, &bh); - rb_fill_rrect(rb, bx + 2, by + 3, bw, bh, 10, COLA(0, 0, 0, 60)); - rb_fill_rrect(rb, bx, by, bw, bh, 10, COL_PANEL); + m3_dialog_surface(rb, bx, by, bw, bh); const char* b = strrchr(F->name, '/'); b = b ? b + 1 : F->name; char q[400]; snprintf(q, sizeof(q), "\"%s\" já existe.", b); fd_fit(buf, sizeof(buf), q, 15, bw - 40); - rb_text_c(rb, bx + 20, by + 34, buf, COL_TEXT, 15); - rb_text_c(rb, bx + 20, by + 60, "Deseja substituir o arquivo?", COL_TEXT_DIM, FS_UI); + rb_text_f(rb, bx + 24, by + 36, buf, M3_ON_SURFACE, M3_TITLE_L - 2, TB_FONT_REGULAR); + rb_text_f(rb, bx + 24, by + 64, "Deseja substituir o arquivo?", M3_ON_SURFACE_VAR, M3_BODY_M, TB_FONT_REGULAR); float yb = by + bh - FD_BTN_H - 16; float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W; fd_button(rb, xc, yb, FD_BTN_W, FD_BTN_H, "Cancelar", false, diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c index 66f3aff..7d33ee8 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c @@ -180,10 +180,10 @@ static float img_pal_y(Ed* ed) { static void img_zoom_slider(Ed* ed, float* x, float* y, float* w, float* h) { float ax, ay, aw, ah; img_area(ed, &ax, &ay, &aw, &ah); - *x = ax + 176; - *w = aw - 176 - 14; + *x = ax + 8 + 112 + 4 + 96 + 20; /* depois de Desfazer e Limpar */ + *w = aw - (8 + 112 + 4 + 96 + 20) - 28; *h = IMG_SLIDER_H; - *y = img_foot_y(ed) + 22.f; + *y = img_foot_y(ed) + (IMG_FOOT_H - IMG_SLIDER_H) * 0.5f + 4.f; (void)h; (void)ah; *h = IMG_SLIDER_H; } @@ -214,10 +214,10 @@ static void img_foot_btn(Ed* ed, int which, float* x, float* y, float* w, float* float ax, ay, aw, ah, fy; img_area(ed, &ax, &ay, &aw, &ah); fy = img_foot_y(ed); - *y = fy + 5; *h = 24; + *y = fy + 3; *h = 28; switch (which) { - case 0: *w = 78; *x = ax + 10; break; /* Desfazer */ - case 1: *w = 68; *x = ax + 96; break; /* Limpar */ + case 0: *w = 112; *x = ax + 8; break; /* Desfazer */ + case 1: *w = 96; *x = ax + 8 + 112 + 4; break; /* Limpar */ default: *w = 30; *x = ax + aw - 40; break; } @@ -644,40 +644,14 @@ static void img_undo_do(Tab* T) { T->img_rev++; } -/* Icones das ferramentas --- */ -static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c) { - switch (tool) { - case IT_SEL: - rb_line(rb, cx - 6, cy - 8, cx - 6, cy + 7, 2.f, c); - rb_line(rb, cx - 6, cy - 8, cx + 5, cy + 1, 2.f, c); - rb_line(rb, cx - 6, cy - 1, cx + 3, cy + 7, 2.f, c); - break; - case IT_BRUSH: - rb_line(rb, cx - 8, cy + 8, cx + 3, cy - 3, 5.f, c); - rb_fill_circle(rb, cx + 6, cy - 6, 3.4f, c); - break; - case IT_LINE: - rb_line(rb, cx - 8, cy + 8, cx + 8, cy - 8, 2.f, c); - break; - case IT_RECT: - rb_stroke_rect(rb, cx - 8, cy - 6, 16, 12, 2.f, c); - break; - case IT_ELLIPSE: - rb_stroke_circle(rb, cx, cy, 8, 2.f, c); - break; - case IT_FILL: - rb_fill_rrect(rb, cx - 8, cy - 8, 13, 13, 3, c); - rb_fill_circle(rb, cx + 4, cy + 5, 4, c); - break; - case IT_ERASER: - rb_fill_rrect(rb, cx - 8, cy - 3, 16, 9, 2, c); - rb_line(rb, cx - 8, cy + 6, cx + 8, cy + 6, 2.f, col_mul(c, 0.6f)); - break; - case IT_PICK: - rb_line(rb, cx + 7, cy - 7, cx + 2, cy - 2, 3.f, c); - rb_fill_circle(rb, cx - 2, cy + 2, 4.4f, c); - break; - } +/* Icones das ferramentas (Material Symbols) --- */ +static const unsigned IMG_TOOL_ICON[IT_N] = { + [IT_SEL] = 0xf82f /* arrow_selector_tool */, [IT_BRUSH] = MI_BRUSH, [IT_LINE] = 0xf41e /* diagonal_line */, + [IT_RECT] = MI_RECTANGLE, [IT_ELLIPSE] = MI_CIRCLE, [IT_FILL] = MI_FILL, + [IT_ERASER] = MI_ERASER, [IT_PICK] = MI_COLORIZE, +}; +static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c, bool on) { + rb_icon(rb, cx, cy, IMG_TOOL_ICON[tool], 24.f, c, on); } /* Render --- */ @@ -810,32 +784,33 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG); /* --- coluna esquerda: ferramentas --- */ - rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, COL_PANEL); - rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE); - for (int i = 0; i < IT_N; i++) { + rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, M3_SURFACE); + rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR); + for (int i = 0; i < IT_N; i++) { /* icon buttons de alternar (M3) */ float bx, by; img_tool_rect(ed, i, &bx, &by); bool sel = T->img_tool == i; bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, IMG_TH, IMG_TH); - Col bg = sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN); - rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, 8, bg); - if (!sel) rb_stroke_rect(rb, bx, by, IMG_TH, IMG_TH, 1.f, COL_PAINT_LINE); - img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? COL_WHITE : COL_TEXT); - if (hov && !sel) - rb_text_c(rb, bx + IMG_TH + 6, by + IMG_TH * 0.5f, img_tool_tip(i), COL_TEXT_DIM, 10.f); + if (sel) rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, M3_PRIMARY); + m3_state(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, sel ? M3_ON_PRIMARY : M3_ON_SURFACE, hov, false); + img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? M3_ON_PRIMARY : M3_ON_SURFACE_VAR, sel); + if (hov && !sel) { /* tooltip simples do M3 */ + const char* tip = img_tool_tip(i); + float tw_ = tw(tip, M3_BODY_S) + 16, ty = by + IMG_TH * 0.5f - 12; + rb_fill_rrect(rb, bx + IMG_TH + 6, ty, tw_, 24, M3_SHAPE_XS, M3_INVERSE_SURFACE); + rb_text_f(rb, bx + IMG_TH + 14, ty + 12, tip, M3_INVERSE_ON_SURFACE, M3_BODY_S, TB_FONT_REGULAR); + } } /* --- barra superior (arquivo) --- */ - rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, COL_PANEL); + rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, M3_SURFACE); rb_line(rb, WS_X + IMG_TOOL_W, WS_Y + IMG_BAR_H - 1, - WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, COL_PAINT_LINE); + WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, M3_OUTLINE_VAR); { - float bx = WS_X + IMG_TOOL_W + 10; - rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU); - rb_text_c(rb, bx + (62 - tw("Abrir", FS_UI-1)) * 0.5f, WS_Y + 17, "Abrir", COL_WHITE, FS_UI-1); + float bx = WS_X + IMG_TOOL_W + 10, mx = ed->mouse_x, my = ed->mouse_y; + m3_button(rb, M3_TONAL, bx, WS_Y + 4, 62, 26, "Abrir", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false); bx += 70; - rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU_DARK); - rb_text_c(rb, bx + (62 - tw("Salvar", FS_UI-1)) * 0.5f, WS_Y + 17, "Salvar", COL_WHITE, FS_UI-1); + m3_button(rb, M3_FILLED, bx, WS_Y + 4, 62, 26, "Salvar", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false); bx += 74; char pbuf[40]; snprintf(pbuf, sizeof(pbuf), "%.30s", T->img_path[0] ? T->img_path : "sem arquivo"); @@ -848,8 +823,8 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { (int)(T->img_zoom * 100.f + 0.5f), T->img_w, T->img_h); if (img_narrow(ed)) { /* sem espaco para o resumo: botao da coluna */ float cx = WS_X + WS_W - IMG_PANEL_BTN_W - 8; - rb_fill_rrect(rb, cx, WS_Y + 5, IMG_PANEL_BTN_W, 24, 6, ed->img_panel_open ? COL_MENU_DARK : COL_MENU); - rb_text_c(rb, cx + (IMG_PANEL_BTN_W - tw("Cores", FS_UI-1)) * 0.5f, WS_Y + 17, "Cores", COL_WHITE, FS_UI-1); + m3_button(rb, ed->img_panel_open ? M3_FILLED : M3_TONAL, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26, "Cores", 0, + M3_PRIMARY, in_rect(ed->mouse_x, ed->mouse_y, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26), false); } else rb_text_c(rb, WS_X + WS_W - 12 - tw(info, FS_UI-1), WS_Y + 17, info, COL_TEXT_DIM, FS_UI-1); } @@ -926,18 +901,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { float ax, ay, aw, ah, fy; img_area(ed, &ax, &ay, &aw, &ah); fy = img_foot_y(ed); - rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, COL_PANEL); - rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, COL_PAINT_LINE); + rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, M3_SURFACE); + rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, M3_OUTLINE_VAR); const char* labels[2] = { "Desfazer", "Limpar" }; - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { /* botoes de texto com icone */ float bx, by, bw, bh; img_foot_btn(ed, i, &bx, &by, &bw, &bh); bool enabled = !(i == 0 && T->img_undo_n == 0); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, bw, bh); - rb_fill_rrect(rb, bx, by, bw, bh, 6, hov && enabled ? COL_HOVER : COL_PAINT_BTN); - rb_stroke_rect(rb, bx, by, bw, bh, 1.f, COL_PAINT_LINE); - rb_text_c(rb, bx + (bw - tw(labels[i], FS_UI-1)) * 0.5f, by + bh * 0.5f, - labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1); + m3_button(rb, M3_TEXT, bx, by, bw, bh, labels[i], i == 0 ? MI_UNDO : MI_DELETE, + enabled ? M3_PRIMARY : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false); } /* --- widget novo: slider de zoom --- */ @@ -947,19 +920,17 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { float t = img_zoom_t(T->img_zoom); float kx = sx + t * (sw - 14.f) + 7.f; bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx - 6, sy - 10, sw + 12, sh + 20); - /* trilha */ - rb_fill_rrect(rb, sx, sy, sw, sh, 3, COL_PAINT_BTN); - /* parte preenchida ate o botao */ - rb_fill_rrect(rb, sx, sy, kx - sx, sh, 3, hov ? COL_MENU : COLA(0, 122, 216, 255)); - rb_stroke_rect(rb, sx, sy, sw, sh, 1.f, COL_PAINT_LINE); - /* marcas de 100% */ - { + /* slider do M3: trilha ativa (primaria) e inativa (container) */ + float tcy = sy + sh * 0.5f; + rb_fill_rrect(rb, sx, tcy - 2, sw, 4, 2, M3_SECONDARY_CONTAINER); + rb_fill_rrect(rb, sx, tcy - 2, kx - sx, 4, 2, M3_PRIMARY); + { /* marca de 100% */ float mxr = sx + img_zoom_t(1.f) * (sw - 14.f) + 7.f; - rb_fill_rect(rb, mxr - 0.5f, sy - 3, 1.f, sh + 6, COL_TEXT_DIM); + rb_fill_circle(rb, mxr, tcy, 1.5f, kx > mxr ? M3_ON_PRIMARY : M3_PRIMARY); } - /* botao */ - rb_fill_circle(rb, kx, sy + sh * 0.5f, 7.f, COL_WHITE); - rb_stroke_circle(rb, kx, sy + sh * 0.5f, 7.f, 2.f, hov ? COL_MENU : COLA(0, 122, 216, 255)); + /* alca */ + if (hov) rb_fill_circle(rb, kx, tcy, 14.f, m3_alpha(M3_PRIMARY, M3_HOVER)); + rb_fill_circle(rb, kx, tcy, 8.f, M3_PRIMARY); /* porcentagem acima do botao */ { char z[16]; @@ -976,16 +947,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (img_panel_shown(ed)) { float px = img_color_x(ed); float cx_, cy_, ro, ri; - rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, COL_PANEL); - rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE); - rb_text_c(rb, px + 12, WS_Y + 16, "Cores", COL_TEXT_DIM, 11.f); + rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, M3_SURFACE); + rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR); + rb_text_f(rb, px + 12, WS_Y + 18, "Cores", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); /* amostra da cor atual */ { Col cc = COLA(T->img_rgb[0], T->img_rgb[1], T->img_rgb[2], 255); float sw = 30.f, sx = px + IMG_RIGHT_W - 14 - sw; - rb_fill_rrect(rb, sx, WS_Y + 5, sw, sw, 5, COL_PAINT_LINE); - rb_fill_rrect(rb, sx + 2, WS_Y + 7, sw - 4, sw - 4, 4, cc); + rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f, M3_OUTLINE_VAR); + rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f - 2, cc); } /* roda de matiz: linhas radiais coloridas */ @@ -1025,15 +996,15 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_stroke_circle(rb, mx_, my_, 5.f, 1.2f, COL_TEXT); } /* paleta rapida (3 x 4) */ - rb_text_c(rb, px + 12, img_pal_y(ed) - 14, "Paleta", COL_TEXT_DIM, 10.f); + rb_text_f(rb, px + 12, img_pal_y(ed) - 14, "Paleta", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM); for (int i = 0; i < 12; i++) { float sx, sy; img_swatch_rect(ed, i, &sx, &sy); bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx, sy, 34, 22); - rb_fill_rrect(rb, sx, sy, 34, 22, 4, COL_PAINT_LINE); - rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, 3, IMG_PALETTE[i]); - if (i == T->img_swatch) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 2.f, COL_MENU); - else if (hov) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 1.4f, COL_TEXT_DIM); + bool on = i == T->img_swatch; + if (on || hov) rb_fill_rrect(rb, sx - 2, sy - 2, 38, 26, M3_SHAPE_S, on ? M3_PRIMARY : M3_OUTLINE); + rb_fill_rrect(rb, sx, sy, 34, 22, M3_SHAPE_S - 2, on || hov ? M3_SURFACE : M3_OUTLINE_VAR); + rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, M3_SHAPE_S - 3, IMG_PALETTE[i]); } /* informacao da cor escolhida */ { @@ -1044,19 +1015,21 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* --- camadas: embaixo da roda de cores (como no Krita) --- */ rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14, - px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, COL_PAINT_LINE); - rb_text_c(rb, px + IMG_PAD, img_layers_title_y(ed), "Camadas", COL_TEXT_DIM, 11.f); + px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, M3_OUTLINE_VAR); + rb_icon(rb, px + IMG_PAD + 9, img_layers_title_y(ed), 0xe53b /* layers */, 18.f, M3_ON_SURFACE_VAR, false); + rb_text_f(rb, px + IMG_PAD + 24, img_layers_title_y(ed), "Camadas", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); for (int i = 0; i < T->img_layer_n; i++) { float rx, ry, rw, rh; img_layer_row(ed, i, &rx, &ry, &rw, &rh); bool sel = (i == T->img_layer_cur); bool hov = in_rect(ed->mouse_x, ed->mouse_y, rx, ry, rw, rh); - rb_fill_rrect(rb, rx, ry, rw, rh, 6, sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN)); - rb_stroke_rect(rb, rx, ry, rw, rh, 1.f, sel ? COL_MENU_DARK : COL_PAINT_LINE); - Col tc = sel ? COL_WHITE : COL_TEXT; + /* item de lista do M3; selecionado = container */ + if (sel) rb_fill_rrect(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_SECONDARY_CONTAINER); + m3_state(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_ON_SURFACE, hov, false); + Col tc = M3_ON_SURFACE; /* olho (visibilidade) */ - if (T->img_layers[i].visible) rb_fill_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, tc); - else rb_stroke_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, 1.4f, tc); + rb_icon(rb, rx + 11, ry + rh * 0.5f, T->img_layers[i].visible ? 0xe8f4 : 0xe8f5, 16.f, + M3_ON_SURFACE_VAR, false); /* miniatura (como uma fantasia do Scratch) */ { float tx = rx + 20, ty = ry + 4, tw_ = rw - 26, th_ = rh - 8; @@ -1076,17 +1049,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { } /* botoes: excluir / nova raster / nova vetor */ { - const char* labels[3] = { "- Camada", "+ Raster", "+ Vetor" }; - Col bgs[3] = { {236/255.f,120/255.f,110/255.f,1.f}, COL_MENU, COL_L_VECTOR }; + const char* labels[3] = { "Camada", "Raster", "Vetor" }; + static const unsigned icons[3] = { 0xe15b /* remove */, MI_ADD, MI_ADD }; + Col bgs[3] = { COL_STOP, M3_PRIMARY, COL_L_VECTOR }; for (int i = 0; i < 3; i++) { float bx2, by2, bw2, bh2; img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2); bool enabled = !(i == 0 && T->img_layer_n <= 1); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx2, by2, bw2, bh2); - Col bg = enabled ? (hov ? col_mul(bgs[i], 0.85f) : bgs[i]) : COL_PAINT_SHAD; - rb_fill_rrect(rb, bx2, by2, bw2, bh2, 6, bg); - rb_text_c(rb, bx2 + (bw2 - tw(labels[i], FS_UI-1)) * 0.5f, by2 + bh2 * 0.5f, - labels[i], COL_WHITE, FS_UI - 1); + m3_button(rb, i == 0 ? M3_OUTLINED : M3_TONAL, bx2, by2, bw2, bh2, labels[i], icons[i], + enabled ? bgs[i] : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false); } } } diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/include/tb_editor_widgets.h b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/include/tb_editor_widgets.h index 6c6e5b4..3ed45fa 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/include/tb_editor_widgets.h +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/include/tb_editor_widgets.h @@ -36,6 +36,15 @@ void tb_ew_line (TinyBlocks_RenderableBlock* rb, float x0, float y0, float void tb_ew_text_c (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs); /* Largura real do texto, medida pelo backend grafico */ float tb_ew_text_width(const char* s, float fs); +/* Texto numa fonte (TB_FONT_REGULAR / TB_FONT_MEDIUM), centrado em cy */ +void tb_ew_text_f (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs, + int font); +/* Icone do Material Symbols (codepoint, ex.: 0xE8B8 = settings) centrado em + * (cx, cy); size = lado do icone (24 no Material 3) */ +void tb_ew_icon (TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c, + bool filled); +/* Sombra de elevacao do Material 3 (level 1..5) atras de (x, y, w, h) */ +void tb_ew_shadow (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level); bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h); diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/src/tb_editor_widgets.c b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/src/tb_editor_widgets.c index 9bf75ad..558d31b 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/src/tb_editor_widgets.c +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-widgets/src/tb_editor_widgets.c @@ -40,5 +40,39 @@ float tb_ew_text_width(const char* s, float fs) { return tb_graphics_measure_text(s, fs); } +void tb_ew_text_f(TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs, + int font) { + if (!s || !s[0]) return; + tb_draw_text_font(rb, x, cy + fs * 0.36f, s, fs, font, c.r, c.g, c.b, c.a); +} + +void tb_ew_icon(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c, + bool filled) { + char u[5] = {0}; /* UTF-8 do codepoint (area privada: 3 bytes) */ + if (cp < 0x800) { u[0] = (char)(0xC0 | (cp >> 6)); u[1] = (char)(0x80 | (cp & 0x3F)); } + else if (cp < 0x10000) { + u[0] = (char)(0xE0 | (cp >> 12)); u[1] = (char)(0x80 | ((cp >> 6) & 0x3F)); + u[2] = (char)(0x80 | (cp & 0x3F)); + } else { + u[0] = (char)(0xF0 | (cp >> 18)); u[1] = (char)(0x80 | ((cp >> 12) & 0x3F)); + u[2] = (char)(0x80 | ((cp >> 6) & 0x3F)); u[3] = (char)(0x80 | (cp & 0x3F)); + } + /* o glifo ocupa 1 em acima da linha de base, avanco = 1 em */ + tb_draw_text_font(rb, cx - size * 0.5f, cy + size * 0.5f, u, size, + filled ? TB_FONT_ICON_FILLED : TB_FONT_ICON, c.r, c.g, c.b, c.a); +} + +void tb_ew_shadow(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level) { + if (level <= 0) return; + /* camadas cada vez maiores e mais fracas, puxadas para baixo (luz de cima) */ + float dy = 0.5f + level * 0.75f; + int n = 2 + level; + for (int i = n; i >= 1; i--) { + float g = (float)i; + float a = 0.10f / (float)n * (float)(n - i + 1) * (0.6f + 0.1f * level); + tb_draw_fill_rrect(rb, x - g * 0.5f, y - g * 0.5f + dy, w + g, h + g, rad + g * 0.5f, 0, 0, 0, a); + } +} + bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h) { return mx >= x && mx < x + w && my >= y && my < y + h; } diff --git a/libraries/tinyblocks-editor/src/tb_editor.c b/libraries/tinyblocks-editor/src/tb_editor.c index d5ebb03..2ac27e5 100644 --- a/libraries/tinyblocks-editor/src/tb_editor.c +++ b/libraries/tinyblocks-editor/src/tb_editor.c @@ -2335,7 +2335,7 @@ static void lay_default(Ed* ed) { int scr = lay_node(ed, LN_LEAF, -1, -1, V_SCRIPTS, 0, 0); int stg = lay_node(ed, LN_LEAF, -1, -1, V_STAGE, 0, 0); int out = lay_node(ed, LN_LEAF, -1, -1, V_OUTPUT, 0, 0); - int right = lay_node(ed, LN_VSPLIT, stg, out, -1, 0, STAGE_BAR_H + (STAGE_W - 16) * 0.75f + 8); + int right = lay_node(ed, LN_VSPLIT, stg, out, -1, 0, STAGE_TOP + (STAGE_W - 16) * 0.75f + 8); int mid = lay_node(ed, LN_HSPLIT, scr, right, -1, 1, STAGE_W); ed->lay_root = lay_node(ed, LN_HSPLIT, pal, mid, -1, 0, PALETTE_W); } @@ -2537,7 +2537,7 @@ static void area_set(Ed* ed, int v, float x, float y, float w, float h) { static void lay_compact(Ed* ed) { float y = MENU_H, h = WIN_H - MENU_H; if (ed->compact_view == CV_STAGE) { - float sh = STAGE_BAR_H + (WIN_W - 16) * 0.75f + 8; /* palco 4:3 na largura toda */ + float sh = STAGE_TOP + (WIN_W - 16) * 0.75f + 8; /* palco 4:3 na largura toda */ if (sh > h * 0.65f) sh = roundf(h * 0.65f); area_set(ed, V_STAGE, 0, y, WIN_W, sh); area_set(ed, V_OUTPUT, 0, y + sh, WIN_W, h - sh); @@ -2655,7 +2655,7 @@ static void rb_scale_from(TinyBlocks_RenderableBlock* rb, uint32_t first, float if (c->kind == TB_DRAW_STROKE_LINE) { /* w,h sao o segundo ponto */ c->w = ox + (c->w - ox) * s; c->h = oy + (c->h - oy) * s; } else { c->w *= s; c->h *= s; } - c->param *= s; + if (c->kind != TB_DRAW_TEXT) c->param *= s; /* no texto, param e a fonte */ c->font_size *= s; } } @@ -2696,7 +2696,7 @@ static void lay_swap(Ed* ed, int va, int vb) { } /* Alca do cabecalho de cada area (arrastar para trocar de lugar) */ -#define GRIP_S 18.f +#define GRIP_S 24.f static void grip_pos(Ed* ed, int v, float* gx, float* gy) { const AreaRect* A = &ed->area[v]; const ViewClass* vc = view_class(v); @@ -2725,7 +2725,7 @@ static int grip_at(Ed* ed, float mx, float my) { } /* Botao destacar/recolher do cabecalho (o palco usa o da barra dele) */ -#define DETACH_S 26.f +#define DETACH_S 32.f /* Largura da barra de abas (sem a alca e o botao destacar, que o compacto nao tem) */ static float tab_bar_w(Ed* ed) { @@ -2773,8 +2773,10 @@ static void draw_detach_btn(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { float bx, by; detach_btn_pos(ed, v, &bx, &by); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, DETACH_S, DETACH_S); - if (hov) rb_fill_rrect(rb, bx, by, DETACH_S, DETACH_S, 5, COL_HOVER); - draw_window_icon(rb, bx - 2, by, DETACH_S + 4, ed->area[v].detached, hov ? COL_MENU : COL_TEXT_DIM); + if (hov) rb_fill_circle(rb, bx + DETACH_S * 0.5f, by + DETACH_S * 0.5f, DETACH_S * 0.5f, + m3_alpha(M3_ON_SURFACE, M3_HOVER)); + rb_icon(rb, bx + DETACH_S * 0.5f, by + DETACH_S * 0.5f, ed->area[v].detached ? MI_CLOSE_FULLSCR : MI_OPEN_IN_NEW, + M3_ICON, M3_ON_SURFACE_VAR, false); char nm[64]; snprintf(nm, sizeof(nm), "%s a área %s", ed->area[v].detached ? "Recolher" : "Destacar", view_name(v)); ax_button(ed, nm, bx, by, DETACH_S, DETACH_S); @@ -2791,11 +2793,16 @@ static void draw_grip(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { tb_a11y_set_actions(ax(ed), ax_add(ed, TB_A11Y_BUTTON, nm, gx, gy, GRIP_S, GRIP_S), TB_A11Y_ACT_DRAG); } bool hov = ed->area_drag == v || in_rect(ed->mouse_x, ed->mouse_y, gx, gy, GRIP_S, GRIP_S); - if (hov) rb_fill_rrect(rb, gx - 2, gy - 2, GRIP_S + 4, GRIP_S + 4, 5, COL_HOVER); - Col c = hov ? COL_MENU : COL_TEXT_DIM; - for (int i = 0; i < 2; i++) - for (int j = 0; j < 3; j++) - rb_fill_circle(rb, gx + 6 + i * 6, gy + 3 + j * 6, 1.6f, c); + if (hov) rb_fill_rrect(rb, gx - 4, gy - 4, GRIP_S + 8, GRIP_S + 8, M3_SHAPE_S, m3_alpha(M3_ON_SURFACE, M3_HOVER)); + rb_icon(rb, gx + GRIP_S * 0.5f, gy + GRIP_S * 0.5f, MI_DRAG_INDICATOR, M3_ICON, M3_ON_SURFACE_VAR, false); +} + +/* Cabecalho de uma area: superficie, divisoria embaixo, titulo (Title Small) */ +static void area_header(Ed* ed, TinyBlocks_RenderableBlock* rb, float x, float y, float w, const char* title) { + (void)ed; + rb_fill_rect(rb, x, y, w, TAB_H, M3_SURFACE); + rb_fill_rect(rb, x, y + TAB_H - 1, w, 1, M3_OUTLINE_VAR); + rb_text_f(rb, x + 16, y + TAB_H * 0.5f, title, M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); } /* Primeira area (folha) de um no do layout, para dar nome as bordas */ @@ -3713,7 +3720,7 @@ static bool sb_import_text(Ed* ed, const char* text, const char* name) { } /* -- Previa da exportacao: o texto que vai para o forum --- */ -#define SBP_HEAD_H 46 +#define SBP_HEAD_H 60 #define SBP_FOOT_H 58 #define SBP_LINE_H 19 @@ -3753,18 +3760,16 @@ static int sbp_lines(const char* s) { static void sbp_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, const char* label, bool primary, bool hov) { - Col bg = primary ? (hov ? COL_MENU_DARK : COL_MENU) : (hov ? COL_HOVER : COL_PANEL); - if (!primary) rb_fill_rrect(rb, x, y, w, 34, 17, COL_BORDER); - rb_fill_rrect(rb, x + (primary ? 0 : 1), y + (primary ? 0 : 1), w - (primary ? 0 : 2), 34 - (primary ? 0 : 2), 16, bg); - rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + 17, label, primary ? COL_WHITE : COL_TEXT, FS_UI); + m3_button(rb, primary ? M3_FILLED : M3_TEXT, x, y, w, 36, label, primary ? MI_CONTENT_COPY : 0, + M3_PRIMARY, hov, false); } /* Botoes do rodape: 0 Copiar, 1 Salvar..., 2 Fechar (direita para esquerda) */ static void sbp_button_pos(Ed* ed, int i, float* bx, float* by, float* bw) { float x, y, w, h; sbp_geom(ed, &x, &y, &w, &h); - static const float widths[3] = { 150, 110, 100 }; - float r = x + w - 16; + static const float widths[3] = { 130, 110, 90 }; + float r = x + w - 24; for (int k = 0; k <= i; k++) { r -= widths[k]; if (k < i) r -= 10; } *bx = r; *by = y + h - SBP_FOOT_H + 12; *bw = widths[i]; } @@ -3773,19 +3778,17 @@ static void sbp_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!ed->sbp_open || !ed->sbp_text) return; float x, y, w, h; sbp_geom(ed, &x, &y, &w, &h); - rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120)); - rb_fill_rrect(rb, x + 3, y + 4, w, h, 12, COLA(0, 0, 0, 70)); - rb_fill_rrect(rb, x, y, w, h, 12, COL_PANEL); - rb_fill_rrect(rb, x, y, w, SBP_HEAD_H, 12, COL_MENU); - rb_fill_rect(rb, x, y + SBP_HEAD_H - 12, w, 12, COL_MENU); + m3_scrim(rb, WIN_W, WIN_H); + m3_dialog_surface(rb, x, y, w, h); char title[96]; snprintf(title, sizeof(title), "Prévia scratchblocks - %s", CT.name); - rb_text_c(rb, x + 18, y + SBP_HEAD_H * 0.5f, title, COL_WHITE, 17); + rb_icon(rb, x + 24 + 12, y + SBP_HEAD_H * 0.5f + 2, MI_IOS_SHARE, 24.f, M3_PRIMARY, false); + rb_text_f(rb, x + 24 + 24 + 12, y + SBP_HEAD_H * 0.5f + 2, title, M3_ON_SURFACE, M3_HEADLINE_S, TB_FONT_REGULAR); tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, title, x, y, w, h), TB_A11Y_MODAL); /* texto, numa area escura como a aba de codigo */ - float cx = x + 14, cy = y + SBP_HEAD_H + 12, cw = w - 28, ch = h - SBP_HEAD_H - SBP_FOOT_H - 18; - rb_fill_rrect(rb, cx, cy, cw, ch, 8, COLA(30, 30, 30, 255)); + float cx = x + 24, cy = y + SBP_HEAD_H + 8, cw = w - 48, ch = h - SBP_HEAD_H - SBP_FOOT_H - 14; + rb_fill_rrect(rb, cx, cy, cw, ch, M3_SHAPE_M, COL_CODE_BG); clip_set(ed, rb, cx + 4, cy + 4, cw - 8, ch - 8); tb_a11y_set_value(ax(ed), ax_add(ed, TB_A11Y_TEXT_FIELD, "scratchblocks", cx, cy, cw, ch), ed->sbp_text); int total = sbp_lines(ed->sbp_text); @@ -3822,7 +3825,7 @@ static void sbp_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* rodape */ char info[96]; snprintf(info, sizeof(info), "%d linhas - Copiar já inclui [scratchblocks]", total); - rb_text_c(rb, x + 18, y + h - SBP_FOOT_H * 0.5f, info, COL_TEXT_DIM, FS_SM); + rb_text_f(rb, x + 24, y + h - SBP_FOOT_H * 0.5f, info, M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR); static const char* labels[3] = { "Copiar", "Salvar...", "Fechar" }; for (int i = 0; i < 3; i++) { float bx, by, bw; @@ -3874,8 +3877,8 @@ static void sb_paste(Ed* ed) { * Diálogo modal "Criar um Bloco" (estilo Scratch) * === */ #define DLG_W 580 -#define DLG_H 344 -#define DLG_HEAD_H 50 +#define DLG_H 352 +#define DLG_HEAD_H 58 /* Geometria do protótipo: preenche comp_dialog_geom e devolve o retângulo */ static void dlg_geom(Ed* ed, float* bx, float* by, float* bw, float* bh) { @@ -4099,28 +4102,22 @@ static void dlg_ok(Ed* ed) { void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!ed->comp_dialog_open) return; - rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120)); + m3_scrim(rb, WIN_W, WIN_H); float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f; Col accent = s_user_colors[ed->comp_dialog_color]; Col dark = col_mul(accent, 0.78f); + float mx = ed->mouse_x, my = ed->mouse_y; - rb_fill_rrect(rb, dx + 3, dy + 4, DLG_W, DLG_H, 12, COLA(0, 0, 0, 70)); - rb_fill_rrect(rb, dx, dy, DLG_W, DLG_H, 12, COL_PANEL); - - /* Cabeçalho */ - rb_fill_rrect(rb, dx, dy, DLG_W, DLG_HEAD_H, 12, accent); - rb_fill_rect(rb, dx, dy + DLG_HEAD_H - 12, DLG_W, 12, accent); + /* dialogo do M3: superficie com canto XL, titulo (headline) a esquerda */ + m3_dialog_surface(rb, dx, dy, DLG_W, DLG_H); const char* title = ed->comp_dialog_def >= 0 ? "Editar Bloco" : "Criar um Bloco"; - rb_text_c(rb, dx + (DLG_W - tw(title, 18)) * 0.5f, dy + DLG_HEAD_H * 0.5f, title, COL_WHITE, 18); + rb_icon(rb, dx + 24 + 12, dy + 34, MI_EXTENSION, 24.f, accent, false); + rb_text_f(rb, dx + 24 + 24 + 12, dy + 34, title, M3_ON_SURFACE, M3_HEADLINE_S, TB_FONT_REGULAR); tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, title, dx, dy, DLG_W, DLG_H), TB_A11Y_MODAL); ax_button(ed, "Fechar", dx + DLG_W - 44, dy, 44, DLG_HEAD_H); - { /* fechar: um X desenhado */ - float qx = dx + DLG_W - 26, qy = dy + DLG_HEAD_H * 0.5f; - rb_fill_circle(rb, qx, qy, 12, COLA(255, 255, 255, 60)); - rb_line(rb, qx - 4.5f, qy - 4.5f, qx + 4.5f, qy + 4.5f, 2.f, COL_WHITE); - rb_line(rb, qx + 4.5f, qy - 4.5f, qx - 4.5f, qy + 4.5f, 2.f, COL_WHITE); - } + m3_icon_button(rb, dx + DLG_W - 30, dy + 34, MI_CLOSE, M3_ON_SURFACE_VAR, + in_rect(mx, my, dx + DLG_W - 44, dy, 44, DLG_HEAD_H), false); /* Protótipo do bloco */ float bx, by, bw, bh; @@ -4188,20 +4185,17 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (ed->comp_dialog_sel >= 0 && ed->comp_dialog_sel < ed->comp_dialog_part_n) { int si = ed->comp_dialog_sel; float ctr = bx + bw * 0.5f, cty = by - 26; - Col cl = si > 0 ? COL_TEXT : COL_BORDER; - Col cr = si + 1 < ed->comp_dialog_part_n ? COL_TEXT : COL_BORDER; + /* icon buttons: mover (apagados na ponta) e apagar */ + Col cl = si > 0 ? M3_ON_SURFACE_VAR : m3_alpha(M3_ON_SURFACE, 0.38f); + Col cr = si + 1 < ed->comp_dialog_part_n ? M3_ON_SURFACE_VAR : m3_alpha(M3_ON_SURFACE, 0.38f); ax_button(ed, "Mover para a esquerda", ctr - 60, cty - 16, 34, 32); ax_button(ed, "Mover para a direita", ctr + 26, cty - 16, 34, 32); - /* setas: mover a parte para a esquerda/direita (apagadas na ponta) */ - rb_line(rb, ctr - 38, cty - 6, ctr - 44, cty, 2.f, cl); - rb_line(rb, ctr - 44, cty, ctr - 38, cty + 6, 2.f, cl); - rb_line(rb, ctr + 38, cty - 6, ctr + 44, cty, 2.f, cr); - rb_line(rb, ctr + 44, cty, ctr + 38, cty + 6, 2.f, cr); + m3_icon_button(rb, ctr - 43, cty, MI_CHEVRON_LEFT, cl, si > 0 && in_rect(mx, my, ctr - 60, cty - 16, 34, 32), false); + m3_icon_button(rb, ctr + 43, cty, MI_CHEVRON_RIGHT, cr, + si + 1 < ed->comp_dialog_part_n && in_rect(mx, my, ctr + 26, cty - 16, 34, 32), false); if (dlg_part_deletable(ed, si)) { ax_button(ed, "Apagar a parte", ctr - 16, cty - 16, 32, 32); - rb_fill_rect(rb, ctr - 7, cty - 8, 14, 3, COL_TEXT); - rb_fill_rect(rb, ctr - 4, cty - 12, 8, 4, COL_TEXT); - rb_fill_rect(rb, ctr - 6, cty - 4, 12, 12, COL_TEXT); + m3_icon_button(rb, ctr, cty, MI_DELETE, M3_ON_SURFACE_VAR, in_rect(mx, my, ctr - 16, cty - 16, 32, 32), false); } } @@ -4222,8 +4216,10 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { "Adicionar entrada booleana", "Adicionar rótulo" }; ax_button(ed, names[i], cx, cy0, cw, ch); } - rb_fill_rrect(rb, cx, cy0, cw, ch, 8, hover ? COL_HOVER : COL_PANEL); - rb_stroke_rect(rb, cx + 0.5f, cy0 + 0.5f, cw - 1, ch - 1, 1, hover ? COL_MENU : COL_BORDER); + /* card "outlined" do M3 (canto M), camada de estado no hover */ + rb_fill_rrect(rb, cx, cy0, cw, ch, M3_SHAPE_M, M3_OUTLINE_VAR); + rb_fill_rrect(rb, cx + 1, cy0 + 1, cw - 2, ch - 2, M3_SHAPE_M - 1, M3_SURFACE); + m3_state(rb, cx, cy0, cw, ch, M3_SHAPE_M, accent, hover, false); float iy = cy0 + 14.f; if (i == 0) { /* um campo vazio, como a entrada no bloco */ rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 11, accent); @@ -4234,27 +4230,30 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 4, accent); rb_text_c(rb, cx + cw * 0.5f - 11, iy + 11, "text", COL_WHITE, FS); } - rb_text_c(rb, cx + (cw - tw(lines[i][0], FS)) * 0.5f, cy0 + 50.f, lines[i][0], COL_TEXT, FS); - rb_text_c(rb, cx + (cw - tw(lines[i][1], FS)) * 0.5f, cy0 + 66.f, lines[i][1], COL_TEXT_DIM, FS); + rb_text_f(rb, cx + (cw - m3_tw_m(lines[i][0], M3_TITLE_S)) * 0.5f, cy0 + 52.f, lines[i][0], + M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); + rb_text_f(rb, cx + (cw - tw(lines[i][1], M3_BODY_S)) * 0.5f, cy0 + 69.f, lines[i][1], + M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR); } - /* Cores + Cancelar/OK, separados do conteúdo por uma linha */ - rb_line(rb, dx + 1, dy + DLG_H - 62.f, dx + DLG_W - 1, dy + DLG_H - 62.f, 1.f, COL_BORDER); + /* Cores (amostras redondas, a escolhida com check) + Cancelar/OK */ float fy = dy + DLG_H - 42.f; for (int ci = 0; ci < USER_COLOR_COUNT; ci++) { float sx = dx + 28.f + ci * 30.f; - if (ed->comp_dialog_color == ci) rb_fill_rrect(rb, sx - 2, fy - 2, 26, 26, 6, COL_TEXT); - rb_fill_rrect(rb, sx, fy, 22, 22, 5, s_user_colors[ci]); + bool csel = ed->comp_dialog_color == ci; + if (csel) rb_fill_circle(rb, sx + 11, fy + 11, 14, s_user_colors[ci]); + if (csel) rb_fill_circle(rb, sx + 11, fy + 11, 12, M3_SURFACE); + rb_fill_circle(rb, sx + 11, fy + 11, csel ? 10 : 11, s_user_colors[ci]); + if (csel) rb_icon(rb, sx + 11, fy + 11, MI_CHECK, 16.f, COL_WHITE, false); char cn[16]; snprintf(cn, sizeof(cn), "Cor %d", ci + 1); tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_RADIO, cn, sx, fy, 22, 22), ed->comp_dialog_color == ci ? TB_A11Y_CHECKED : 0); } float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f; - rb_fill_rrect(rb, cax, fy - 8, 84, 36, 8, COL_BORDER); - rb_text_c(rb, cax + (84 - tw("Cancelar", FS_UI)) * 0.5f, fy + 10, "Cancelar", COL_TEXT, FS_UI); - rb_fill_rrect(rb, okx, fy - 8, 84, 36, 8, accent); - rb_text_c(rb, okx + (84 - tw("OK", FS_UI)) * 0.5f, fy + 10, "OK", COL_WHITE, FS_UI); + m3_button(rb, M3_TEXT, cax, fy - 8, 84, 36, "Cancelar", 0, col_mul(accent, 0.85f), + in_rect(mx, my, cax, fy - 8, 84, 36), false); + m3_button(rb, M3_FILLED, okx, fy - 8, 84, 36, "OK", 0, accent, in_rect(mx, my, okx, fy - 8, 84, 36), false); ax_button(ed, "Cancelar", cax, fy - 8, 84, 36); ax_button(ed, "OK", okx, fy - 8, 84, 36); ax_pop(ed); @@ -4358,18 +4357,40 @@ static void bubble_type_label(Ed* ed, TinyBlocks_RenderableBlock* rb, float bx, rb_text_c(rb, bx + 10, by + 12, ed->bubble_type, COL_TEXT_DIM, 10.f); } -static void menu_button(TinyBlocks_RenderableBlock* rb, float x, float w, const char* label, bool active) { - rb_fill_rrect(rb, x, MENU_BTN_Y, w, MENU_BTN_H, 6, active ? COL_MENU_DARK : COLA(255, 255, 255, 34)); - rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, MENU_H * 0.5f, label, COL_WHITE, FS_UI); +/* Janela destacada na barra: chip (contorno claro, icone de recolher) */ +static void menu_chip(TinyBlocks_RenderableBlock* rb, float x, float w, const char* nm, bool hov) { + float y = (MENU_H - 32) * 0.5f; + rb_fill_rrect(rb, x, y, w, 32, M3_SHAPE_S, COLA(255, 255, 255, 150)); + rb_fill_rrect(rb, x + 1, y + 1, w - 2, 30, M3_SHAPE_S - 1, COL_MENU); + m3_state(rb, x, y, w, 32, M3_SHAPE_S, COL_WHITE, hov, false); + rb_icon(rb, x + 8 + 9, MENU_H * 0.5f, MI_CLOSE_FULLSCR, 18.f, COL_WHITE, false); + rb_text_f(rb, x + 8 + 18 + 8, MENU_H * 0.5f, nm, COL_WHITE, M3_LABEL_L, TB_FONT_MEDIUM); +} + +/* Acao da top app bar: botao de texto com icone, conteudo on-primary; + ligado = container translucido (como um toggle tonal) */ +static void menu_button(TinyBlocks_RenderableBlock* rb, float x, float w, const char* label, unsigned icon, + bool active, bool hover) { + float r = MENU_BTN_H * 0.5f; + if (active) rb_fill_rrect(rb, x, MENU_BTN_Y, w, MENU_BTN_H, r, COLA(255, 255, 255, 46)); + m3_state(rb, x, MENU_BTN_Y, w, MENU_BTN_H, r, COL_WHITE, hover, false); + float cy = MENU_BTN_Y + MENU_BTN_H * 0.5f; + if (!label) { rb_icon(rb, x + w * 0.5f, cy, icon, 24.f, COL_WHITE, active); return; } + rb_icon(rb, x + 12.f + 9.f, cy, icon, 18.f, COL_WHITE, false); + rb_text_f(rb, x + 12.f + 18.f + 8.f, cy, label, COL_WHITE, M3_LABEL_L, TB_FONT_MEDIUM); } static const char* const s_menu_label[MB_COUNT] = { [MB_OPEN] = "Abrir", [MB_SAVE] = "Salvar", [MB_EXPORT] = "Exportar", [MB_LIBMAN] = "Bibliotecas", [MB_LIB] = "Carregar library...", [MB_CFG] = "Config", }; +static const unsigned s_menu_icon[MB_COUNT] = { + [MB_OPEN] = MI_FOLDER_OPEN, [MB_SAVE] = MI_SAVE, [MB_EXPORT] = MI_IOS_SHARE, + [MB_LIBMAN] = MI_LIBRARY_BOOKS, [MB_LIB] = MI_UPLOAD_FILE, [MB_CFG] = MI_SETTINGS, +}; -#define MENU_TITLE_FS 20 -#define MENU_GAP 6.f +#define MENU_TITLE_FS M3_TITLE_L +#define MENU_GAP 4.f /* Posicao dos botoes do menu para a largura atual. O que nao cabe sai na * ordem de drop_order (o titulo e o -1) e vai para o menu "☰", que fica na @@ -4379,18 +4400,19 @@ static void menu_layout(Ed* ed) { float right = WIN_W - 10; ed->menu_seg_w = 0; if (ed->compact) { - ed->menu_seg_w = tw("Código", FS_UI) + tw("Palco", FS_UI) + 40; + ed->menu_seg_w = m3_tw_m("Código", M3_LABEL_L) + m3_tw_m("Palco", M3_LABEL_L) + 48; ed->menu_seg_x = right - ed->menu_seg_w; right = ed->menu_seg_x - MENU_GAP - 40; /* bandeira */ } float chips = 0; /* janelas destacadas */ - for (int v = 0; v < V_COUNT; v++) if (ed->vwin[v]) chips += tw(view_name(v), FS_UI) + 48; + for (int v = 0; v < V_COUNT; v++) if (ed->vwin[v]) chips += m3_tw_m(view_name(v), M3_LABEL_L) + 50; for (int k = 0; k < TABWIN_MAX; k++) if (ed->twin[k].win && ed->twin[k].tab >= 0 && ed->twin[k].tab < ed->tab_n) - chips += tw(ed->tabs[ed->twin[k].tab].name, FS_UI) + 48; + chips += m3_tw_m(ed->tabs[ed->twin[k].tab].name, M3_LABEL_L) + 50; float w[MB_COUNT]; - for (int i = 0; i < MB_COUNT; i++) w[i] = tw(s_menu_label[i], FS_UI) + (i == MB_LIB ? 28 : 26); - float title_w = tw("TinyBlocks", MENU_TITLE_FS) + 22; + for (int i = 0; i < MB_COUNT; i++) /* 12 + icone 18 + 8 + rotulo + 16 */ + w[i] = i == MB_CFG ? MENU_MORE_W : m3_tw_m(s_menu_label[i], M3_LABEL_L) + 12 + 18 + 8 + 16; + float title_w = tw("TinyBlocks", MENU_TITLE_FS) + 24; static const int drop_order[] = { MB_LIB, MB_LIBMAN, MB_EXPORT, MB_CFG, -1, MB_SAVE, MB_OPEN }; bool shown[MB_COUNT], title = true; @@ -4404,10 +4426,10 @@ static void menu_layout(Ed* ed) { else { shown[drop_order[d]] = false; more = true; } } ed->menu_more = more; - float x = 10; + float x = 8; if (more) { ed->menu_more_x = x; x += MENU_MORE_W + MENU_GAP; } ed->menu_title = title; - ed->menu_title_x = more ? x + 4 : 18; + ed->menu_title_x = more ? x + 4 : 16; if (title) x = ed->menu_title_x + title_w; static const int left[] = { MB_OPEN, MB_SAVE, MB_EXPORT, MB_LIBMAN, MB_LIB }; for (size_t k = 0; k < sizeof(left) / sizeof(left[0]); k++) { @@ -4440,7 +4462,8 @@ static int hit_menu_seg(Ed* ed, float mx, float my) { static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_fill_rect(rb, 0, 0, WIN_W, MENU_H, COL_MENU); - if (ed->menu_title) rb_text_c(rb, ed->menu_title_x, MENU_H*0.5f, "TinyBlocks", COL_WHITE, MENU_TITLE_FS); + if (ed->menu_title) rb_text_f(rb, ed->menu_title_x, MENU_H*0.5f, "TinyBlocks", COL_WHITE, MENU_TITLE_FS, + TB_FONT_REGULAR); float mx = ed->mouse_x, my = ed->mouse_y; bool active = ed->path_input_active; const MenuBtn* B = ed->menu_btn; @@ -4456,41 +4479,46 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (ed->menu_more) { /* "☰": o que nao coube */ float bx = ed->menu_more_x; bool open = ed->ctx_menu_open && ed->ctx_more; - rb_fill_rrect(rb, bx, MENU_BTN_Y, MENU_MORE_W, MENU_BTN_H, 6, - open || hit_menu_more(ed, mx, my) ? COL_MENU_DARK : COLA(255, 255, 255, 34)); - for (int i = 0; i < 3; i++) - rb_fill_rrect(rb, bx + 11, MENU_H * 0.5f - 7 + i * 6, MENU_MORE_W - 22, 2.5f, 1, COL_WHITE); + m3_icon_button(rb, bx + MENU_MORE_W * 0.5f, MENU_H * 0.5f, MI_MENU, COL_WHITE, + hit_menu_more(ed, mx, my), open); tb_a11y_set_states(ax(ed), ax_button(ed, "Mais opções", bx, MENU_BTN_Y, MENU_MORE_W, MENU_BTN_H), open ? TB_A11Y_EXPANDED : 0); } for (int i = 0; i < MB_COUNT; i++) { if (!B[i].shown) continue; bool hov = hit_menu_btn(ed, i, mx, my); - if (i == MB_LIB) { /* estilo "link", sem moldura */ - if (hov || on[i]) rb_fill_rect(rb, B[i].x, 0, B[i].w, MENU_H, COL_MENU_DARK); - rb_text_c(rb, B[i].x + 14, MENU_H*0.5f, s_menu_label[i], COL_WHITE, FS_UI); - ax_button(ed, s_menu_label[i], B[i].x, 0, B[i].w, MENU_H); + if (i == MB_CFG) { /* icon button (engrenagem) */ + m3_icon_button(rb, B[i].x + B[i].w * 0.5f, MENU_H * 0.5f, MI_SETTINGS, COL_WHITE, hov, on[i]); + ax_button(ed, s_menu_label[i], B[i].x, MENU_BTN_Y, B[i].w, MENU_BTN_H); continue; } - menu_button(rb, B[i].x, B[i].w, s_menu_label[i], on[i] || hov); + menu_button(rb, B[i].x, B[i].w, s_menu_label[i], s_menu_icon[i], on[i], hov); int n = ax_button(ed, s_menu_label[i], B[i].x, MENU_BTN_Y, B[i].w, MENU_BTN_H); if (i == MB_EXPORT) tb_a11y_set_states(ax(ed), n, on[i] ? TB_A11Y_EXPANDED : 0); } if (ed->compact) { /* bandeira + Codigo|Palco */ float fx = ed->menu_seg_x - MENU_GAP - 40, fy = MENU_BTN_Y; bool fh = hit_menu_flag(ed, mx, my); - rb_fill_rrect(rb, fx, fy, 40, MENU_BTN_H, 6, fh || ed->vm_running ? COL_MENU_DARK : COLA(255, 255, 255, 34)); - rb_fill_rect(rb, fx + 13, fy + 5, 2, MENU_BTN_H - 10, COL_WHITE); - rb_fill_rrect(rb, fx + 15, fy + 5, 14, 10, 2, COL_FLAG); + rb_fill_circle(rb, fx + 20, MENU_H * 0.5f, 18, ed->vm_running ? COLA(255, 255, 255, 255) : COLA(255, 255, 255, 230)); + m3_state(rb, fx + 2, MENU_H * 0.5f - 18, 36, 36, 18, COL_FLAG, fh, false); + rb_icon(rb, fx + 20, MENU_H * 0.5f, MI_FLAG, 22.f, COL_FLAG, true); tb_a11y_set_states(ax(ed), ax_button(ed, "Executar", fx, fy, 40, MENU_BTN_H), ed->vm_running ? TB_A11Y_BUSY : 0); float sx = ed->menu_seg_x, sw = ed->menu_seg_w, half = sw * 0.5f; - rb_fill_rrect(rb, sx, fy, sw, MENU_BTN_H, MENU_BTN_H * 0.5f, COLA(255, 255, 255, 34)); + /* botao segmentado do M3: contorno em pilula, o segmento ligado cheio */ + rb_fill_rrect(rb, sx, fy, sw, MENU_BTN_H, MENU_BTN_H * 0.5f, COLA(255, 255, 255, 150)); + rb_fill_rrect(rb, sx + 1, fy + 1, sw - 2, MENU_BTN_H - 2, MENU_BTN_H * 0.5f - 1, COL_MENU); + rb_fill_rect(rb, sx + half - 0.5f, fy, 1, MENU_BTN_H, COLA(255, 255, 255, 150)); const char* nm[2] = { "Código", "Palco" }; for (int k = 0; k < 2; k++) { bool sel = ed->compact_view == (k ? CV_STAGE : CV_CODE); float hx = sx + k * half; - if (sel) rb_fill_rrect(rb, hx + 2, fy + 2, half - 4, MENU_BTN_H - 4, (MENU_BTN_H - 4) * 0.5f, COL_WHITE); - rb_text_c(rb, hx + (half - tw(nm[k], FS_UI)) * 0.5f, MENU_H * 0.5f, nm[k], sel ? COL_MENU : COL_WHITE, FS_UI); + if (sel) { + rb_fill_rrect(rb, hx + 1, fy + 1, half - 2, MENU_BTN_H - 2, (MENU_BTN_H - 2) * 0.5f, COL_WHITE); + if (k == 0) rb_fill_rect(rb, hx + half * 0.5f, fy + 1, half * 0.5f - 0.5f, MENU_BTN_H - 2, COL_WHITE); + else rb_fill_rect(rb, hx + 0.5f, fy + 1, half * 0.5f, MENU_BTN_H - 2, COL_WHITE); + } + rb_text_f(rb, hx + (half - m3_tw_m(nm[k], M3_LABEL_L)) * 0.5f, MENU_H * 0.5f, nm[k], + sel ? COL_MENU : COL_WHITE, M3_LABEL_L, TB_FONT_MEDIUM); tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_TAB, nm[k], hx, fy, half, MENU_BTN_H), sel ? TB_A11Y_SELECTED : 0); } @@ -4501,13 +4529,11 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { ed->chip_w[v] = 0; if (!ed->vwin[v]) continue; const char* nm = view_name(v); - float w = tw(nm, FS_UI) + 40; + float w = m3_tw_m(nm, M3_LABEL_L) + 8 + 18 + 8 + 16; cx -= w; ed->chip_x[v] = cx; ed->chip_w[v] = w; bool hov = in_rect(mx, my, cx, 7, w, MENU_H - 14); - rb_fill_rrect(rb, cx, 7, w, MENU_H - 14, 6, hov ? COL_MENU_DARK : COLA(255, 255, 255, 34)); - draw_window_icon(rb, cx + 2, 7 + (MENU_H - 14 - 22) * 0.5f, 22, true, COL_WHITE); - rb_text_c(rb, cx + 30, MENU_H * 0.5f, nm, COL_WHITE, FS_UI); + menu_chip(rb, cx, w, nm, hov); tb_a11y_set_description(ax(ed), ax_button(ed, nm, cx, 7, w, MENU_H - 14), "janela destacada: ative para recolher"); cx -= 8; @@ -4517,26 +4543,28 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { W->chip_w = 0; if (!W->win || W->tab < 0 || W->tab >= ed->tab_n) continue; const char* nm = ed->tabs[W->tab].name; - float w = tw(nm, FS_UI) + 40; + float w = m3_tw_m(nm, M3_LABEL_L) + 8 + 18 + 8 + 16; cx -= w; W->chip_x = cx; W->chip_w = w; bool hov = in_rect(mx, my, cx, 7, w, MENU_H - 14); - rb_fill_rrect(rb, cx, 7, w, MENU_H - 14, 6, hov ? COL_MENU_DARK : COLA(255, 255, 255, 34)); - draw_window_icon(rb, cx + 2, 7 + (MENU_H - 14 - 22) * 0.5f, 22, true, COL_WHITE); - rb_text_c(rb, cx + 30, MENU_H * 0.5f, nm, COL_WHITE, FS_UI); + menu_chip(rb, cx, w, nm, hov); tb_a11y_set_description(ax(ed), ax_button(ed, nm, cx, 7, w, MENU_H - 14), "aba destacada: ative para recolher"); cx -= 8; } if (ed->path_input_active) { - /* depois do ultimo botao a esquerda; sem espaco, cobre a barra toda */ + /* campo do M3 na barra: depois do ultimo botao a esquerda; sem + espaco, cobre a barra toda */ float bx = 10; for (int i = 0; i < MB_COUNT; i++) if (B[i].shown && i != MB_CFG) bx = fmaxf(bx, B[i].x + B[i].w + 10); float bw = (B[MB_CFG].shown ? B[MB_CFG].x - 10 : WIN_W - 16) - bx; if (bw < 220) { bx = 8; bw = WIN_W - 16; } - rb_fill_rrect(rb, bx, 7, bw, MENU_H-14, 6, COL_WHITE); + rb_fill_rrect(rb, bx, MENU_BTN_Y - 2, bw, MENU_BTN_H + 4, M3_SHAPE_XS, COL_WHITE); + rb_icon(rb, bx + 20, MENU_H * 0.5f, ed->path_mode == PM_LIB ? MI_UPLOAD_FILE : + ed->path_mode == PM_LOAD ? MI_FOLDER_OPEN : MI_SAVE, 20.f, M3_ON_SURFACE_VAR, false); + bx += 30; bw -= 30; const char* prompt = ed->path_mode == PM_LOAD ? "caminho do projeto .json (Enter abre, Esc cancela)" : ed->path_mode == PM_SAVE ? "caminho para salvar o projeto .json" : @@ -4658,34 +4686,38 @@ static void render_toasts(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (t->count > 1) snprintf(text, sizeof(text), "%s (x%d)", t->text, t->count); else scopy(text, sizeof(text), t->text); char lines[4][256]; - int nl = toast_wrap(text, maxw - 2*TOAST_PAD - 26.f, lines); + int nl = toast_wrap(text, maxw - 2*TOAST_PAD - 30.f - (t->ok ? 0.f : 32.f), lines); float tw_max = 0; - for (int l = 0; l < nl; l++) tw_max = fmaxf(tw_max, tw(lines[l], FS_UI)); - float w = fmaxf(220.f, tw_max + 2*TOAST_PAD + 30.f); + for (int l = 0; l < nl; l++) tw_max = fmaxf(tw_max, tw(lines[l], M3_BODY_M)); + float w = fmaxf(220.f, tw_max + 2*TOAST_PAD + 34.f + (t->ok ? 0.f : 32.f)); if (w > maxw) w = maxw; float h = nl * TOAST_LINE_H + 2*TOAST_PAD + 4.f; y -= h; t->x = right - w; t->y = y; t->w = w; t->h = h; + /* snackbar do M3: superficie inversa; erro com icone */ float a = t->left_ms < TOAST_FADE ? fmaxf(0.f, t->left_ms / TOAST_FADE) : 1.f; - Col bar = t->ok ? COL_MENU : COL_STOP; - Col bg = COL_PANEL, txt = COL_TEXT, dim = COL_TEXT_DIM, sh = COLA(0, 0, 0, 50), bd = COL_BORDER; - bar.a *= a; bg.a *= a; txt.a *= a; dim.a *= a; sh.a *= a; bd.a *= a; + Col bar = t->ok ? M3_INVERSE_PRIMARY : COL_STOP; + Col bg = M3_INVERSE_SURFACE, txt = M3_INVERSE_ON_SURFACE; + bar.a *= a; bg.a *= a; txt.a *= a; bool hov = toast_hit(t, ed->mouse_x, ed->mouse_y); - rb_fill_rrect(rb, t->x + 2, t->y + 3, w, h, 8, sh); - rb_fill_rrect(rb, t->x, t->y, w, h, 8, bd); - rb_fill_rrect(rb, t->x + 1, t->y + 1, w - 2, h - 2, 7, bg); - rb_fill_rrect(rb, t->x + 1, t->y + 1, 5, h - 2, 2.5f, bar); /* faixa da cor */ + if (a > 0.6f) rb_shadow(rb, t->x, t->y, w, h, M3_SHAPE_XS, 3); + rb_fill_rrect(rb, t->x, t->y, w, h, M3_SHAPE_XS, bg); + float lx = t->x + TOAST_PAD + 4; + if (!t->ok) { + Col ic = COL_STOP; ic.a *= a; + rb_icon(rb, t->x + 16 + 10, t->y + TOAST_PAD + 2 + TOAST_LINE_H * 0.5f, MI_ERROR, 20.f, ic, false); + lx = t->x + 16 + 20 + 12; + } for (int l = 0; l < nl; l++) - rb_text_c(rb, t->x + TOAST_PAD + 4, t->y + TOAST_PAD + 2 + TOAST_LINE_H * (l + 0.5f), - lines[l], txt, FS_UI); - /* fechar */ - float cx = t->x + w - 16.f, cy = t->y + 16.f; - bool xh = in_rect(ed->mouse_x, ed->mouse_y, cx - 9, cy - 9, 18, 18); - if (xh) { Col hc = COL_HOVER; hc.a *= a; rb_fill_circle(rb, cx, cy, 9, hc); } - rb_line(rb, cx - 4, cy - 4, cx + 4, cy + 4, 1.6f, xh ? txt : dim); - rb_line(rb, cx + 4, cy - 4, cx - 4, cy + 4, 1.6f, xh ? txt : dim); + rb_text_f(rb, lx, t->y + TOAST_PAD + 2 + TOAST_LINE_H * (l + 0.5f), + lines[l], txt, M3_BODY_M, TB_FONT_REGULAR); + /* fechar: icon button */ + float cx = t->x + w - 18.f, cy = t->y + 18.f; + bool xh = in_rect(ed->mouse_x, ed->mouse_y, cx - 11, cy - 11, 22, 22); + if (xh) rb_fill_circle(rb, cx, cy, 14, m3_alpha(txt, M3_HOVER * a)); + rb_icon(rb, cx, cy, MI_CLOSE, 20.f, txt, false); /* temporizador: barra que encolhe (para com o mouse em cima) */ int an = ax_push(ed, TB_A11Y_STATUS, t->text, t->x, t->y, w, h); if (!t->ok) tb_a11y_set_description(ax(ed), an, "erro"); /* o papel ja diz "aviso" */ @@ -4699,7 +4731,7 @@ static void render_toasts(Ed* ed, TinyBlocks_RenderableBlock* rb) { float k = t->total_ms > 0 ? fmaxf(0.f, t->left_ms / t->total_ms) : 0.f; Col tb = bar; if (hov) tb.a *= 0.45f; - rb_fill_rect(rb, t->x + 8, t->y + h - 5, (w - 16) * k, 2.5f, tb); + rb_fill_rect(rb, t->x + M3_SHAPE_XS, t->y + h - 2, (w - 2 * M3_SHAPE_XS) * k, 2.f, tb); /* tempo */ y -= 8.f; } } @@ -4710,7 +4742,7 @@ static bool toasts_click(Ed* ed, float mx, float my) { for (int i = 0; i < ed->toast_n; i++) { Toast* t = &ed->toasts[i]; if (!toast_hit(t, mx, my)) continue; - float cx = t->x + t->w - 16.f, cy = t->y + 16.f; + float cx = t->x + t->w - 18.f, cy = t->y + 18.f; if (in_rect(mx, my, cx - 11, cy - 11, 22, 22)) { toast_remove(ed, i); return true; } return false; } @@ -4720,7 +4752,9 @@ static bool toasts_click(Ed* ed, float mx, float my) { static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!AREA(V_SCRIPTS).shown) return; float y0 = AREA(V_SCRIPTS).y, x0 = WS_X, wbar = tab_bar_w(ed); /* sobra alca e botao */ - rb_fill_rect(rb, x0, y0, WS_W, TAB_H, COL_UI_BG); + /* abas primarias do M3: superficie, divisoria embaixo, indicador na ativa */ + rb_fill_rect(rb, x0, y0, WS_W, TAB_H, M3_SURFACE); + rb_fill_rect(rb, x0, y0 + TAB_H - 1, WS_W, 1, M3_OUTLINE_VAR); int dragged = ed->tab_drag ? ed->tab_press : -1; int vis[MAX_TABS], vn = tabs_visible_list(ed, vis); ax_push(ed, TB_A11Y_TAB_LIST, "Abas", x0, y0, wbar, TAB_H); @@ -4734,22 +4768,28 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) { tx = ed->mouse_x - ed->tab_grab_dx; if (tx < x0 + 4) tx = x0 + 4; if (tx > x0 + wbar - TAB_W) tx = x0 + wbar - TAB_W; - rb_fill_rrect(rb, tx + 2, y0 + 8, TAB_W - 4, TAB_H - 6, 8, COLA(0, 0, 0, 40)); + rb_shadow(rb, tx, y0 + 4, TAB_W - 4, TAB_H - 8, M3_SHAPE_S, 2); /* arrastada: elevada */ + rb_fill_rrect(rb, tx, y0 + 4, TAB_W - 4, TAB_H - 8, M3_SHAPE_S, M3_SURFACE); } bool cur = i == ed->cur_tab; - Col bg = cur ? COL_PANEL : COL_TAB_OFF; - rb_fill_rrect(rb, tx, y0+6, TAB_W-4, TAB_H-6, 8, bg); - rb_fill_rect(rb, tx, y0+TAB_H-8, TAB_W-4, 8, bg); - float cy = y0 + 6 + (TAB_H-6)*0.5f, lx = tx + 12; + bool hov = !ed->tab_drag && in_rect(ed->mouse_x, ed->mouse_y, tx, y0, TAB_W - 4, TAB_H - 1); + m3_state(rb, tx, y0, TAB_W - 4, TAB_H - 1, 0, M3_ON_SURFACE, hov, false); + Col fg = cur ? M3_PRIMARY : M3_ON_SURFACE_VAR; + float cy = y0 + TAB_H * 0.5f, lx = tx + 12; if (ed->tabs[i].is_composite) { - rb_fill_circle(rb, tx+14, cy, 5, s_user_colors[ed->tabs[i].color_idx]); - lx = tx + 24; + rb_fill_circle(rb, tx+20, cy, 6, s_user_colors[ed->tabs[i].color_idx]); + lx = tx + 34; } else if (tab_class(&ed->tabs[i])->icon && tab_class(&ed->tabs[i])->icon(rb, tx, cy)) { - lx = tx + 24; + lx = tx + 34; } clip_set(ed, rb, lx, y0, tx + TAB_W - 30 - lx, TAB_H); /* nome longo nao passa do X */ - rb_text_c(rb, lx, cy, ed->tabs[i].name, cur ? COL_MENU : COL_TEXT, FS_UI); + rb_text_f(rb, lx, cy, ed->tabs[i].name, fg, M3_TITLE_S, TB_FONT_MEDIUM); clip_clear(ed, rb); + if (cur) { + float iw = fminf(TAB_W - 20, m3_tw_m(ed->tabs[i].name, M3_TITLE_S) + (lx - tx - 12)); + if (iw < 24) iw = 24; + m3_tab_indicator(rb, tx + 12, y0 + TAB_H, iw, M3_PRIMARY); + } int an = ax_push(ed, TB_A11Y_TAB, ed->tabs[i].name, tx, y0 + 6, TAB_W - 4, TAB_H - 6); tb_a11y_set_point(ax(ed), an, tx + 14, cy); tb_a11y_set_states(ax(ed), an, cur ? TB_A11Y_SELECTED : 0); @@ -4758,17 +4798,18 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) { tb_a11y_set_description(ax(ed), an, tab_class(&ed->tabs[i])->name); if (ed->tab_n > 1 && ed->tabctx < 0) { /* fechar: um X desenhado */ float qx = tx + TAB_W - 18; - rb_line(rb, qx - 3.5f, cy - 3.5f, qx + 3.5f, cy + 3.5f, 1.5f, COL_TEXT_DIM); - rb_line(rb, qx + 3.5f, cy - 3.5f, qx - 3.5f, cy + 3.5f, 1.5f, COL_TEXT_DIM); + if (in_rect(ed->mouse_x, ed->mouse_y, tx + TAB_W - 28, y0 + 6, 24, TAB_H - 6)) + rb_fill_circle(rb, qx, cy, 12, m3_alpha(M3_ON_SURFACE, M3_HOVER)); + rb_icon(rb, qx, cy, MI_CLOSE, 18.f, M3_ON_SURFACE_VAR, false); ax_button(ed, "Fechar aba", tx + TAB_W - 28, y0 + 6, 24, TAB_H - 6); } ax_pop(ed); } float px = WS_X + 8 + vn*TAB_W; if (ed->tabctx < 0 && px + PLUS_W <= x0 + wbar && ed->tab_n < MAX_TABS) { - float pcy = y0 + 6 + (TAB_H-6)*0.5f; - if (ed->plus_menu_open) rb_fill_circle(rb, px+13, pcy, 12, COL_HOVER); - rb_text_c(rb, px+8, pcy, "+", ed->plus_menu_open ? COL_MENU : COL_TEXT, 18); + float pcy = y0 + TAB_H * 0.5f; + m3_icon_button(rb, px + PLUS_W * 0.5f, pcy, MI_ADD, ed->plus_menu_open ? M3_PRIMARY : M3_ON_SURFACE_VAR, + in_rect(ed->mouse_x, ed->mouse_y, px, y0, PLUS_W, TAB_H), ed->plus_menu_open); tb_a11y_set_states(ax(ed), ax_button(ed, "Nova aba", px, y0, PLUS_W, TAB_H), ed->plus_menu_open ? TB_A11Y_EXPANDED : 0); } @@ -4779,12 +4820,12 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) { static void render_categories(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!AREA(V_PALETTE).shown) return; /* cabecalho da paleta (alca para trocar de lugar) */ - rb_fill_rect(rb, PAL_X, AREA(V_PALETTE).y, AREA(V_PALETTE).w, TAB_H, COL_UI_BG); - rb_text_c(rb, PAL_X + 14, AREA(V_PALETTE).y + TAB_H * 0.5f, "Blocos", COL_TEXT_DIM, FS_UI); + area_header(ed, rb, PAL_X, AREA(V_PALETTE).y, AREA(V_PALETTE).w, "Blocos"); draw_grip(ed, rb, V_PALETTE); - rb_fill_rect(rb, PAL_X, PAL_Y, CAT_W, PAL_B-PAL_Y, COL_PANEL); - rb_line(rb, FLY_X-1, PAL_Y, FLY_X-1, PAL_B, 1.f, COL_BORDER); + /* navigation rail do M3: o "icone" de cada categoria e a bolinha da cor */ + rb_fill_rect(rb, PAL_X, PAL_Y, CAT_W, PAL_B-PAL_Y, M3_SURFACE); + rb_line(rb, FLY_X-1, PAL_Y, FLY_X-1, PAL_B, 1.f, M3_OUTLINE_VAR); float ih = cat_item_h(ed); int cur = current_cat(ed); float mid = PAL_X + CAT_W*0.5f; @@ -4792,15 +4833,18 @@ static void render_categories(Ed* ed, TinyBlocks_RenderableBlock* rb) { clip_set(ed, rb, PAL_X, PAL_Y, CAT_W - 1, PAL_B - PAL_Y - LIBMAN_BTN_H); for (int c = 0; c < ed->cat_n; c++) { float iy = PAL_Y + c*ih - ed->cat_scroll; - if (c == cur) rb_fill_rect(rb, PAL_X, iy, CAT_W-1, ih, COL_UI_BG); - /* compacta: circulo e rotulo menores quando a coluna aperta */ - float k = ih >= 48.f ? 1.f : ih / 48.f; - float r = 10.f * (k < 0.6f ? 0.6f : k), fs = ih >= 40.f ? 10.f : 9.f; - float cy = iy + ih*0.36f; - rb_fill_circle(rb, mid, cy, r, ed->cats[c].dark); - rb_fill_circle(rb, mid, cy, r - 1, ed->cats[c].col); - float w = tw(ed->cats[c].name, fs); - rb_text_c(rb, mid - w*0.5f, iy + ih*0.78f, ed->cats[c].name, COL_TEXT, fs); + /* compacta: indicador, bolinha e rotulo menores quando a coluna aperta */ + float k = ih >= 56.f ? 1.f : ih / 56.f; + float ph = 32.f * (k < 0.7f ? 0.7f : k), pw = fminf(52.f, CAT_W - 12.f); + float r = 8.f * (k < 0.85f ? 0.85f : k), fs = ih >= 48.f ? M3_LABEL_M : 11.f; + float py = iy + (ih - ph - fs - 4.f) * 0.5f, cy = py + ph * 0.5f; + bool hov = in_rect(ed->mouse_x, ed->mouse_y, PAL_X, iy, CAT_W - 1, ih); + if (c == cur) rb_fill_rrect(rb, mid - pw * 0.5f, py, pw, ph, ph * 0.5f, M3_SECONDARY_CONTAINER); + m3_state(rb, mid - pw * 0.5f, py, pw, ph, ph * 0.5f, M3_ON_SURFACE, hov, false); + rb_fill_circle(rb, mid, cy, r, ed->cats[c].col); + float w = m3_tw_m(ed->cats[c].name, fs); + rb_text_f(rb, mid - w*0.5f, py + ph + 4.f + fs * 0.5f, ed->cats[c].name, + c == cur ? M3_ON_SURFACE : M3_ON_SURFACE_VAR, fs, TB_FONT_MEDIUM); if (c == 0) ax_push(ed, TB_A11Y_TAB_LIST, "Categorias", PAL_X, PAL_Y, CAT_W, PAL_B - PAL_Y); bool off = iy < PAL_Y || iy + ih > PAL_B - LIBMAN_BTN_H; /* coluna rolada */ tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_TAB, ed->cats[c].name, PAL_X, iy, CAT_W - 1, ih), @@ -4811,19 +4855,20 @@ static void render_categories(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* Botao de buscar/adicionar library, no fim do painel (como o Scratch) */ float by = PAL_B - LIBMAN_BTN_H; bool hov = hit_libman_foot(ed, ed->mouse_x, ed->mouse_y); - rb_fill_rect(rb, PAL_X, by, CAT_W-1, LIBMAN_BTN_H, hov ? COL_LIBBTN_DARK : COL_LIBBTN); + /* FAB do M3 (canto L, elevacao 3) com a cor de sempre */ + rb_fill_rect(rb, PAL_X, by, CAT_W - 1, LIBMAN_BTN_H, M3_SURFACE); + float fs = 44.f, fx = mid - fs * 0.5f, fy = by + (LIBMAN_BTN_H - fs) * 0.5f; + rb_shadow(rb, fx, fy, fs, fs, M3_SHAPE_M, hov ? 4 : 3); + rb_fill_rrect(rb, fx, fy, fs, fs, M3_SHAPE_M, COL_LIBBTN); + m3_state(rb, fx, fy, fs, fs, M3_SHAPE_M, COL_WHITE, hov, false); + rb_icon(rb, mid, fy + fs * 0.5f, MI_LIBRARY_ADD, 24.f, COL_WHITE, false); ax_button(ed, "Adicionar extensão", PAL_X, by, CAT_W - 1, LIBMAN_BTN_H); - float cx = mid, 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) { if (!AREA(V_PALETTE).shown || FLY_R - FLY_X < 2) return; /* gaveta fechada */ - rb_fill_rect(rb, FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B-PAL_Y, COL_FLY); - rb_line(rb, FLY_R-1, PAL_Y, FLY_R-1, PAL_B, 1.f, COL_BORDER); + rb_fill_rect(rb, FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B-PAL_Y, M3_SURFACE_LOW); + rb_line(rb, FLY_R-1, PAL_Y, FLY_R-1, PAL_B, 1.f, M3_OUTLINE_VAR); clip_set(ed, rb, FLY_X, PAL_Y, FLY_R - FLY_X - 1, PAL_B-PAL_Y); float oy = PAL_Y - ed->fly_scroll; tb_a11y_set_actions(ax(ed), ax_push(ed, TB_A11Y_LIST, "Paleta", FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B - PAL_Y), @@ -4850,13 +4895,12 @@ static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (iy + it->h < PAL_Y || iy > PAL_B) continue; switch (it->kind) { case FI_HEADER: - rb_text_c(rb, FLY_X + FLY_PAD, iy + it->h*0.55f, ed->cats[it->cat].name, COL_TEXT, 14); + rb_text_f(rb, FLY_X + FLY_PAD, iy + it->h*0.55f, ed->cats[it->cat].name, M3_ON_SURFACE, + M3_TITLE_S, TB_FONT_MEDIUM); break; case FI_BUTTON: - rb_fill_rrect(rb, FLY_X + FLY_PAD, iy+4, FLY_BTN_W, 30, 6, COL_BORDER); - rb_fill_rrect(rb, FLY_X + FLY_PAD + 1, iy+5, FLY_BTN_W-2, 28, 5, COL_PANEL); - rb_text_c(rb, FLY_X + FLY_PAD + (FLY_BTN_W - tw("Criar um Bloco", FS_UI))*0.5f, - iy + 19, "Criar um Bloco", COL_TEXT, FS_UI); + m3_button(rb, M3_OUTLINED, FLY_X + FLY_PAD, iy + 2, FLY_BTN_W, 32, "Criar um Bloco", MI_ADD, + M3_PRIMARY, in_rect(ed->mouse_x, ed->mouse_y, FLY_X + FLY_PAD, iy + 2, FLY_BTN_W, 32), false); break; case FI_BLOCK: render_block(ed, rb, &ed->fly, it->bi, FLY_X, oy); @@ -5241,11 +5285,18 @@ void render_code_tab(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_line(rb, x0, y0 + barh, x0 + w, y0 + barh, 1.f, COL_TIP_BORDER); char title[320]; snprintf(title, sizeof(title), "%s", T->code_path[0] ? T->code_path : (T->name[0] ? T->name : "sem titulo")); - rb_text_c(rb, x0 + 10, y0 + barh * 0.5f, title, COL_CODE_TEXT, FS_UI - 2); - float lw = tw(T->code_lang, FS_UI - 2); - rb_fill_rrect(rb, x0 + w - lw - 26, y0 + 5, lw + 16, 20, 5, COL_TIP_BORDER); - rb_text_c(rb, x0 + w - lw - 18, y0 + barh * 0.5f, T->code_lang, COL_TIP_LINK, FS_UI - 2); - rb_text_c(rb, x0 + w - lw - 26 - 62, y0 + barh * 0.5f, "Salvar", COL_CODE_TEXT, FS_UI - 2); + rb_icon(rb, x0 + 10 + 9, y0 + barh * 0.5f, MI_DESCRIPTION, 18.f, COL_TEXT_DIM, false); + rb_text_f(rb, x0 + 34, y0 + barh * 0.5f, title, COL_CODE_TEXT, M3_BODY_S, TB_FONT_REGULAR); + /* linguagem: chip; Salvar: botao de texto com icone (tema escuro) */ + float lw = tw(T->code_lang, FS_UI - 2), mx = ed->mouse_x, my = ed->mouse_y; + float chx = x0 + w - lw - 26; + rb_fill_rrect(rb, chx, y0 + 4, lw + 16, 22, M3_SHAPE_S, COL_TIP_BORDER); + m3_state(rb, chx, y0 + 4, lw + 16, 22, M3_SHAPE_S, COL_WHITE, in_rect(mx, my, chx, y0, lw + 16, barh), false); + rb_text_f(rb, x0 + w - lw - 18, y0 + barh * 0.5f, T->code_lang, COL_TIP_LINK, FS_UI - 2, TB_FONT_MEDIUM); + float svx = x0 + w - lw - 26 - 62; + m3_state(rb, svx - 6, y0 + 4, 58, 22, 11, COL_WHITE, in_rect(mx, my, svx - 6, y0, 58, barh), false); + rb_icon(rb, svx + 4, y0 + barh * 0.5f, MI_SAVE, 14.f, COL_CODE_TEXT, false); + rb_text_f(rb, svx + 14, y0 + barh * 0.5f, "Salvar", COL_CODE_TEXT, FS_UI - 2, TB_FONT_MEDIUM); if (T->code_hl_dirty) code_rehighlight(T); @@ -5439,25 +5490,26 @@ void render_plus_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { plus_menu_pos(ed, &px, &py); const int n = PLUS_MENU_N; float h = 26 + n * PLUS_MENU_ITEM_H + 6; - rb_fill_rrect(rb, px - 2, py + 2, PLUS_MENU_W + 4, h + 4, 10, COLA(0,0,0,40)); - rb_fill_rrect(rb, px, py, PLUS_MENU_W, h, 8, COL_PANEL); - rb_stroke_rect(rb, px, py, PLUS_MENU_W, h, 1.f, COL_BORDER); - rb_text_c(rb, px + 12, py + 13, "Nova aba", COL_TEXT_DIM, 11.f); + m3_menu_surface(rb, px, py, PLUS_MENU_W, h); + rb_text_f(rb, px + 16, py + 15, "Nova aba", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM); const char* labels[PLUS_MENU_N] = { "Blueprint", "Novo bloco", "Edição de Imagem", "Editor de Código" }; const char* subs[PLUS_MENU_N] = { "folha em branco para scripts", "montar um bloco em Meus Blocos", "editar SVG/imagem", "editar .c/.py/..." }; static const Col dots[PLUS_MENU_N] = {{0.30f,0.62f,1.f,1.f}, {1.f,0.40f,0.50f,1.f}, {0.98f,0.62f,0.25f,1.f}, {0.42f,0.72f,0.35f,1.f}}; + static const unsigned icons[PLUS_MENU_N] = { MI_WIDGETS, MI_EXTENSION, MI_IMAGE, MI_CODE }; ax_push(ed, TB_A11Y_MENU, "Nova aba", px, py, PLUS_MENU_W, h); for (int i = 0; i < n; i++) { float iy = py + 26 + i * PLUS_MENU_ITEM_H; tb_a11y_set_description(ax(ed), ax_click(ed, TB_A11Y_MENU_ITEM, labels[i], px, iy, PLUS_MENU_W, PLUS_MENU_ITEM_H), subs[i]); bool hov = ed->plus_menu_hover == i; - if (hov) rb_fill_rrect(rb, px + 4, iy, PLUS_MENU_W - 8, PLUS_MENU_ITEM_H - 2, 6, COL_HOVER); - rb_fill_circle(rb, px + 20, iy + PLUS_MENU_ITEM_H * 0.5f - 1, 6, dots[i]); - rb_text_c(rb, px + 36, iy + 12, labels[i], COL_TEXT, FS_UI - 1); - rb_text_c(rb, px + 36, iy + 25, subs[i], COL_TEXT_DIM, 10.f); + m3_state(rb, px, iy, PLUS_MENU_W, PLUS_MENU_ITEM_H, 0, M3_ON_SURFACE, hov, false); + /* item de duas linhas: icone na cor do tipo de aba, rotulo e apoio */ + rb_fill_circle(rb, px + 16 + 16, iy + PLUS_MENU_ITEM_H * 0.5f, 18, m3_alpha(dots[i], 0.16f)); + rb_icon(rb, px + 16 + 16, iy + PLUS_MENU_ITEM_H * 0.5f, icons[i], M3_ICON, col_mul(dots[i], 0.85f), false); + rb_text_f(rb, px + 64, iy + 17, labels[i], M3_ON_SURFACE, M3_BODY_L - 1, TB_FONT_REGULAR); + rb_text_f(rb, px + 64, iy + 35, subs[i], M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR); } ax_pop(ed); } @@ -5466,11 +5518,11 @@ void render_plus_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { void render_tooltip(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!ed->tip_open) return; float x = ed->tip_x, y = ed->tip_y, w = ed->tip_w, h = ed->tip_h; - rb_fill_rrect(rb, x + 2, y + 3, w, h, 6, COLA(0,0,0,60)); - rb_fill_rrect(rb, x, y, w, h, 5, COL_TIP_BG); - rb_stroke_rect(rb, x, y, w, h, 1.f, COL_TIP_BORDER); + /* tooltip "rich" do M3 (superficie inversa: mostra codigo) */ + rb_shadow(rb, x, y, w, h, M3_SHAPE_M, 2); + rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_M, COL_TIP_BG); float ty = y + 12; - rb_text_c(rb, x + 12, ty, ed->tip_title, COL_CODE_TEXT, 12.f); + rb_text_f(rb, x + 12, ty, ed->tip_title, COL_CODE_TEXT, 12.f, TB_FONT_MEDIUM); ty += 18; rb_text_c(rb, x + 12, ty, ed->tip_loc, COL_TIP_LINK, 11.f); ty += 16; @@ -5518,10 +5570,7 @@ static bool code_tab_scroll(Ed* ed, float mx, float my, double dx, double dy) { return true; } static bool code_tab_icon(TinyBlocks_RenderableBlock* rb, float x, float cy) { - rb_fill_rrect(rb, x+9, cy-6, 11, 13, 2, COLA(42,74,110,255)); - rb_fill_rect(rb, x+11, cy-3, 6, 1.4f, COLA(120,190,255,255)); - rb_fill_rect(rb, x+11, cy+0, 6, 1.4f, COLA(120,190,255,255)); - rb_fill_rect(rb, x+11, cy+3, 4, 1.4f, COLA(120,190,255,255)); + rb_icon(rb, x + 21, cy, MI_CODE, 20.f, M3_ON_SURFACE_VAR, false); return true; } @@ -5557,8 +5606,7 @@ static bool image_tab_scroll(Ed* ed, float mx, float my, double dx, double dy) { return true; } static bool image_tab_icon(TinyBlocks_RenderableBlock* rb, float x, float cy) { - rb_fill_rrect(rb, x+9, cy-6, 12, 12, 2, COLA(200,150,60,255)); - rb_fill_circle(rb, x+13, cy-2, 2, COLA(255,235,180,255)); + rb_icon(rb, x + 21, cy, MI_IMAGE, 20.f, M3_ON_SURFACE_VAR, false); return true; } @@ -5907,22 +5955,21 @@ static void comp_panel_pos(Ed* ed, float* px, float* py) { static void render_comp_panel(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!CT.is_composite) return; float px, py; comp_panel_pos(ed, &px, &py); - rb_fill_rrect(rb, px, py, CP_W, CP_H, 8, COL_BORDER); - rb_fill_rrect(rb, px+1, py+1, CP_W-2, CP_H-2, 7, COL_PANEL); + /* barra flutuante do M3 (canto L, elevacao 2) */ + rb_shadow(rb, px, py, CP_W, CP_H, M3_SHAPE_L, 2); + rb_fill_rrect(rb, px, py, CP_W, CP_H, M3_SHAPE_L, M3_SURFACE); Col c = s_user_colors[CT.color_idx]; - rb_fill_rrect(rb, px+10, py+10, 24, 24, 6, col_mul(c, 0.8f)); - rb_fill_rrect(rb, px+11, py+11, 22, 22, 5, c); + rb_fill_circle(rb, px + 22, py + CP_H * 0.5f, 12, c); + rb_icon(rb, px + 22, py + CP_H * 0.5f, MI_EXTENSION, 16.f, COL_WHITE, false); const char* nm = ed->comp_name_buf[0] ? ed->comp_name_buf : "Novo bloco"; - rb_text_c(rb, px+44, py+CP_H*0.5f, nm, COL_TEXT, FS_UI); + rb_text_f(rb, px + 44, py + CP_H * 0.5f, nm, M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); - float bx = px + CP_W - 10; + float bx = px + CP_W - 10, mx = ed->mouse_x, my = ed->mouse_y; bx -= 78; - rb_fill_rrect(rb, bx, py+8, 78, 28, 6, c); - rb_text_c(rb, bx + (78 - tw("Salvar", FS_UI))*0.5f, py+CP_H*0.5f, "Salvar", COL_WHITE, FS_UI); + m3_button(rb, M3_FILLED, bx, py + 6, 78, 32, "Salvar", 0, c, in_rect(mx, my, bx, py + 6, 78, 32), false); bx -= 96; - rb_fill_rrect(rb, bx, py+8, 88, 28, 6, COL_BORDER); - rb_text_c(rb, bx + (88 - tw("Editar bloco", FS_UI))*0.5f, py+CP_H*0.5f, "Editar bloco", COL_TEXT, FS_UI); + m3_button(rb, M3_TONAL, bx, py + 6, 88, 32, "Editar", MI_EDIT, c, in_rect(mx, my, bx, py + 6, 88, 32), false); ax_push(ed, TB_A11Y_TOOLBAR, nm, px, py, CP_W, CP_H); ax_button(ed, "Editar bloco", bx, py + 8, 88, 28); ax_button(ed, "Salvar", bx + 96, py + 8, 78, 28); @@ -5934,35 +5981,35 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) { AreaRect A = AREA(V_STAGE); if (!A.shown) return; float sx = A.x, sy = A.y; - rb_fill_rect(rb, sx, sy, A.w, A.h, COL_UI_BG); + rb_fill_rect(rb, sx, sy, A.w, A.h, M3_SURFACE_CONTAINER); + rb_fill_rect(rb, sx, sy, A.w, STAGE_BAR_H, M3_SURFACE); + rb_fill_rect(rb, sx, sy + STAGE_BAR_H - 1, A.w, 1, M3_OUTLINE_VAR); - /* Bandeira verde */ - float fx = sx + 10, fy = sy + 6; - if (ed->flag_hover || ed->vm_running) rb_fill_rrect(rb, fx, fy, 40, 32, 6, COL_HOVER); - rb_fill_rect(rb, fx+13, fy+6, 2, 21, COL_FLAG_DARK); - rb_fill_rrect(rb, fx+15, fy+6, 15, 11, 2, COL_FLAG); - /* Parar */ - float tx = sx + 56; - if (ed->stop_hover) rb_fill_rrect(rb, tx, fy, 40, 32, 6, COL_HOVER); - draw_hex(rb, tx+10, fy+6, 20, 20, COL_STOP_DARK); - rb_fill_circle(rb, tx+20, fy+16, 9, COL_STOP); + /* Bandeira verde e parar: icon buttons (ligado = container tonal) */ + float fx = sx + 10, fy = sy + 4; + float scy = sy + STAGE_BAR_H * 0.5f, tx = sx + 56; + if (ed->vm_running) rb_fill_circle(rb, fx + 20, scy, M3_ICON_BTN * 0.5f, m3_alpha(COL_FLAG, 0.16f)); + if (ed->flag_hover) rb_fill_circle(rb, fx + 20, scy, M3_ICON_BTN * 0.5f, m3_alpha(COL_FLAG, M3_HOVER)); + rb_icon(rb, fx + 20, scy, MI_FLAG, 24.f, COL_FLAG, true); + if (ed->stop_hover) rb_fill_circle(rb, tx + 20, scy, M3_ICON_BTN * 0.5f, m3_alpha(COL_STOP, M3_HOVER)); + rb_icon(rb, tx + 20, scy, MI_STOP_CIRCLE, 24.f, COL_STOP, true); if (ed->compact || A.w >= 110 + tw("Palco", FS_UI) + 100) /* estreito: o rotulo daria na alca */ - rb_text_c(rb, sx + 110, sy + STAGE_BAR_H*0.5f, "Palco", COL_TEXT_DIM, FS_UI); + rb_text_f(rb, sx + 110, sy + STAGE_BAR_H*0.5f, "Palco", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM); tb_a11y_set_states(ax(ed), ax_button(ed, "Executar", fx, fy, 40, 32), ed->vm_running ? TB_A11Y_BUSY : 0); ax_button(ed, "Parar", tx, fy, 40, 32); draw_grip(ed, rb, V_STAGE); /* Destacar / recolher o palco */ if (ed->stage && !ed->compact) { float dx = sx + A.w - 50; - if (ed->detach_hover) rb_fill_rrect(rb, dx, fy, 40, 32, 6, COL_HOVER); - draw_window_icon(rb, dx, fy, 32, A.detached, COL_TEXT); + m3_icon_button(rb, dx + 20, sy + STAGE_BAR_H * 0.5f, A.detached ? MI_CLOSE_FULLSCR : MI_OPEN_IN_NEW, + M3_ON_SURFACE_VAR, ed->detach_hover, false); ax_button(ed, A.detached ? "Recolher o palco" : "Destacar o palco", dx, fy, 40, 32); } - float bx = sx + 8, by = sy + STAGE_BAR_H, bw = A.w - 16; - float ph = A.h - STAGE_BAR_H - 8; + float bx = sx + 8, by = sy + STAGE_TOP, bw = A.w - 16; + float ph = A.h - STAGE_TOP - 8; if (ed->stage && ph > 8) { - rb_fill_rrect(rb, bx, by, bw, ph, 8, COL_BORDER); + rb_fill_rrect(rb, bx, by, bw, ph, M3_SHAPE_M, M3_OUTLINE_VAR); TinyBlocks_RenderableBlock* sub = NULL; tb_stage_set_view(bw-2, ph-2); ax_add(ed, TB_A11Y_CANVAS, "Palco", bx + 1, by + 1, bw - 2, ph - 2); /* a vista do palco */ @@ -5979,11 +6026,12 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) { static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) { AreaRect A = AREA(V_OUTPUT); if (!A.shown) return; - rb_fill_rect(rb, A.x, A.y, A.w, A.h, COL_UI_BG); + rb_fill_rect(rb, A.x, A.y, A.w, A.h, M3_SURFACE_CONTAINER); float bx = A.x + 8, by = A.y, bw = A.w - 16; float bh = A.h - 8; - rb_fill_rrect(rb, bx, by, bw, bh, 8, COL_BORDER); - rb_fill_rrect(rb, bx+1, by+1, bw-2, bh-2, 7, COL_PANEL); + /* card "outlined" do M3 */ + rb_fill_rrect(rb, bx, by, bw, bh, M3_SHAPE_M, M3_OUTLINE_VAR); + rb_fill_rrect(rb, bx+1, by+1, bw-2, bh-2, M3_SHAPE_M - 1, M3_SURFACE); clip_set(ed, rb, bx+2, by+2, bw-4, bh-4); /* Monitores de variáveis */ @@ -6015,6 +6063,12 @@ static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) { const char* p = ed->stage_buf; for (int l = 0; *p; l++) { size_t n = strcspn(p, "\n"); + if (l < skip && l >= skip - 200) { /* rolada para cima: so na arvore */ + char line[128]; + size_t m = n < sizeof(line) - 1 ? n : sizeof(line) - 1; + memcpy(line, p, m); line[m] = 0; + tb_a11y_set_states(ax(ed), ax_add(ed, TB_A11Y_LABEL, line, bx + 12, by, bw - 24, 0), TB_A11Y_OFFSCREEN); + } if (l >= skip) { char line[128]; size_t m = n < sizeof(line) - 1 ? n : sizeof(line) - 1; @@ -6042,8 +6096,35 @@ static void render_output(Ed* ed, TinyBlocks_RenderableBlock* rb) { draw_grip(ed, rb, V_OUTPUT); } -#define CTX_ITEM_H 30 -#define CTX_W 190 +#define CTX_ITEM_H M3_MENU_ITEM +#define CTX_W 248 +#define CTX_PAD 8.f /* respiro em cima e embaixo da lista (M3) */ +static unsigned ctx_icon(int id) { + switch (id) { + case CM_DUPLICATE: return MI_CONTENT_COPY; + case CM_DELETE: return MI_DELETE; + case CM_EDIT_DEF: return MI_EDIT; + case CM_GROUP_NEW: return MI_ADD_BOX; + case CM_GROUP_STACK: return MI_SELECT; + case CM_GROUP_RENAME: return MI_TEXT_FIELDS; + case CM_GROUP_COLOR: return MI_PALETTE; + case CM_GROUP_DELETE: return MI_DELETE; + case CM_CLEANUP: return MI_GRID_VIEW; + case CM_NEW_COMPOSITE: return MI_ADD; + case CM_EXP_JSON: return MI_DATA_OBJECT; + case CM_EXP_XML: return MI_CODE; + case CM_EXP_CSV: return MI_TABLE; + case CM_EXP_SB: return MI_IOS_SHARE; + case CM_PASTE_SB: return MI_CONTENT_PASTE; + case CM_MB_OPEN: return MI_FOLDER_OPEN; + case CM_MB_SAVE: return MI_SAVE; + case CM_MB_EXPORT: return MI_IOS_SHARE; + case CM_MB_LIBMAN: return MI_LIBRARY_BOOKS; + case CM_MB_LIB: return MI_UPLOAD_FILE; + case CM_MB_CFG: return MI_SETTINGS; + default: return 0; + } +} static const char* ctx_label(int id) { switch (id) { case CM_DUPLICATE: return "Duplicar"; @@ -6063,7 +6144,7 @@ static const char* ctx_label(int id) { case CM_PASTE_SB: return "Colar scratchblocks"; case CM_MB_OPEN: return "Abrir projeto..."; case CM_MB_SAVE: return "Salvar projeto..."; - case CM_MB_EXPORT: return "Exportar >"; + case CM_MB_EXPORT: return "Exportar"; case CM_MB_LIBMAN: return "Bibliotecas"; case CM_MB_LIB: return "Carregar library..."; case CM_MB_CFG: return "Configurações"; @@ -6072,7 +6153,7 @@ static const char* ctx_label(int id) { } static void ctx_pos(Ed* ed, float* x, float* y) { - float mh = ed->ctx_n*CTX_ITEM_H + 8; + float mh = ed->ctx_n*CTX_ITEM_H + 2*CTX_PAD; *x = ed->ctx_menu_x; *y = ed->ctx_menu_y; if (*x + CTX_W > WIN_W) *x = WIN_W - CTX_W; if (*y + mh > WIN_H) *y = WIN_H - mh; @@ -6080,27 +6161,49 @@ static void ctx_pos(Ed* ed, float* x, float* y) { static int ctx_hit(Ed* ed, float mx, float my) { float x, y; ctx_pos(ed, &x, &y); - if (!in_rect(mx, my, x, y+4, CTX_W, ed->ctx_n*CTX_ITEM_H)) return -1; - return (int)((my - y - 4) / CTX_ITEM_H); + if (!in_rect(mx, my, x, y+CTX_PAD, CTX_W, ed->ctx_n*CTX_ITEM_H)) return -1; + return (int)((my - y - CTX_PAD) / CTX_ITEM_H); } static void render_ctx_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!ed->ctx_menu_open) return; float x, y; ctx_pos(ed, &x, &y); - float mh = ed->ctx_n*CTX_ITEM_H + 8; - rb_fill_rrect(rb, x+2, y+3, CTX_W, mh, 6, COLA(0,0,0,40)); - rb_fill_rrect(rb, x, y, CTX_W, mh, 6, COL_BORDER); - rb_fill_rrect(rb, x+1, y+1, CTX_W-2, mh-2, 5, COL_PANEL); + float mh = ed->ctx_n*CTX_ITEM_H + 2*CTX_PAD; + m3_menu_surface(rb, x, y, CTX_W, mh); ax_push(ed, TB_A11Y_MENU, "Menu de contexto", x, y, CTX_W, mh); for (int i = 0; i < ed->ctx_n; i++) { - float iy = y + 4 + i*CTX_ITEM_H; - if (ed->ctx_menu_hover == i) rb_fill_rect(rb, x+1, iy, CTX_W-2, CTX_ITEM_H, COL_UI_BG); - rb_text_c(rb, x+14, iy + CTX_ITEM_H*0.5f, ctx_label(ed->ctx_items[i]), COL_TEXT, FS_UI); + float iy = y + CTX_PAD + i*CTX_ITEM_H; + int id = ed->ctx_items[i]; + bool danger = id == CM_DELETE || id == CM_GROUP_DELETE; + m3_menu_item(rb, x, iy, CTX_W, CTX_ITEM_H, ctx_label(id), ctx_icon(id), ed->ctx_menu_hover == i, + danger ? COL_ERR_TEXT : M3_ON_SURFACE); + if (id == CM_MB_EXPORT) /* submenu: seta no fim */ + rb_icon(rb, x + CTX_W - 12 - 10, iy + CTX_ITEM_H * 0.5f, MI_ARROW_RIGHT, M3_ICON, M3_ON_SURFACE_VAR, false); ax_click(ed, TB_A11Y_MENU_ITEM, ctx_label(ed->ctx_items[i]), x, iy, CTX_W, CTX_ITEM_H); } ax_pop(ed); } +/* Top app bar das telas cheias (Bibliotecas, Configuracoes): seta de + voltar (icon button) e titulo Title Large; "Voltar" ocupa 0..170 */ +static void fs_header(Ed* ed, TinyBlocks_RenderableBlock* rb, const char* title, float head_h) { + rb_fill_rect(rb, 0, 0, WIN_W, head_h, COL_MENU); + bool hov = in_rect(ed->mouse_x, ed->mouse_y, 0, 0, 170, head_h); + m3_icon_button(rb, 16 + 20, head_h * 0.5f, MI_ARROW_BACK, COL_WHITE, hov, false); + rb_text_f(rb, 16 + 40 + 16, head_h * 0.5f, title, COL_WHITE, M3_TITLE_L, TB_FONT_REGULAR); +} + +/* Caixa de selecao do M3 (18 px, canto 2) */ +static void m3_checkbox(TinyBlocks_RenderableBlock* rb, float x, float y, bool on) { + if (on) { + rb_fill_rrect(rb, x, y, 18, 18, 2, M3_PRIMARY); + rb_icon(rb, x + 9, y + 9, MI_CHECK, 16.f, M3_ON_PRIMARY, false); + } else { + rb_fill_rrect(rb, x, y, 18, 18, 2, M3_ON_SURFACE_VAR); + rb_fill_rrect(rb, x + 2, y + 2, 14, 14, 1, M3_SURFACE); + } +} + /* === * Gestor de libraries (tinyblocks-libman) - UI do editor * === */ @@ -6109,8 +6212,8 @@ static void render_ctx_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) { #define LM_MARGIN (LM_NARROW ? 12 : 40) #define LM_CARD_H 190 #define LM_CARD_GAP 24 -#define LM_CHIP_H 34 -#define LM_CHIP_GAP 10 +#define LM_CHIP_H 32 +#define LM_CHIP_GAP 8 #define LM_SEARCH_W (LM_NARROW ? WIN_W - 2*LM_MARGIN : 340) #define LM_COLS (LM_NARROW ? 1 : 2) #define LM_CARD_W ((WIN_W - 2*LM_MARGIN - (LM_COLS - 1)*LM_CARD_GAP) / LM_COLS) @@ -6159,7 +6262,8 @@ static float libman_chip_layout(Ed* ed, float rects[][4]) { float x0 = LM_NARROW ? LM_MARGIN : LM_MARGIN + LM_SEARCH_W + 24; float x = x0, y = LM_HEAD_H + 14 + (LM_NARROW ? 44 + LM_CHIP_GAP : 0), rowmax = y; for (int i = 0; i < n; i++) { - float w = tw(labels[i], FS_UI) + 28; + bool sel = (i == 0) ? (ed->libman_filter < 0) : (ed->libman_filter == i-1); + float w = m3_tw_m(labels[i], M3_LABEL_L) + (sel ? 8 + 18 + 8 + 12 : 24); /* ligado: check */ if (x + w > WIN_W - LM_MARGIN) { x = x0; y += LM_CHIP_H + LM_CHIP_GAP; } if (rects) { rects[i][0] = x; rects[i][1] = y; rects[i][2] = w; rects[i][3] = LM_CHIP_H; } x += w + LM_CHIP_GAP; @@ -6179,33 +6283,27 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { float gridY = libman_grid_y(ed); /* Fundo */ - rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COL_UI_BG); + rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, M3_SURFACE_CONTAINER); /* Cabeçalho */ - rb_fill_rect(rb, 0, 0, WIN_W, LM_HEAD_H, COL_MENU); - float bx = fmaxf(LM_MARGIN, 28), by = LM_HEAD_H*0.5f; - rb_fill_circle(rb, bx, by, 16, COLA(255,255,255,40)); - rb_line(rb, bx+4, by-7, bx-5, by, 2.f, COL_WHITE); - rb_line(rb, bx-5, by, bx+4, by+7, 2.f, COL_WHITE); - rb_text_c(rb, bx + 28, by, "Voltar", COL_WHITE, FS_UI); { const char* t = "Escolha uma Extensão"; - float tx = fmaxf((WIN_W - tw(t, 20))*0.5f, bx + 28 + tw("Voltar", FS_UI) + 20); /* nao cobre o Voltar */ - rb_text_c(rb, tx, by, t, COL_WHITE, 20); + fs_header(ed, rb, t, LM_HEAD_H); tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, t, 0, 0, WIN_W, WIN_H), TB_A11Y_MODAL); ax_button(ed, "Voltar", 0, 0, 170, LM_HEAD_H); } - /* Barra de filtros */ + /* Barra de filtros: busca (search bar do M3) e chips de filtro */ float fh = libman_chip_layout(ed, NULL); - rb_fill_rect(rb, 0, LM_HEAD_H, WIN_W, fh, COL_PANEL); + rb_fill_rect(rb, 0, LM_HEAD_H, WIN_W, fh, M3_SURFACE); + rb_fill_rect(rb, 0, LM_HEAD_H + fh - 1, WIN_W, 1, M3_OUTLINE_VAR); float sx = LM_MARGIN, sy = LM_HEAD_H + 14; - rb_fill_rrect(rb, sx, sy, LM_SEARCH_W, 44, 22, COL_UI_BG); - if (ed->libman_search_focus) rb_stroke_rect(rb, sx-1, sy-1, LM_SEARCH_W+2, 46, 2.f, COL_MENU); + m3_search_bar(rb, sx, sy, LM_SEARCH_W, 44, ed->libman_search_focus, M3_PRIMARY); { const char* t = ed->libman_query[0] ? ed->libman_query : "Buscar"; - rb_text_c(rb, sx + 16, sy + 22, t, - ed->libman_query[0] ? COL_TEXT : COL_TEXT_DIM, FS_UI); + rb_text_f(rb, sx + 52, sy + 22, t, + ed->libman_query[0] ? M3_ON_SURFACE : M3_ON_SURFACE_VAR, M3_BODY_L, TB_FONT_REGULAR); if (ed->libman_search_focus) - te_draw(ed, rb, ed->libman_query, sizeof(ed->libman_query), false, sx + 16, sy + 22, 22, FS_UI, COL_TEXT); + te_draw(ed, rb, ed->libman_query, sizeof(ed->libman_query), false, sx + 52, sy + 22, 22, M3_BODY_L, + M3_PRIMARY); ax_field(ed, "Buscar", ed->libman_query, ed->libman_search_focus, sx, sy, LM_SEARCH_W, 44); } { @@ -6215,17 +6313,15 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { libman_chip_layout(ed, rects); for (int i = 0; i < n; i++) { bool sel = (i == 0) ? (ed->libman_filter < 0) : (ed->libman_filter == i-1); - rb_fill_rrect(rb, rects[i][0], rects[i][1], rects[i][2], rects[i][3], 17, - sel ? COL_MENU : COL_UI_BG); - rb_text_c(rb, rects[i][0] + 14, rects[i][1] + LM_CHIP_H*0.5f, labels[i], - sel ? COL_WHITE : COL_TEXT, FS_UI); + bool hov = in_rect(ed->mouse_x, ed->mouse_y, rects[i][0], rects[i][1], rects[i][2], rects[i][3]); + m3_chip(rb, rects[i][0], rects[i][1], rects[i][2], rects[i][3], labels[i], sel ? MI_CHECK : 0, sel, hov); tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_RADIO, labels[i], rects[i][0], rects[i][1], rects[i][2], rects[i][3]), sel ? TB_A11Y_CHECKED : 0); } } /* Grade de cartoes (com recorte e rolagem) */ - rb_fill_rect(rb, 0, gridY, WIN_W, WIN_H - gridY, COL_UI_BG); + rb_fill_rect(rb, 0, gridY, WIN_W, WIN_H - gridY, M3_SURFACE_CONTAINER); clip_set(ed, rb, 0, gridY, WIN_W, WIN_H - gridY); ax_push(ed, TB_A11Y_LIST, "Libraries", 0, gridY, WIN_W, WIN_H - gridY); for (int k = 0; k < nh; k++) { @@ -6237,18 +6333,25 @@ void libman_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { const TbLibmanEntry* e = tb_libman_entry(hits[k]); if (!e) continue; Col c = { e->color[0]/255.f, e->color[1]/255.f, e->color[2]/255.f, 1.f }; - rb_fill_rrect(rb, x, y, LM_CARD_W, LM_CARD_H, 8, COL_PANEL); - rb_fill_rrect(rb, x, y, LM_CARD_W, 56, 8, c); + /* card "elevated" do M3 (canto M): faixa da cor da categoria em cima */ + bool hov = ed->libman_hover == k; + rb_shadow(rb, x, y, LM_CARD_W, LM_CARD_H, M3_SHAPE_M, hov ? 2 : 1); + rb_fill_rrect(rb, x, y, LM_CARD_W, LM_CARD_H, M3_SHAPE_M, M3_SURFACE); + rb_fill_rrect(rb, x, y, LM_CARD_W, 56, M3_SHAPE_M, c); rb_fill_rect(rb, x, y + 40, LM_CARD_W, 16, c); - rb_text_c(rb, x + 16, y + 28, e->category, COL_WHITE, FS_UI); - rb_text_c(rb, x + 16, y + 84, e->name, COL_TEXT, 18); - rb_text_c(rb, x + 16, y + 114, e->description, COL_TEXT_DIM, FS_UI); - rb_text_c(rb, x + 16, y + LM_CARD_H - 22, e->shared, COL_TEXT_DIM, FS_SM); - if (tb_libman_loaded(hits[k])) { - rb_fill_circle(rb, x + LM_CARD_W - 24, y + 28, 8, COL_FLAG); - rb_text_c(rb, x + LM_CARD_W - 110, y + LM_CARD_H - 22, "carregada", COL_FLAG, FS_SM); + rb_icon(rb, x + 16 + 12, y + 28, MI_EXTENSION, 24.f, COL_WHITE, false); + rb_text_f(rb, x + 16 + 24 + 12, y + 28, e->category, COL_WHITE, M3_TITLE_M, TB_FONT_MEDIUM); + rb_text_f(rb, x + 16, y + 84, e->name, M3_ON_SURFACE, M3_TITLE_L, TB_FONT_REGULAR); + rb_text_f(rb, x + 16, y + 114, e->description, M3_ON_SURFACE_VAR, M3_BODY_M, TB_FONT_REGULAR); + rb_text_f(rb, x + 16, y + LM_CARD_H - 22, e->shared, M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR); + if (tb_libman_loaded(hits[k])) { /* chip "carregada" */ + const char* lt = "carregada"; + float cw2 = m3_tw_m(lt, M3_LABEL_L) + 8 + 18 + 8 + 12, cx2 = x + LM_CARD_W - 16 - cw2; + rb_fill_rrect(rb, cx2, y + LM_CARD_H - 38, cw2, 32, M3_SHAPE_S, m3_mix(M3_SURFACE, COL_FLAG, 0.16f)); + rb_icon(rb, cx2 + 8 + 9, y + LM_CARD_H - 22, MI_CHECK_CIRCLE, 18.f, COL_FLAG_DARK, true); + rb_text_f(rb, cx2 + 8 + 18 + 8, y + LM_CARD_H - 22, lt, COL_FLAG_DARK, M3_LABEL_L, TB_FONT_MEDIUM); } - if (ed->libman_hover == k) rb_stroke_rect(rb, x-1, y-1, LM_CARD_W+2, LM_CARD_H+2, 2.f, COL_MENU); + m3_state(rb, x, y, LM_CARD_W, LM_CARD_H, M3_SHAPE_M, M3_ON_SURFACE, hov, false); int an = ax_click(ed, TB_A11Y_LIST_ITEM, e->name, x, y, LM_CARD_W, LM_CARD_H); tb_a11y_set_description(ax(ed), an, e->description); tb_a11y_set_value(ax(ed), an, tb_libman_loaded(hits[k]) ? "carregada" : ""); @@ -6382,7 +6485,9 @@ static void settings_close(Ed* ed) { ed->settings_path_focus = false; } -static float settings_btn_w(int i) { return i == 1 ? 150.f : 96.f; } +static float settings_btn_w(int i) { + return m3_button_w(i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "Nova", MI_ADD); +} static void settings_btn_rect(Ed* ed, int i, float* x, float* y, float* w, float* h) { float gap = 12.f, cur = WIN_W - ST_MARGIN; @@ -6397,12 +6502,6 @@ static void settings_path_rect(Ed* ed, float* x, float* y, float* w, float* h) { if (ST_NARROW) { *y = ST_TOOL_Y + 12.f; *w = WIN_W - 2.f * ST_MARGIN; } } -static void st_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, - const char* label, bool active) { - rb_fill_rrect(rb, x, y, w, h, 6, active ? COL_MENU_DARK : COL_MENU); - rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_WHITE, FS_UI); -} - static void settings_export(Ed* ed, const char* path) { if (!path || !path[0]) path = ed->settings_path; bool ok = tb_environ_export_csv_meta(path, "arquivo_config", path); @@ -6424,32 +6523,21 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (!ed->settings_open) return; int n = tb_environ_count(); - rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COL_UI_BG); + rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, M3_SURFACE_CONTAINER); /* Cabecalho */ - rb_fill_rect(rb, 0, 0, WIN_W, ST_HEAD_H, COL_MENU); - float bx = ST_MARGIN, by = ST_HEAD_H * 0.5f; - rb_fill_circle(rb, bx, by, 16, COLA(255,255,255,40)); - rb_line(rb, bx+4, by-7, bx-5, by, 2.f, COL_WHITE); - rb_line(rb, bx-5, by, bx+4, by+7, 2.f, COL_WHITE); - rb_text_c(rb, bx + 28, by, "Voltar", COL_WHITE, FS_UI); { const char* t = "Configurações"; - rb_text_c(rb, (WIN_W - tw(t, 20)) * 0.5f, by, t, COL_WHITE, 20); + fs_header(ed, rb, t, ST_HEAD_H); tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, t, 0, 0, WIN_W, WIN_H), TB_A11Y_MODAL); ax_button(ed, "Voltar", 0, 0, 170, ST_HEAD_H); } /* Opcoes: toggle de deteccao do caminho pela variavel de ambiente */ - rb_fill_rect(rb, 0, ST_OPT_Y, WIN_W, ST_OPT_H, COL_FLY); + rb_fill_rect(rb, 0, ST_OPT_Y, WIN_W, ST_OPT_H, M3_SURFACE); { - float cb = ST_OPT_Y + (ST_OPT_H - 20) * 0.5f; - rb_fill_rrect(rb, ST_MARGIN, cb, 20, 20, 4, - ed->settings_use_env ? COL_MENU : COL_WHITE); - rb_stroke_rect(rb, ST_MARGIN, cb, 20, 20, 2.f, COL_MENU); - if (ed->settings_use_env) { - rb_line(rb, ST_MARGIN + 4, cb + 10, ST_MARGIN + 8, cb + 15, 2.5f, COL_WHITE); - rb_line(rb, ST_MARGIN + 8, cb + 15, ST_MARGIN + 16, cb + 5, 2.5f, COL_WHITE); - } - rb_text_c(rb, ST_MARGIN + 30, ST_OPT_Y + ST_OPT_H*0.5f, ST_ENV_LABEL, COL_TEXT, FS_UI); + float cb = ST_OPT_Y + (ST_OPT_H - 18) * 0.5f; + m3_checkbox(rb, ST_MARGIN + 1, cb, ed->settings_use_env); + rb_text_f(rb, ST_MARGIN + 32, ST_OPT_Y + ST_OPT_H*0.5f, ST_ENV_LABEL, M3_ON_SURFACE, M3_BODY_M, + TB_FONT_REGULAR); tb_a11y_set_states(ax(ed), ax_click(ed, TB_A11Y_CHECKBOX, ST_ENV_LABEL, ST_MARGIN, ST_OPT_Y, 540, ST_OPT_H), ed->settings_use_env ? TB_A11Y_CHECKED : 0); const char* e = tb_environ_env_path(); @@ -6460,11 +6548,11 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { } /* Barra de ferramentas */ - rb_fill_rect(rb, 0, ST_TOOL_Y, WIN_W, ST_TOOL_H, COL_PANEL); + rb_fill_rect(rb, 0, ST_TOOL_Y, WIN_W, ST_TOOL_H, M3_SURFACE); + rb_fill_rect(rb, 0, ST_TOOL_Y + ST_TOOL_H - 1, WIN_W, 1, M3_OUTLINE_VAR); { float px, py, pw, ph; settings_path_rect(ed, &px, &py, &pw, &ph); - rb_fill_rrect(rb, px, py, pw, ph, 6, COL_WHITE); - if (ed->settings_path_focus) rb_stroke_rect(rb, px-1, py-1, pw+2, ph+2, 2.f, COL_MENU); + m3_field(rb, px, py, pw, ph, ed->settings_path_focus, M3_PRIMARY); clip_set(ed, rb, px + 4, py, pw - 8, ph); rb_text_c(rb, px + 12, py + ph*0.5f, ed->settings_path, COL_TEXT, FS_UI); if (ed->settings_path_focus) @@ -6475,13 +6563,14 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { for (int i = 0; i < 3; i++) { float x, y, w, h; settings_btn_rect(ed, i, &x, &y, &w, &h); bool hov = in_rect(ed->mouse_x, ed->mouse_y, x, y, w, h); - st_button(rb, x, y, w, h, - i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "+ Nova", hov); + m3_button(rb, i == 0 ? M3_FILLED : M3_TONAL, x, y, w, h, + i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "Nova", i == 0 ? MI_SAVE : i == 1 ? MI_TABLE : MI_ADD, + M3_PRIMARY, hov, false); ax_button(ed, i == 0 ? "Salvar" : i == 1 ? "Exportar CSV" : "Nova configuração", x, y, w, h); } /* Lista */ - rb_fill_rect(rb, 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y, COL_UI_BG); + rb_fill_rect(rb, 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y, M3_SURFACE_CONTAINER); clip_set(ed, rb, 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y); ax_push(ed, TB_A11Y_LIST, "Configurações", 0, ST_LIST_Y, WIN_W, WIN_H - ST_LIST_Y); if (ed->settings_new_key) @@ -6490,8 +6579,8 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (ed->settings_new_key) { float y = ST_LIST_Y - ed->settings_scroll; - rb_fill_rrect(rb, ST_MARGIN, y + 2, WIN_W - 2*ST_MARGIN, ST_ROW_H - 4, 6, COL_PANEL); - rb_text_c(rb, ST_MARGIN + 16, y + ST_ROW_H*0.5f, "+", COL_MENU, FS_UI); + m3_field(rb, ST_MARGIN, y + 2, WIN_W - 2*ST_MARGIN, ST_ROW_H - 4, true, M3_PRIMARY); + rb_icon(rb, ST_MARGIN + 20, y + ST_ROW_H*0.5f, MI_ADD, 20.f, M3_PRIMARY, false); const char* t = ed->settings_key[0] ? ed->settings_key : "nome da chave (Enter confirma, Esc cancela)"; rb_text_c(rb, ST_MARGIN + 40, y + ST_ROW_H*0.5f, t, ed->settings_key[0] ? COL_TEXT : COL_TEXT_DIM, FS_UI); @@ -6504,17 +6593,19 @@ void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) { float x, y, w, h; settings_row_rect(ed, i, &x, &y, &w, &h); if (y + h < ST_LIST_Y || y > WIN_H) continue; bool sel = (i == ed->settings_sel); - rb_fill_rrect(rb, x, y + 2, w, h - 4, 6, sel ? COL_PANEL : COL_FLY); - if (sel && !ed->settings_value_edit) rb_stroke_rect(rb, x, y+1, w, h-2, 2.f, COL_MENU); - rb_text_c(rb, x + 16, y + h*0.5f, tb_environ_key(i), COL_TEXT, FS_UI); + /* item de lista do M3: superficie, divisoria, selecionado = container */ + rb_fill_rect(rb, x, y, w, h, sel ? M3_SECONDARY_CONTAINER : M3_SURFACE); + rb_fill_rect(rb, x + 16, y + h - 1, w - 32, 1, M3_OUTLINE_VAR); + m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, in_rect(ed->mouse_x, ed->mouse_y, x, y, w, h), false); + rb_text_f(rb, x + 16, y + h*0.5f, tb_environ_key(i), M3_ON_SURFACE, M3_BODY_L - 1, TB_FONT_REGULAR); float vx = x + 16 + tw("", FS_UI) + 260.f; if (vx > x + w - 260.f) vx = x + w - 260.f; if (sel && ed->settings_value_edit) { - rb_fill_rrect(rb, vx - 6, y + 6, w - (vx - x) - 4, h - 12, 4, COL_WHITE); + m3_field(rb, vx - 8, y + 4, w - (vx - x) - 4, h - 8, true, M3_PRIMARY); rb_text_c(rb, vx, y + h*0.5f, ed->settings_edit, COL_TEXT, FS_UI); te_draw(ed, rb, ed->settings_edit, sizeof(ed->settings_edit), false, vx, y + h*0.5f, 20, FS_UI, COL_TEXT); } else { - rb_text_c(rb, vx, y + h*0.5f, tb_environ_value_at(i), COL_TEXT_DIM, FS_UI); + rb_text_f(rb, vx, y + h*0.5f, tb_environ_value_at(i), M3_ON_SURFACE_VAR, M3_BODY_M, TB_FONT_REGULAR); } bool editing = sel && ed->settings_value_edit; int an = ax_click(ed, TB_A11Y_LIST_ITEM, tb_environ_key(i), x, y, w, h); @@ -7247,8 +7338,8 @@ static void feed_keys(TinyBlocks_Block* evb) { propria. Pontos vao em px da vista do palco; o core converte. */ static void input_feed(Ed* ed, TinyBlocks_Block* evb) { TinyBlocks_Block* src = evb; - float ox = AREA(V_STAGE).x + 8 + 1, oy = AREA(V_STAGE).y + STAGE_BAR_H + 1; /* vista no painel */ - if (ed->vwin_in[V_STAGE]) { src = ed->vwin_in[V_STAGE]; ox = 8 + 1; oy = STAGE_BAR_H + 1; } + float ox = AREA(V_STAGE).x + 8 + 1, oy = AREA(V_STAGE).y + STAGE_TOP + 1; /* vista no painel */ + if (ed->vwin_in[V_STAGE]) { src = ed->vwin_in[V_STAGE]; ox = 8 + 1; oy = STAGE_TOP + 1; } tb_input_begin_frame(); float vx = (float)ev_real(src, GFX_IN_MOUSE_X) - ox; @@ -7289,14 +7380,14 @@ static void input_feed(Ed* ed, TinyBlocks_Block* evb) { } static bool hit_flag(Ed* ed, float mx, float my) { - return AREA(V_STAGE).shown && in_rect(mx, my, AREA(V_STAGE).x + 10, AREA(V_STAGE).y + 6, 40, 32); + return AREA(V_STAGE).shown && in_rect(mx, my, AREA(V_STAGE).x + 10, AREA(V_STAGE).y + 4, 40, 32); } static bool hit_stop(Ed* ed, float mx, float my) { - return AREA(V_STAGE).shown && in_rect(mx, my, AREA(V_STAGE).x + 56, AREA(V_STAGE).y + 6, 40, 32); + return AREA(V_STAGE).shown && in_rect(mx, my, AREA(V_STAGE).x + 56, AREA(V_STAGE).y + 4, 40, 32); } static bool hit_detach(Ed* ed, float mx, float my) { return ed->stage && AREA(V_STAGE).shown && !ed->compact && - in_rect(mx, my, AREA(V_STAGE).x + AREA(V_STAGE).w - 50, AREA(V_STAGE).y + 6, 40, 32); + in_rect(mx, my, AREA(V_STAGE).x + AREA(V_STAGE).w - 50, AREA(V_STAGE).y + 4, 40, 32); } TB_ED_API void start_path(Ed* ed, int mode, const char* def) { @@ -8440,6 +8531,37 @@ static void pinch_update(Ed* ed, TinyBlocks_Block* evb, float ox, float oy) { CT.ws_sy = ed->pinch_wy - (cy - WS_Y) / tab_zoom(&CT); } +/* Para conferir o visual sem clicar (com TINYBLOCKS_SHOT): TINYBLOCKS_OPEN + * abre uma tela no inicio - bloco, config, bibliotecas, abrir, menu, + * nova-aba, exportar, codigo, imagem */ +static void dev_open(Ed* ed) { + const char* w = getenv("TINYBLOCKS_OPEN"); + if (!w || !w[0]) return; + if (!strcmp(w, "bloco")) { + dlg_open(ed, -1); + te_insert(ed, ed->comp_dialog_name, sizeof(ed->comp_dialog_name), "girar", false); + dlg_add_part(ed, PARAM_NUM); + te_insert(ed, ed->comp_dialog_parts[1].name, sizeof(ed->comp_dialog_parts[1].name), "graus", false); + dlg_add_part(ed, PARAM_LABEL); + te_insert(ed, ed->comp_dialog_parts[2].name, sizeof(ed->comp_dialog_parts[2].name), "vezes", false); + } + else if (!strcmp(w, "config")) settings_show(ed); + else if (!strcmp(w, "bibliotecas")) libman_show(ed); + else if (!strcmp(w, "abrir")) start_path(ed, PM_LOAD, ""); + else if (!strcmp(w, "nova-aba")) ed->plus_menu_open = true; + else if (!strcmp(w, "menu")) on_rmb_down(ed, WS_X + 120, WS_Y + 60); + else if (!strcmp(w, "exportar")) sbp_open(ed); + else if (!strcmp(w, "codigo")) { + tab_new_kind(ed, "exemplo.c", false, TK_CODE); + snprintf(CT.code_lang, sizeof(CT.code_lang), "c"); + const char* src = "#include \n\nint main(void) {\n printf(\"ola\\n\");\n return 0;\n}\n"; + code_set_text(&CT, src, (int)strlen(src)); + CT.code_anchor = 20; CT.code_caret = 35; + CT.code_hl_dirty = true; + } + else if (!strcmp(w, "imagem")) { tab_new_kind(ed, "Imagem", false, TK_IMAGE); palette_rebuild(ed); } +} + static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) { g_active_ed = ed; { /* modificadores segurados (Shift+clique estende a selecao) */ @@ -8608,7 +8730,9 @@ static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) { if (typed[0]) on_text(ed, typed); if (from >= 0) return; /* o resto e uma vez por quadro (principal) */ + if (ed->frame_no == 3) dev_open(ed); input_feed(ed, evb); /* Sensores: mouse/teclado/toque/sensores do palco */ + long_press_check(ed); ed_mcp_poll(ed); /* pedidos de agentes (servidor MCP), na thread do editor */ vm_frame(ed); /* scripts rodando (sempre / repita) avancam um quadro */ @@ -8715,7 +8839,7 @@ static void scripts_view_overlay(Ed* ed, TinyBlocks_RenderableBlock* rb) { static const ViewClass s_views[V_COUNT] = { [V_PALETTE] = { "Blocos", CAT_W + 120.f, 80.f, palette_view_render, NULL, NULL }, [V_SCRIPTS] = { "Scripts", 220.f, TAB_H + 120.f, scripts_view_render, scripts_view_overlay, NULL }, - [V_STAGE] = { "Palco", 160.f, STAGE_BAR_H + 60.f, render_stage, NULL, stage_grip }, + [V_STAGE] = { "Palco", 160.f, STAGE_TOP + 60.f, render_stage, NULL, stage_grip }, [V_OUTPUT] = { "Saída", 160.f, 80.f, render_output, NULL, output_grip }, }; diff --git a/libraries/tinyblocks-editor/src/tb_editor_modules.c b/libraries/tinyblocks-editor/src/tb_editor_modules.c index 63fc4ad..585ff3a 100644 --- a/libraries/tinyblocks-editor/src/tb_editor_modules.c +++ b/libraries/tinyblocks-editor/src/tb_editor_modules.c @@ -124,8 +124,12 @@ static bool resolve_widgets(void) { sym_fn(&w.text_c, "tinyblocks-editor-widgets", "tb_ew_text_c"); sym_fn(&w.text_width, "tinyblocks-editor-widgets", "tb_ew_text_width"); sym_fn(&w.in_rect, "tinyblocks-editor-widgets", "tb_ew_in_rect"); + sym_fn(&w.text_f, "tinyblocks-editor-widgets", "tb_ew_text_f"); + sym_fn(&w.icon, "tinyblocks-editor-widgets", "tb_ew_icon"); + sym_fn(&w.shadow, "tinyblocks-editor-widgets", "tb_ew_shadow"); bool ok = w.col_mul && w.fill_rect && w.fill_rrect && w.fill_circle && w.stroke_rect && - w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect; + w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect && + w.text_f && w.icon && w.shadow; if (ok) tb_ed_w = w; return ok; } @@ -174,7 +178,8 @@ bool tb_ed_modules_load(Ed* ed) { .col_mul = tb_ew_col_mul, .fill_rect = tb_ew_fill_rect, .fill_rrect = tb_ew_fill_rrect, .fill_circle = tb_ew_fill_circle, .stroke_rect = tb_ew_stroke_rect, .stroke_circle = tb_ew_stroke_circle, .line = tb_ew_line, .text_c = tb_ew_text_c, - .text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect }; + .text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect, + .text_f = tb_ew_text_f, .icon = tb_ew_icon, .shadow = tb_ew_shadow }; tb_ed_img = (TbEdImageApi){ .view = tb_editor_image_view, .click = tb_editor_image_click, .drag = tb_editor_image_drag, .release = tb_editor_image_release, .load_file = tb_editor_image_load_file, diff --git a/libraries/tinyblocks-sdl2/src/tb_sdl2.c b/libraries/tinyblocks-sdl2/src/tb_sdl2.c index afe996d..0a42b88 100644 --- a/libraries/tinyblocks-sdl2/src/tb_sdl2.c +++ b/libraries/tinyblocks-sdl2/src/tb_sdl2.c @@ -79,7 +79,7 @@ static void eval_handle_noop(TinyBlocks_Block* self, TinyBlocks* rt) { #define FONT_CACHE_CAP 64 /* o zoom da area de scripts pede muitos tamanhos */ #define FONT_SEARCH_COUNT 9 -typedef struct { int size; TTF_Font* font; unsigned used; } FontEntry; +typedef struct { int size, family; TTF_Font* font; unsigned used; } FontEntry; static FontEntry s_font_cache[FONT_CACHE_CAP]; static int s_font_cache_n = 0; @@ -96,8 +96,37 @@ static const char* s_font_paths[FONT_SEARCH_COUNT] = { "C:/Windows/Fonts/arial.ttf", }; -/* A fonte que vai junto do programa (pacote Windows, AppImage): - /fonts/DejaVuSans.ttf */ +/* Fontes que vao junto do programa (TB_FONT_*): Roboto e Material Symbols. + Procura em $TINYBLOCKS_APPDIR/fonts (AppImage, Android), /fonts (pacote Windows) e /../assets/fonts + (rodando da arvore: build/editor). DejaVu fica de reserva para o texto. */ +static const char* s_family_files[TB_FONT_COUNT] = { + "Roboto-Regular.ttf", "Roboto-Medium.ttf", + "MaterialSymbolsOutlined.ttf", "MaterialSymbolsFilled.ttf", +}; + +static TTF_Font* open_in(const char* dir, const char* sub, const char* file, int size) { + char path[1200]; + snprintf(path, sizeof(path), "%s%s%s", dir, sub, file); + return TTF_OpenFont(path, size); +} + +static TTF_Font* family_font(int family, int size) { + const char* file = s_family_files[family]; + TTF_Font* f = NULL; + const char* dir = getenv("TINYBLOCKS_APPDIR"); + if (dir && dir[0]) f = open_in(dir, "/fonts/", file, size); + char* base = f ? NULL : SDL_GetBasePath(); + if (base) { + f = open_in(base, "fonts/", file, size); + if (!f) f = open_in(base, "../assets/fonts/", file, size); + SDL_free(base); + } +#ifdef __ANDROID__ + if (!f) f = open_in("", "fonts/", file, size); /* assets do APK */ +#endif + return f; +} static TTF_Font* bundled_font(int size) { char path[1024]; const char* dir = getenv("TINYBLOCKS_APPDIR"); @@ -113,16 +142,24 @@ static TTF_Font* bundled_font(int size) { return TTF_OpenFont(path, size); } -static TTF_Font* get_font(int size) { +static TTF_Font* get_font(int size, int family) { static unsigned tick = 0; tick++; + if (family < 0 || family >= TB_FONT_COUNT) family = TB_FONT_REGULAR; for (int i = 0; i < s_font_cache_n; i++) - if (s_font_cache[i].size == size) { s_font_cache[i].used = tick; return s_font_cache[i].font; } + if (s_font_cache[i].size == size && s_font_cache[i].family == family) { + s_font_cache[i].used = tick; + return s_font_cache[i].font; + } - TTF_Font* f = bundled_font(size); - for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++) - f = TTF_OpenFont(s_font_paths[i], size); - if (!f) return NULL; + TTF_Font* f = family_font(family, size); + if (!f && family == TB_FONT_MEDIUM) f = family_font(TB_FONT_REGULAR, size); + if (!f && family <= TB_FONT_MEDIUM) { /* sem Roboto: DejaVu */ + f = bundled_font(size); + for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++) + f = TTF_OpenFont(s_font_paths[i], size); + } + if (!f) return NULL; /* sem icones: nada */ /* cheio: fecha o usado ha mais tempo (antes vazava uma fonte por chamada) */ int slot = s_font_cache_n; @@ -133,6 +170,7 @@ static TTF_Font* get_font(int size) { TTF_CloseFont(s_font_cache[slot].font); } else s_font_cache_n++; s_font_cache[slot].size = size; + s_font_cache[slot].family = family; s_font_cache[slot].font = f; s_font_cache[slot].used = tick; return f; @@ -330,7 +368,8 @@ static void sdl2_execute(SDL_Renderer* ren, scaled = *cmd; scaled.x *= s_ui_scale; scaled.y *= s_ui_scale; scaled.w *= s_ui_scale; scaled.h *= s_ui_scale; - scaled.param *= s_ui_scale; scaled.font_size *= s_ui_scale; + if (cmd->kind != TB_DRAW_TEXT) scaled.param *= s_ui_scale; /* no texto e a fonte */ + scaled.font_size *= s_ui_scale; cmd = &scaled; } switch (cmd->kind) { @@ -429,7 +468,7 @@ static void sdl2_execute(SDL_Renderer* ren, case TB_DRAW_TEXT: if (cmd->text[0]) { - TTF_Font* font = get_font((int)(cmd->font_size + 0.5f)); + TTF_Font* font = get_font((int)(cmd->font_size + 0.5f), (int)cmd->param); if (font) { SDL_Color col = { (Uint8)(cmd->r*255.f), (Uint8)(cmd->g*255.f), @@ -866,18 +905,42 @@ static char* be_clipboard_get(void) { return r; } +/* Captura para conferir o visual sem olhar a tela de ninguem: + TINYBLOCKS_SHOT=arquivo.bmp salva a 1a janela depois de + TINYBLOCKS_SHOT_FRAMES quadros (padrao 30) e sai. */ +static void shot_check(SdlWin* w) { + static int frames = 0; + static bool done = false; + const char* path = getenv("TINYBLOCKS_SHOT"); + if (done || !path || !path[0]) return; + SdlWin* first = s_wins; + while (first && first->next) first = first->next; /* a lista e LIFO */ + if (w != first) return; + const char* fe = getenv("TINYBLOCKS_SHOT_FRAMES"); + if (++frames < (fe && atoi(fe) > 0 ? atoi(fe) : 30)) return; + done = true; + int pw = 0, ph = 0; + SDL_GetRendererOutputSize(w->ren, &pw, &ph); + SDL_Surface* s = SDL_CreateRGBSurfaceWithFormat(0, pw, ph, 32, SDL_PIXELFORMAT_ARGB8888); + if (s && SDL_RenderReadPixels(w->ren, NULL, SDL_PIXELFORMAT_ARGB8888, s->pixels, s->pitch) == 0) + SDL_SaveBMP(s, path); + if (s) SDL_FreeSurface(s); + exit(0); /* so para conferir: sai em seguida */ +} + static void be_window_present(void* handle, const TinyBlocks_RenderableBlock* rb) { SdlWin* w = (SdlWin*)handle; SDL_SetRenderDrawColor(w->ren, 0, 0, 0, 255); SDL_RenderClear(w->ren); if (rb) sdl2_execute(w->ren, rb); + shot_check(w); SDL_RenderPresent(w->ren); } static float be_measure_text(const char* text, float font_size) { if (!be_init()) return 0.f; const float S = s_ui_scale > 0.f ? s_ui_scale : 1.f; - TTF_Font* font = get_font((int)(font_size * S + 0.5f)); + TTF_Font* font = get_font((int)(font_size * S + 0.5f), TB_FONT_REGULAR); int w = 0, h = 0; if (!font || TTF_SizeUTF8(font, text, &w, &h) != 0) return 0.f; return (float)w / S; /* largura em unidades logicas */ diff --git a/packaging/android/android_boot.c b/packaging/android/android_boot.c index d42aea1..2a2dc91 100644 --- a/packaging/android/android_boot.c +++ b/packaging/android/android_boot.c @@ -6,7 +6,7 @@ * 2. exporta TINYBLOCKS_APPDIR, que as libraries usam para achar a fonte * e os certificados (no Android nao existe /proc/self/exe do app nem * SDL_GetBasePath); - * 3. copia dos assets para essa pasta a DejaVu e o ca-bundle.crt (o + * 3. copia dos assets para essa pasta as fontes e o ca-bundle.crt (o * SDL2_ttf e o OpenSSL precisam de caminho no sistema de arquivos). * * Chamado do inicio do main() do editor, antes de qualquer library rodar. @@ -68,6 +68,16 @@ void tb_android_boot(void) { copy_asset(am, "fonts/DejaVuSans.ttf", dst); snprintf(dst, sizeof(dst), "%s/fonts/DejaVuSansMono.ttf", dir); copy_asset(am, "fonts/DejaVuSansMono.ttf", dst); + static const char* const m3[] = { /* Roboto + Material Symbols (interface M3) */ + "Roboto-Regular.ttf", "Roboto-Medium.ttf", + "MaterialSymbolsOutlined.ttf", "MaterialSymbolsFilled.ttf", + }; + for (size_t i = 0; i < sizeof(m3) / sizeof(m3[0]); i++) { + char src[96]; + snprintf(src, sizeof(src), "fonts/%s", m3[i]); + snprintf(dst, sizeof(dst), "%s/fonts/%s", dir, m3[i]); + copy_asset(am, src, dst); + } snprintf(dst, sizeof(dst), "%s/certs/ca-bundle.crt", dir); copy_asset(am, "certs/ca-bundle.crt", dst); } diff --git a/packaging/android/build.sh b/packaging/android/build.sh index 7494a22..f74b64c 100755 --- a/packaging/android/build.sh +++ b/packaging/android/build.sh @@ -229,6 +229,7 @@ mipmaps() { done cp /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf "$AND/assets/fonts/" cp /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf "$AND/assets/fonts/" + cp "$ROOT"/assets/fonts/*.ttf "$ROOT"/assets/fonts/LICENSE-*.txt "$AND/assets/fonts/" # Roboto + Material Symbols cp /etc/ssl/certs/ca-certificates.crt "$AND/assets/certs/ca-bundle.crt" } diff --git a/packaging/windows/win.mk b/packaging/windows/win.mk index f8de891..858ad8c 100644 --- a/packaging/windows/win.mk +++ b/packaging/windows/win.mk @@ -117,10 +117,11 @@ win-pkg: $(WIN_EXE) else cp $(WIN_DEPS)/share/pki/ca-trust-source/ca-bundle.trust.crt $(WIN_PKG)/certs/ca-bundle.crt; fi @cp $(WIN_FONTS) $(WIN_PKG)/fonts/ || { echo "Falta a fonte DejaVu (pacote fonts-dejavu-core)"; exit 1; } @cp $(WIN_FONT_LICENSE) $(WIN_PKG)/fonts/LICENSE.txt 2>/dev/null || true + @cp assets/fonts/*.ttf assets/fonts/LICENSE-*.txt $(WIN_PKG)/fonts/ # Roboto + Material Symbols @cp -r examples/gan-animais $(WIN_PKG)/exemplos-gan-animais 2>/dev/null || true @printf '%s\r\n' "TinyBlocks $(APP_VER) para Windows ($(WIN_ARCH))" "" \ "Abra TinyBlocks.exe. As DLLs desta pasta precisam ficar junto dele." \ - "Fonte: DejaVu Sans (licenca livre, ver fonts/LICENSE.txt)." > $(WIN_PKG)/LEIA-ME.txt + "Fontes: Roboto e Material Symbols (Apache 2.0) e DejaVu Sans (ver fonts/)." > $(WIN_PKG)/LEIA-ME.txt exe: win-pkg ## Gera o TinyBlocks.exe para Windows (build/win-x86_64/TinyBlocks e o .zip) @rm -f $(WIN_ZIP) diff --git a/src/tb_renderable_block.c b/src/tb_renderable_block.c index 7ea86b8..0812fd2 100644 --- a/src/tb_renderable_block.c +++ b/src/tb_renderable_block.c @@ -125,6 +125,14 @@ void tb_draw_text(TinyBlocks_RenderableBlock* rb, strncpy(c->text, text, sizeof(c->text) - 1); } +void tb_draw_text_font(TinyBlocks_RenderableBlock* rb, + float x, float y, const char* text, float font_size, int font, + float r, float g, float b, float a) { + uint32_t n = rb ? rb->count : 0; + tb_draw_text(rb, x, y, text, font_size, r, g, b, a); + if (rb && rb->count > n) rb->cmds[n].param = (float)font; +} + void tb_draw_image(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const TinyBlocks_Image* image) {