Skip to content

Commit

Permalink
Merge pull request #230 from TcMenu/main-themebuilder-fix
Browse files Browse the repository at this point in the history
#229 theme builder fix for card layout
  • Loading branch information
davetcc authored Aug 26, 2024
2 parents e79cfa1 + 699a72e commit c3607c3
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 47 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
2 changes: 2 additions & 0 deletions src/graphics/GraphicsDeviceRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ namespace tcgfx {
void GraphicsDeviceRenderer::enableCardLayout(const DrawableIcon& left, const DrawableIcon& right, MenuTouchScreenManager* touchScreenManager, bool monoDisplay) {
if(cardLayoutPane == nullptr) {
cardLayoutPane = new CardLayoutPane(&left, &right, touchScreenManager, monoDisplay);
} else {
serlogF(SER_TCMENU_INFO, "Card already init");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/graphics/TcThemeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ ThemePropertiesBuilder &TcThemeBuilder::menuItemOverride(MenuItem &item) {
}

TcThemeBuilder& TcThemeBuilder::enableCardLayoutWithXbmImages(Coord iconSize, const uint8_t *leftIcon, const uint8_t *rightIcon, bool isMono) {
renderer.enableCardLayout(
DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, leftIcon, nullptr),
DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, rightIcon, nullptr),
nullptr, isMono);
auto left = new DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, leftIcon, nullptr);
auto right = new DrawableIcon(-1, iconSize, tcgfx::DrawableIcon::ICON_XBITMAP, rightIcon, nullptr);
renderer.enableCardLayout(*left, *right, nullptr, isMono);
return *this;
}

Expand Down Expand Up @@ -137,3 +136,4 @@ TcThemeBuilder& TcThemeBuilder::manualDimensions(int x, int y) {
renderer.setDisplayDimensions(x, y);
return *this;
}

4 changes: 2 additions & 2 deletions src/graphics/TcThemeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace tcgfx {
* @param mag the magnification value
* @return reference to itself for chaining
*/
ThemePropertiesBuilder& withNativeFont(void* data, uint8_t mag) {
ThemePropertiesBuilder& withNativeFont(const void* data, uint8_t mag) {
fontData = data;
fontMag = mag;
needsProps();
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace tcgfx {
* @param mag the native mag value
* @return reference to itself for chaining
*/
TcThemeBuilder& withNativeFont(void* data, uint8_t mag) {
TcThemeBuilder& withNativeFont(const void* data, uint8_t mag) {
fontData = data;
fontMag = mag;
return *this;
Expand Down

0 comments on commit c3607c3

Please sign in to comment.