Skip to content

Commit c3607c3

Browse files
authored
Merge pull request #230 from TcMenu/main-themebuilder-fix
#229 theme builder fix for card layout
2 parents e79cfa1 + 699a72e commit c3607c3

File tree

7 files changed

+74
-47
lines changed

7 files changed

+74
-47
lines changed

examples/esp/esp32s2Saola/ThemeMonoInverse.h

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef TCMENU_THEME_MONO_INVERSE
2+
#define TCMENU_THEME_MONO_INVERSE
3+
4+
#include <graphics/TcThemeBuilder.h>
5+
6+
color_t defaultItemPaletteMono[] = {1, 0, 1, 1};
7+
color_t defaultTitlePaletteMono[] = {0, 1, 0, 0};
8+
9+
#define TITLE_PADDING 2
10+
#define TITLE_SPACING 2
11+
12+
/**
13+
* This is one of the stock themes, you can modify it to meet your requirements, and it will not be updated by tcMenu
14+
* Designer unless you delete it. This sets up the fonts, spacing and padding for all items.
15+
* @param gr the graphical renderer
16+
* @param itemFont the font for items
17+
* @param titleFont the font for titles
18+
* @param needEditingIcons if editing icons are needed
19+
*/
20+
void installMonoInverseTitleTheme(GraphicsDeviceRenderer& gr, const MenuFontDef& itemFont, const MenuFontDef& titleFont,
21+
bool needEditingIcons, BaseGraphicalRenderer::TitleMode titleMode, bool useUnicode) {
22+
TcThemeBuilder themeBuilder(gr);
23+
themeBuilder.withSelectedColors(0, 2)
24+
.dimensionsFromRenderer()
25+
.withItemPadding(MenuPadding(1))
26+
.withRenderingSettings(titleMode, false)
27+
.withPalette(defaultItemPaletteMono)
28+
.withNativeFont(itemFont.fontData, itemFont.fontMag)
29+
.withSpacing(1);
30+
31+
if(needEditingIcons) {
32+
themeBuilder.withStandardLowResCursorIcons();
33+
}
34+
35+
if(useUnicode) {
36+
themeBuilder.enablingTcUnicode();
37+
}
38+
39+
themeBuilder.defaultTitleProperties()
40+
.withNativeFont(titleFont.fontData, titleFont.fontMag)
41+
.withPalette(defaultTitlePaletteMono)
42+
.withPadding(MenuPadding(TITLE_PADDING))
43+
.withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE)
44+
.withSpacing(TITLE_SPACING)
45+
.apply();
46+
47+
themeBuilder.defaultActionProperties()
48+
.withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE)
49+
.apply();
50+
51+
themeBuilder.defaultItemProperties()
52+
.withJustification(tcgfx::GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT)
53+
.apply();
54+
55+
themeBuilder.apply();
56+
}
57+
58+
#endif //TCMENU_THEME_MONO_INVERSE

examples/esp/esp32s2Saola/esp32s2Saola.emf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
"lastRemoteUuids": [
367367
"46c30011-cac6-4598-a7b8-b0630d55daab"
368368
],
369-
"lastThemeUuid": "0dd60ceb-7e0f-46e2-8d40-b264eb3aa7e0",
369+
"lastThemeUuid": "396ED4DF-AD7B-4951-A848-A9E5838A549B",
370370
"applicationUUID": "b447b433-fe4f-4ce7-8746-d94bfeefc707",
371371
"applicationName": "ESP32-S2 Saola board",
372372
"lastProperties": [
@@ -539,7 +539,8 @@
539539
"menuDefinitions": []
540540
},
541541
"packageNamespace": "",
542-
"appIsModular": false
542+
"appIsModular": false,
543+
"listOfEmbeddedForms": []
543544
},
544545
"stringLists": []
545546
}

examples/esp/esp32s2Saola/generated/esp32s2Saola_menu.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use elsewhere.
99
*/
1010

