MainMenu
Overview
The MainMenu widget is a scroll-wheel menu container. It combines a ScrollWheelWithSelectionStyle (center item visually distinct from surrounding items) with a built-in ScrollIndicator. The screen provides item data through callbacks — MainMenu handles all wheel rendering, animation, and indicator synchronization.
This package replaces the older Menu, MenuItemNotSelected, and MenuItemSelected widgets and adds support for richer item styles, layout customization, and animation callbacks.
Bundled Files
The package includes several interdependent classes:
File |
Role |
|---|---|
|
Top-level container (Designer custom container) |
|
Surrounding (non-selected) wheel item |
|
Center (selected) wheel item |
|
Data struct describing a single item |
|
Stateless rendering helpers (header-only) |
|
Arc position indicator (managed internally) |
|
Toggle switch used by |
Components (Designer)
Name |
Type |
Size |
|---|---|---|
|
ScrollWheelWithSelectionStyle |
240×132 px |
|
ScrollIndicator instance |
36×146 px |
Item Styles
Each item is configured via MenuItemConfig::Style:
Style |
Center item |
Surrounding item |
Description |
|---|---|---|---|
|
✓ |
✓ |
Centered label text only |
|
✓ |
— (degrades to SIMPLE) |
Label + interactive |
|
✓ |
✓ |
Label + smaller hint text below |
|
✓ |
✓ |
Label + hint on same line, baseline-aligned |
|
✓ |
✓ |
Static bitmap + label |
|
✓ |
— (falls back to ICON/SIMPLE) |
Dynamic raw-pixel bitmap + label |
MenuItemConfig
struct MenuItemConfig {
Style style = SIMPLE;
// Main text (priority: msgId > msgText > msgChar)
TypedTextId msgId = TYPED_TEXT_INVALID;
TypedTextId msgIdType = TYPED_TEXT_INVALID; // font/alignment override
const Unicode::UnicodeChar* msgText = nullptr;
const char* msgChar = nullptr;
// Hint text — TIP / INLINE styles
TypedTextId tipId = TYPED_TEXT_INVALID;
TypedTextId tipIdType = TYPED_TEXT_INVALID;
const Unicode::UnicodeChar* tipText = nullptr;
const char* tipChar = nullptr;
colortype tipColor = Color::getColorFromRGB(192, 192, 192);
// Icon — ICON / ICON_EXT styles
BitmapId iconId = BITMAP_INVALID;
const uint8_t* extIcon = nullptr; // raw ABGR2222 pixels, 60×60 (ICON_EXT)
// Toggle state — TOGGLE style
bool toggleState = false;
// Per-item layout overrides (optional)
const CenterItemLayout* centerLayout = nullptr;
const ItemLayout* itemLayout = nullptr;
};
Layout Priority
Layout geometry (text positions, icon positions) is resolved in this order:
MenuItemConfig::centerLayout/itemLayout— per-item overrideMainMenu::setCenterItemLayout()/setItemLayout()— menu-wide defaultBuilt-in hardcoded defaults
API
Wheel size
void setNumberOfItems(int16_t count); // configures wheel + ScrollIndicator
int16_t getNumberOfItems();
Navigation
void selectNext(); // animated, fires middle + ended callbacks
void selectPrev(); // animated, fires middle + ended callbacks
void selectItem(int16_t index); // instant jump, no animation callbacks
uint16_t getSelectedItem();
Item callbacks
// Called for each surrounding item during scroll:
void setUpdateItemCallback(GenericCallback<MainMenuItem&, int16_t>& cb);
// Called for the center item during scroll:
void setUpdateCenterItemCallback(GenericCallback<MainMenuCenterItem&, int16_t>& cb);
Inside each callback, call item.apply(cfg) to render the item.
Animation callbacks
// Fires at the midpoint of selectNext/selectPrev animation (not fired by selectItem):
void setAnimationMiddleCallback(GenericCallback<int16_t>& cb);
// Fires when animation completes:
void setAnimationEndedCallback(GenericCallback<int16_t>& cb);
void setAnimationSteps(int16_t steps); // default: 4
Layout
void setCenterItemLayout(const CenterItemLayout& layout);
void setItemLayout(const ItemLayout& layout);
Usage in TouchGFX Designer
Import the package:
Open TouchGFX Designer
Go to
Edit→Import→Custom ContainersSelect
MainMenu.tpkg
Add to screen: drag the
MainMenucontainer onto your screen.No designer properties — all configuration is done in C++.
Usage in C++ Code
#include <gui/containers/MainMenu.hpp>
#include <gui/containers/MenuItemConfig.hpp>
// In the View header:
MainMenu mainMenu;
touchgfx::Callback<MyView, MainMenuItem&, int16_t> mItemCb;
touchgfx::Callback<MyView, MainMenuCenterItem&, int16_t> mCenterCb;
touchgfx::Callback<MyView, int16_t> mAnimMiddleCb;
touchgfx::Callback<MyView, int16_t> mAnimEndedCb;
// In setupScreen():
mItemCb.setHandler(*this, &MyView::onUpdateItem);
mCenterCb.setHandler(*this, &MyView::onUpdateCenterItem);
mAnimMiddleCb.setHandler(*this, &MyView::onAnimMiddle);
mAnimEndedCb.setHandler(*this, &MyView::onAnimEnded);
mainMenu.setUpdateItemCallback(mItemCb);
mainMenu.setUpdateCenterItemCallback(mCenterCb);
mainMenu.setAnimationMiddleCallback(mAnimMiddleCb);
mainMenu.setAnimationEndedCallback(mAnimEndedCb);
mainMenu.setNumberOfItems(5);
// Item callback:
void MyView::onUpdateItem(MainMenuItem& item, int16_t index)
{
MenuItemConfig cfg;
cfg.style = MenuItemConfig::TIP;
cfg.msgId = myItems[index].titleId;
cfg.tipChar = myItems[index].subtitle;
item.apply(cfg);
}
// Center item callback:
void MyView::onUpdateCenterItem(MainMenuCenterItem& item, int16_t index)
{
MenuItemConfig cfg;
cfg.style = MenuItemConfig::TOGGLE;
cfg.msgId = myItems[index].titleId;
cfg.toggleState = mySettings[index];
item.apply(cfg);
}
// Navigate:
mainMenu.selectNext();
mainMenu.selectPrev();
mainMenu.selectItem(2); // instant, no animation
uint16_t current = mainMenu.getSelectedItem();
Files Included
manifest.xml— package manifest (requires TouchGFX ≥ 4.26.1)content/CustomContainerExport.touchgfx— Designer container definitioncontent/CustomContainerManifest.xml— container manifestcontent/texts.xml— text databasefiles/gui/include/gui/containers/MainMenu.hpp— top-level container headerfiles/gui/src/containers/MainMenu.cppfiles/gui/include/gui/containers/MainMenuItem.hppfiles/gui/src/containers/MainMenuItem.cppfiles/gui/include/gui/containers/MainMenuCenterItem.hppfiles/gui/src/containers/MainMenuCenterItem.cppfiles/gui/include/gui/containers/MenuItemConfig.hpp— data structs (header-only)files/gui/include/gui/containers/MenuItemRenderer.hpp— rendering helpers (header-only)files/gui/include/gui/containers/ScrollIndicator.hpp+.cpp— bundled dependencyfiles/gui/include/gui/containers/Toggle.hpp+.cpp— bundled dependencyfiles/assets/fonts/— Poppins Regular, Medium, SemiBold, Italic
Dependencies
TouchGFX Framework (minimum version 4.26.1)
Poppins font family (bundled in package)
BitmapDatabase.hpp— for static icon bitmap IDs (ICONstyle)TextKeysAndLanguages.hpp— for typed text IDs