From 699a72ea6e75fed542d16de0cf55002eb1a0f53a Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 26 Aug 2024 14:03:04 +0100 Subject: [PATCH] #229 theme builder example from latest designer --- examples/esp/esp32s2Saola/ThemeMonoInverse.h | 34 ----------- .../esp32s2Saola/ThemeMonoInverseBuilder.h | 58 +++++++++++++++++++ examples/esp/esp32s2Saola/esp32s2Saola.emf | 5 +- .../generated/esp32s2Saola_menu.cpp | 10 ++-- 4 files changed, 66 insertions(+), 41 deletions(-) delete mode 100644 examples/esp/esp32s2Saola/ThemeMonoInverse.h create mode 100644 examples/esp/esp32s2Saola/ThemeMonoInverseBuilder.h diff --git a/examples/esp/esp32s2Saola/ThemeMonoInverse.h b/examples/esp/esp32s2Saola/ThemeMonoInverse.h deleted file mode 100644 index 1d689400..00000000 --- a/examples/esp/esp32s2Saola/ThemeMonoInverse.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TCMENU_THEME_MONO_INVERSE -#define TCMENU_THEME_MONO_INVERSE - -color_t defaultItemPaletteMono[] = {1, 0, 1, 1}; -color_t defaultTitlePaletteMono[] = {0, 1, 0, 0}; - -#define TITLE_PADDING 2 -#define TITLE_SPACING 2 - -void installMonoInverseTitleTheme(GraphicsDeviceRenderer& bgr, const MenuFontDef& itemFont, const MenuFontDef& titleFont, bool needEditingIcons) { - bgr.setDisplayDimensions(bgr.getDeviceDrawable()->getDisplayDimensions().x, bgr.getDeviceDrawable()->getDisplayDimensions().y); - auto& factory = bgr.getGraphicsPropertiesFactory(); - - factory.setSelectedColors(0, 2); - - MenuPadding titlePadding(TITLE_PADDING); - MenuPadding itemPadding(1); - int titleHeight = bgr.heightForFontPadding(titleFont.fontData, titleFont.fontMag, titlePadding); - int itemHeight = bgr.heightForFontPadding(itemFont.fontData, itemFont.fontMag, itemPadding); - - factory.addImageToCache(DrawableIcon(SPECIAL_ID_EDIT_ICON, Coord(8, 6),DrawableIcon::ICON_XBITMAP, loResEditingIcon)); - factory.addImageToCache(DrawableIcon(SPECIAL_ID_ACTIVE_ICON, Coord(8, 6),DrawableIcon::ICON_XBITMAP, loResActiveIcon)); - - factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_TITLE, defaultTitlePaletteMono, titlePadding, titleFont.fontData, titleFont.fontMag, - TITLE_SPACING, titleHeight + 1, GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE, MenuBorder(0)); - factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_ITEM, defaultItemPaletteMono, itemPadding, itemFont.fontData, itemFont.fontMag, - 1, itemHeight, GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT , MenuBorder(0)); - factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_ACTION, defaultItemPaletteMono, itemPadding, itemFont.fontData, itemFont.fontMag, - 1, itemHeight, GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE, MenuBorder(0)); - - tcgfx::ConfigurableItemDisplayPropertiesFactory::refreshCache(); -} - -#endif //TCMENU_THEME_MONO_INVERSE \ No newline at end of file diff --git a/examples/esp/esp32s2Saola/ThemeMonoInverseBuilder.h b/examples/esp/esp32s2Saola/ThemeMonoInverseBuilder.h new file mode 100644 index 00000000..9f4bbce3 --- /dev/null +++ b/examples/esp/esp32s2Saola/ThemeMonoInverseBuilder.h @@ -0,0 +1,58 @@ +#ifndef TCMENU_THEME_MONO_INVERSE +#define TCMENU_THEME_MONO_INVERSE + +#include + +color_t defaultItemPaletteMono[] = {1, 0, 1, 1}; +color_t defaultTitlePaletteMono[] = {0, 1, 0, 0}; + +#define TITLE_PADDING 2 +#define TITLE_SPACING 2 + +/** + * This is one of the stock themes, you can modify it to meet your requirements, and it will not be updated by tcMenu + * Designer unless you delete it. This sets up the fonts, spacing and padding for all items. + * @param gr the graphical renderer + * @param itemFont the font for items + * @param titleFont the font for titles + * @param needEditingIcons if editing icons are needed + */ +void installMonoInverseTitleTheme(GraphicsDeviceRenderer& gr, const MenuFontDef& itemFont, const MenuFontDef& titleFont, + bool needEditingIcons, BaseGraphicalRenderer::TitleMode titleMode, bool useUnicode) { + TcThemeBuilder themeBuilder(gr); + themeBuilder.withSelectedColors(0, 2) + .dimensionsFromRenderer() + .withItemPadding(MenuPadding(1)) + .withRenderingSettings(titleMode, false) + .withPalette(defaultItemPaletteMono) + .withNativeFont(itemFont.fontData, itemFont.fontMag) + .withSpacing(1); + + if(needEditingIcons) { + themeBuilder.withStandardLowResCursorIcons(); + } + + if(useUnicode) { + themeBuilder.enablingTcUnicode(); + } + + themeBuilder.defaultTitleProperties() + .withNativeFont(titleFont.fontData, titleFont.fontMag) + .withPalette(defaultTitlePaletteMono) + .withPadding(MenuPadding(TITLE_PADDING)) + .withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE) + .withSpacing(TITLE_SPACING) + .apply(); + + themeBuilder.defaultActionProperties() + .withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE) + .apply(); + + themeBuilder.defaultItemProperties() + .withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT) + .apply(); + + themeBuilder.apply(); +} + +#endif //TCMENU_THEME_MONO_INVERSE diff --git a/examples/esp/esp32s2Saola/esp32s2Saola.emf b/examples/esp/esp32s2Saola/esp32s2Saola.emf index 8970e207..bc463c0a 100644 --- a/examples/esp/esp32s2Saola/esp32s2Saola.emf +++ b/examples/esp/esp32s2Saola/esp32s2Saola.emf @@ -366,7 +366,7 @@ "lastRemoteUuids": [ "46c30011-cac6-4598-a7b8-b0630d55daab" ], - "lastThemeUuid": "0dd60ceb-7e0f-46e2-8d40-b264eb3aa7e0", + "lastThemeUuid": "396ED4DF-AD7B-4951-A848-A9E5838A549B", "applicationUUID": "b447b433-fe4f-4ce7-8746-d94bfeefc707", "applicationName": "ESP32-S2 Saola board", "lastProperties": [ @@ -539,7 +539,8 @@ "menuDefinitions": [] }, "packageNamespace": "", - "appIsModular": false + "appIsModular": false, + "listOfEmbeddedForms": [] }, "stringLists": [] } \ No newline at end of file diff --git a/examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp b/examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp index b8019851..cfeadb83 100644 --- a/examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp +++ b/examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp @@ -8,9 +8,11 @@ use elsewhere. */ +// Generated for Arduino ESP32 by TcMenu 4.3.1-SNAPSHOT on 2024-08-26T12:55:56.108558600Z. + #include #include "esp32s2Saola_menu.h" -#include "../ThemeMonoInverse.h" +#include "../ThemeMonoInverseBuilder.h" // Global variable declarations const PROGMEM ConnectorLocalInfo applicationInfo = { "ESP32-S2 Saola board", "b447b433-fe4f-4ce7-8746-d94bfeefc707" }; @@ -90,15 +92,13 @@ void setupMenu() { menuConnectivityIoTMonitor.setLocalOnly(true); menuConnectivityAuthenticator.setLocalOnly(true); - // Code generated by plugins. + // Code generated by plugins and new operators. gfx.begin(); renderer.setUpdatesPerSecond(10); switches.init(internalDigitalIo(), SWITCHES_POLL_EVERYTHING, true); menuMgr.initForEncoder(&renderer, &menuIntEdit, 5, 6, 7); remoteServer.addConnection(ðernetConnection); - renderer.setTitleMode(BaseGraphicalRenderer::TITLE_ALWAYS); - renderer.setUseSliderForAnalog(false); - installMonoInverseTitleTheme(renderer, MenuFontDef(nullptr, 1), MenuFontDef(nullptr, 1), true); + installMonoInverseTitleTheme(renderer, MenuFontDef(nullptr, 1), MenuFontDef(nullptr, 1), true, BaseGraphicalRenderer::TITLE_ALWAYS, false); // We have an IoT monitor, register the server menuConnectivityIoTMonitor.setRemoteServer(remoteServer);