Skip to content

Commit

Permalink
#229 theme builder example from latest designer
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Aug 26, 2024
1 parent 44ef11c commit 699a72e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 41 deletions.
34 changes: 0 additions & 34 deletions examples/esp/esp32s2Saola/ThemeMonoInverse.h

This file was deleted.

58 changes: 58 additions & 0 deletions examples/esp/esp32s2Saola/ThemeMonoInverseBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef TCMENU_THEME_MONO_INVERSE
#define TCMENU_THEME_MONO_INVERSE

#include <graphics/TcThemeBuilder.h>

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
5 changes: 3 additions & 2 deletions examples/esp/esp32s2Saola/esp32s2Saola.emf
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -539,7 +539,8 @@
"menuDefinitions": []
},
"packageNamespace": "",
"appIsModular": false
"appIsModular": false,
"listOfEmbeddedForms": []
},
"stringLists": []
}
10 changes: 5 additions & 5 deletions examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use elsewhere.
*/

// Generated for Arduino ESP32 by TcMenu 4.3.1-SNAPSHOT on 2024-08-26T12:55:56.108558600Z.

#include <tcMenu.h>
#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" };
Expand Down Expand Up @@ -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(&ethernetConnection);
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);
Expand Down

0 comments on commit 699a72e

Please sign in to comment.