Skip to content

Commit 31003f7

Browse files
committed
#236 theme builder example improvements.
1 parent 192c445 commit 31003f7

File tree

5 files changed

+149
-11
lines changed

5 files changed

+149
-11
lines changed

examples/arduino32/stm32DuinoDemo/app_icondata.h

+14
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@ static unsigned char muteOnIcon40Bits[] = {
8282
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
8383
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
8484

85+
// XBM_LSB_FIRST width=32, height=32, size=128
86+
// auto size = Coord(32, 32);
87+
const uint8_t cardIconBitmap[] PROGMEM = {
88+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x0f,0x00,0xc0,0x08,0x10,0x03,
89+
0x20,0x89,0x91,0x04,0x10,0xc9,0x93,0x08,0x10,0x8a,0x51,0x08,0x08,0x8c,0x31,0x11,0xe4,0x08,0x90,0x23,
90+
0xe2,0x08,0xd0,0x47,0xe4,0x08,0x10,0x23,0x04,0x08,0x10,0x21,0x08,0x08,0x10,0x10,0x10,0x08,0x10,0x08,
91+
0x10,0x08,0x10,0x08,0x20,0x08,0x10,0x04,0x40,0x08,0x10,0x02,0x80,0x08,0x10,0x01,0x80,0x08,0x10,0x01,
92+
0x00,0xf1,0x8f,0x00,0x00,0x02,0x40,0x00,0x00,0x82,0x41,0x00,0x00,0x44,0x22,0x00,0x00,0xfe,0x7f,0x00,
93+
0x00,0xf3,0xdf,0x00,0x00,0x9d,0xc8,0x00,0x00,0xad,0xd6,0x00,0x00,0xad,0xd6,0x00,0x00,0x93,0xce,0x00,
94+
0x00,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00
95+
};
96+
97+
98+
8599
#endif //TCMENU_STM32DUINO_ICONDATA_H

examples/arduino32/stm32DuinoDemo/generated/stm32DuinoDemo_menu.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use elsewhere.
99
*/
1010

11-
// Generated for STM32Duino by TcMenu 4.3.1 on 2024-09-15T10:15:26.406693600Z.
11+
// Generated for STM32Duino by TcMenu 4.3.1 on 2024-09-21T08:48:23.694313500Z.
1212

1313
#include <tcMenu.h>
1414
#include "stm32DuinoDemo_menu.h"
@@ -97,8 +97,19 @@ AnalogMenuItem menuStatusCurrent(&minfoStatusCurrent, 0, &menuStatusMotor, INFO_
9797
const SubMenuInfo minfoStatus = { "Status", 22, 0xffff, 0, NO_CALLBACK };
9898
BackMenuItem menuBackStatus(&minfoStatus, &menuStatusCurrent, INFO_LOCATION_PGM);
9999
SubMenuItem menuStatus(&minfoStatus, &menuBackStatus, &menuSettings, INFO_LOCATION_PGM);
100+
const AnyMenuInfo minfoStatusCardsDmnd = { "Dmnd", 36, 0xffff, 0, NO_CALLBACK };
101+
ActionMenuItem menuStatusCardsDmnd(&minfoStatusCardsDmnd, nullptr, INFO_LOCATION_PGM);
102+
const AnyMenuInfo minfoStatusCardsHrts = { "Hrts", 35, 0xffff, 0, NO_CALLBACK };
103+
ActionMenuItem menuStatusCardsHrts(&minfoStatusCardsHrts, &menuStatusCardsDmnd, INFO_LOCATION_PGM);
104+
const AnyMenuInfo minfoStatusCardsClub = { "Club", 34, 0xffff, 0, NO_CALLBACK };
105+
ActionMenuItem menuStatusCardsClub(&minfoStatusCardsClub, &menuStatusCardsHrts, INFO_LOCATION_PGM);
106+
const AnyMenuInfo minfoStatusCardsAce = { "Ace", 33, 0xffff, 0, NO_CALLBACK };
107+
ActionMenuItem menuStatusCardsAce(&minfoStatusCardsAce, &menuStatusCardsClub, INFO_LOCATION_PGM);
108+
const SubMenuInfo minfoStatusCards = { "Cards", 32, 0xffff, 0, NO_CALLBACK };
109+
BackMenuItem menuBackStatusCards(&minfoStatusCards, &menuStatusCardsAce, INFO_LOCATION_PGM);
110+
SubMenuItem menuStatusCards(&minfoStatusCards, &menuBackStatusCards, &menuStatus, INFO_LOCATION_PGM);
100111
const AnyMenuInfo minfo78 = { "78", 21, 0xffff, 0, NO_CALLBACK };
101-
ActionMenuItem menu78(&minfo78, &menuStatus, INFO_LOCATION_PGM);
112+
ActionMenuItem menu78(&minfo78, &menuStatusCards, INFO_LOCATION_PGM);
102113
const AnyMenuInfo minfo45 = { "45", 20, 0xffff, 0, NO_CALLBACK };
103114
ActionMenuItem menu45(&minfo45, &menu78, INFO_LOCATION_PGM);
104115
const AnyMenuInfo minfo33 = { "33", 19, 0xffff, 0, NO_CALLBACK };

examples/arduino32/stm32DuinoDemo/generated/stm32DuinoDemo_menu.h

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ extern AnalogMenuItem menuStatusMotor;
6868
extern AnalogMenuItem menuStatusCurrent;
6969
extern BackMenuItem menuBackStatus;
7070
extern SubMenuItem menuStatus;
71+
extern ActionMenuItem menuStatusCardsDmnd;
72+
extern ActionMenuItem menuStatusCardsHrts;
73+
extern ActionMenuItem menuStatusCardsClub;
74+
extern ActionMenuItem menuStatusCardsAce;
75+
extern BackMenuItem menuBackStatusCards;
76+
extern SubMenuItem menuStatusCards;
7177
extern ActionMenuItem menu78;
7278
extern ActionMenuItem menu45;
7379
extern ActionMenuItem menu33;

examples/arduino32/stm32DuinoDemo/stm32DuinoDemo.emf

+71
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,77 @@
4545
"staticDataInRAM": false
4646
}
4747
},
48+
{
49+
"parentId": 0,
50+
"type": "subMenu",
51+
"item": {
52+
"secured": false,
53+
"name": "Cards",
54+
"variableName": "StatusCards",
55+
"id": 32,
56+
"eepromAddress": -1,
57+
"readOnly": false,
58+
"localOnly": false,
59+
"visible": true,
60+
"staticDataInRAM": false
61+
}
62+
},
63+
{
64+
"parentId": 32,
65+
"type": "actionMenu",
66+
"item": {
67+
"name": "Ace",
68+
"variableName": "StatusCardsAce",
69+
"id": 33,
70+
"eepromAddress": -1,
71+
"readOnly": false,
72+
"localOnly": false,
73+
"visible": true,
74+
"staticDataInRAM": false
75+
}
76+
},
77+
{
78+
"parentId": 32,
79+
"type": "actionMenu",
80+
"item": {
81+
"name": "Club",
82+
"variableName": "StatusCardsClub",
83+
"id": 34,
84+
"eepromAddress": -1,
85+
"readOnly": false,
86+
"localOnly": false,
87+
"visible": true,
88+
"staticDataInRAM": false
89+
}
90+
},
91+
{
92+
"parentId": 32,
93+
"type": "actionMenu",
94+
"item": {
95+
"name": "Hrts",
96+
"variableName": "StatusCardsHrts",
97+
"id": 35,
98+
"eepromAddress": -1,
99+
"readOnly": false,
100+
"localOnly": false,
101+
"visible": true,
102+
"staticDataInRAM": false
103+
}
104+
},
105+
{
106+
"parentId": 32,
107+
"type": "actionMenu",
108+
"item": {
109+
"name": "Dmnd",
110+
"variableName": "StatusCardsDmnd",
111+
"id": 36,
112+
"eepromAddress": -1,
113+
"readOnly": false,
114+
"localOnly": false,
115+
"visible": true,
116+
"staticDataInRAM": false
117+
}
118+
},
48119
{
49120
"parentId": 0,
50121
"type": "subMenu",

examples/arduino32/stm32DuinoDemo/stm32DuinoDemo.ino

+45-9
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,33 @@ const uint8_t myManualMac[] = { 0xde, 0xed, 0xbe, 0xef, 0xfe, 0xed };
3131
const uint8_t standardNetMask[] = { 255, 255, 255, 0 };
3232

3333
//
34-
// We use a card layout to present the items, here we demonstrate how to set it up and prepare custom menu items that
35-
// have different layouts and fonts.
34+
// We use a card layout to present the items, card layout means that only one item will be displayed at once on the
35+
// display with a left and right icon on the edges showing in which direction you can move between items. Below is a
36+
// somewhat rough ASCII-art example of how it may look on the display.
37+
//
38+
// / __ \ the left and right icons show when you can move in each direction
39+
// | | | | one item (whatever is actively selected) is drawn in the middle
40+
// \ -- / it is recommended that the title be disabled during card-layout menus
41+
//
42+
// This demonstrates how to set up card layout for both the root menu and also an additional sub menu, preparing
43+
// custom drawing using icons or larger fonts for those items.
3644
//
3745
// START card layout and custom layout code
3846

47+
// Some helpful guides for working with card layouts and theme builder:
48+
// 1. https://tcmenu.github.io/documentation/arduino-libraries/tc-menu/creating-and-using-bitmaps-menu/
49+
// 2. https://tcmenu.github.io/documentation/arduino-libraries/tc-menu/themes/rendering-with-themes-icons-grids/
50+
3951
// here we provide two title widgets, for ethernet connection, and client connection
4052
TitleWidget widgetConnection(iconsConnection, 2, 16, 12, nullptr);
4153
TitleWidget widgetEthernet(iconsEthernetConnection, 2, 16, 12, &widgetConnection);
4254

4355
color_t defaultCardPalette[] = {1, 0, 1, 1};
4456

45-
void setupGridLayoutForCardView() {
57+
void overrideDrawingForMainMenu(TcThemeBuilder& themeBuilder) {
4658
// we're going to use this a few times so declare once
4759
const Coord iconSize(APPICONS_WIDTH, APPICONS_HEIGHT);
4860

49-
// create a theme builder to help us configure how to draw.
50-
TcThemeBuilder themeBuilder(renderer);
51-
52-
// enable card layout providing the left and right icons. This enables for root menu
53-
themeBuilder.enableCardLayoutWithXbmImages(Coord(11, 22), ArrowHoriz11x22BitmapLeft, ArrowHoriz11x22BitmapRight, true);
54-
5561
// override menu33 to draw text centered in a large font with more padding
5662
themeBuilder.menuItemOverride(menu33)
5763
.withJustification(tcgfx::GridPosition::JUSTIFY_CENTER_NO_VALUE)
@@ -89,6 +95,36 @@ void setupGridLayoutForCardView() {
8995
.withPalette(defaultCardPalette)
9096
.onRow(4)
9197
.withDrawingMode(tcgfx::GridPosition::DRAW_AS_ICON_ONLY).apply();
98+
99+
themeBuilder.menuItemOverride(menuStatusCards)
100+
.withImageXbmp(Coord(32, 32), cardIconBitmap)
101+
.onRow(5)
102+
.withPalette(defaultCardPalette)
103+
.withJustification(tcgfx::GridPosition::JUSTIFY_CENTER_NO_VALUE)
104+
.apply();
105+
}
106+
107+
void overrideDrawingForCardMenu(TcThemeBuilder& themeBuilder) {
108+
// override every single item on the card menu to have larger font and different padding/justification
109+
themeBuilder.submenuPropertiesActionOverride(menuStatusCards)
110+
.withJustification(tcgfx::GridPosition::JUSTIFY_CENTER_NO_VALUE)
111+
.withNativeFont(u8g2_font_inr33_mn, 1)
112+
.withPadding(MenuPadding(2))
113+
.apply();
114+
}
115+
116+
void setupGridLayoutForCardView() {
117+
// create a theme builder to help us configure how to draw.
118+
TcThemeBuilder themeBuilder(renderer);
119+
120+
// enable card layout providing the left and right icons. This enables for root menu
121+
themeBuilder.enableCardLayoutWithXbmImages(Coord(11, 22), ArrowHoriz11x22BitmapLeft, ArrowHoriz11x22BitmapRight, true)
122+
.setMenuAsCard(menuStatusCards, true);
123+
124+
// see the method above where we override drawing for all items that are in card layout.
125+
overrideDrawingForMainMenu(themeBuilder);
126+
overrideDrawingForCardMenu(themeBuilder);
127+
92128
// now we make the two settings and status menus use icons instead of regular drawing.
93129
themeBuilder.apply();
94130

0 commit comments

Comments
 (0)