11+
// Generated for Arduino ESP32 by TcMenu 4.3.1-SNAPSHOT on 2024-08-26T12:55:56.108558600Z.
12+
1113
#include <tcMenu.h>
1214
#include "esp32s2Saola_menu.h"
13-
#include "../ThemeMonoInverse.h"
15+
#include "../ThemeMonoInverseBuilder.h"
1416

1517
// Global variable declarations
1618
const PROGMEM ConnectorLocalInfo applicationInfo = { "ESP32-S2 Saola board", "b447b433-fe4f-4ce7-8746-d94bfeefc707" };
@@ -90,15 +92,13 @@ void setupMenu() {
9092
menuConnectivityIoTMonitor.setLocalOnly(true);
9193
menuConnectivityAuthenticator.setLocalOnly(true);
9294

93-
// Code generated by plugins.
95+
// Code generated by plugins and new operators.
9496
gfx.begin();
9597
renderer.setUpdatesPerSecond(10);
9698
switches.init(internalDigitalIo(), SWITCHES_POLL_EVERYTHING, true);
9799
menuMgr.initForEncoder(&renderer, &menuIntEdit, 5, 6, 7);
98100
remoteServer.addConnection(&ethernetConnection);
99-
renderer.setTitleMode(BaseGraphicalRenderer::TITLE_ALWAYS);
100-
renderer.setUseSliderForAnalog(false);
101-
installMonoInverseTitleTheme(renderer, MenuFontDef(nullptr, 1), MenuFontDef(nullptr, 1), true);
101+
installMonoInverseTitleTheme(renderer, MenuFontDef(nullptr, 1), MenuFontDef(nullptr, 1), true, BaseGraphicalRenderer::TITLE_ALWAYS, false);
102102

103103
// We have an IoT monitor, register the server
104104
menuConnectivityIoTMonitor.setRemoteServer(remoteServer);

src/graphics/GraphicsDeviceRenderer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ namespace tcgfx {
494494
void GraphicsDeviceRenderer::enableCardLayout(const DrawableIcon& left, const DrawableIcon& right, MenuTouchScreenManager* touchScreenManager, bool monoDisplay) {
495495
if(cardLayoutPane == nullptr) {
496496
cardLayoutPane = new CardLayoutPane(&left, &right, touchScreenManager, monoDisplay);
497+
} else {
498+
serlogF(SER_TCMENU_INFO, "Card already init");
497499
}
498500
}
499501

src/graphics/TcThemeBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ ThemePropertiesBuilder &TcThemeBuilder::menuItemOverride(MenuItem &item) {
102102
}
103103

104104
TcThemeBuilder& TcThemeBuilder::enableCardLayoutWithXbmImages(Coord iconSize, const uint8_t *leftIcon, const uint8_t *rightIcon, bool isMono) {
105-
renderer.enableCardLayout(
106-
DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, leftIcon, nullptr),
107-
DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, rightIcon, nullptr),
108-
nullptr, isMono);
105+
auto left = new DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, leftIcon, nullptr);
106+
auto right = new DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, rightIcon, nullptr);
107+
renderer.enableCardLayout(*left, *right, nullptr, isMono);
109108
return *this;
110109
}
111110

@@ -137,3 +136,4 @@ TcThemeBuilder& TcThemeBuilder::manualDimensions(int x, int y) {
137136
renderer.setDisplayDimensions(x, y);
138137
return *this;
139138
}
139+

src/graphics/TcThemeBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace tcgfx {
9393
* @param mag the magnification value
9494
* @return reference to itself for chaining
9595
*/
96-
ThemePropertiesBuilder& withNativeFont(void* data, uint8_t mag) {
96+
ThemePropertiesBuilder& withNativeFont(const void* data, uint8_t mag) {
9797
fontData = data;
9898
fontMag = mag;
9999
needsProps();
@@ -349,7 +349,7 @@ namespace tcgfx {
349349
* @param mag the native mag value
350350
* @return reference to itself for chaining
351351
*/
352-
TcThemeBuilder& withNativeFont(void* data, uint8_t mag) {
352+
TcThemeBuilder& withNativeFont(const void* data, uint8_t mag) {
353353
fontData = data;
354354
fontMag = mag;
355355
return *this;

0 commit comments

Comments
 (0)