Skip to content

Commit 14365a1

Browse files
committed
#138 #173 on touch control, when items overflow show scroll icons. Start of touch keyboard.
1 parent 22e4229 commit 14365a1

14 files changed

Lines changed: 557 additions & 193 deletions

‎cmake/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_library(tcMenu
3333
../src/graphics/MenuTouchScreenEncoder.cpp
3434
../src/graphics/RuntimeTitleMenuItem.cpp
3535
../src/graphics/TcDrawableButton.cpp
36+
../src/graphics/TcTouchKeyboardController.cpp
3637
../src/graphics/TcThemeBuilder.cpp
3738
../src/remote/BaseBufferedRemoteTransport.cpp
3839
../src/remote/BaseRemoteComponents.cpp

‎library.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"authors": "tcmenu"
2727
}
2828
],
29-
"version": "5.0.1",
29+
"version": "5.1.0",
3030
"license": "Apache-2.0",
3131
"frameworks": "arduino, mbed",
3232
"platforms": "*"

‎library.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
name=tcMenu
7-
version=5.0.1
7+
version=5.1.0
88
maintainer=www.thecoderscorner.com
99
author=davetcc
1010
category=Other

‎src/graphics/BaseGraphicalRenderer.cpp‎

Lines changed: 32 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "BaseGraphicalRenderer.h"
77
#include "BaseDialog.h"
88
#include "RuntimeTitleMenuItem.h"
9+
#include "TcTouchKeyboardController.h"
910

1011
namespace tcgfx {
1112

@@ -110,96 +111,17 @@ void BaseGraphicalRenderer::subMenuRender(MenuItem* rootItem, uint8_t& locRedraw
110111

111112
}
112113

113-
GridPositionRowCacheEntry* BaseGraphicalRenderer::findMenuEntryAndDimensions(const Coord& screenPos, Coord& localStart, Coord& localSize) {
114-
// 1. Bail out if a modal dialog is active or display has been taken over
115-
if((dialog!=nullptr && dialog->isRenderNeeded()) || displayTakenMode != NOT_TAKEN_OVER) {
116-
return nullptr;
117-
}
118-
119-
// 2. Handle runtime list rendering mode (lists manage their own row/title coordinates)
120-
if(currentRootMenu && currentRootMenu->getMenuType() == MENUTYPE_RUNTIME_LIST) {
121-
auto* runList = reinterpret_cast<ListRuntimeMenuItem*>(currentRootMenu);
122-
auto* itemProps = getDisplayPropertiesFactory().configFor(runList, ItemDisplayProperties::COMPTYPE_ITEM);
123-
auto* titleProps = getDisplayPropertiesFactory().configFor(runList, ItemDisplayProperties::COMPTYPE_TITLE);
124-
int titleHeight = titleProps->getRequiredHeight() + titleProps->getSpaceAfter();
125-
int rowHeight = itemProps->getRequiredHeight() + + itemProps->getSpaceAfter();
126-
if(screenPos.y < titleHeight) {
127-
// Touch landed within list title area
128-
cachedEntryItem = GridPositionRowCacheEntry(runList, GridPosition(GridPosition::DRAW_TITLE_ITEM, GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT, 0, titleHeight), titleProps);
129-
return &cachedEntryItem;
130-
}
131-
else {
132-
// Touch landed within list items: calculate zero-based row index clamped to list size
133-
auto rowNum = internal_min(int((screenPos.y - titleHeight) / rowHeight), int(runList->getNumberOfRows() - 1));
134-
cachedEntryItem = GridPositionRowCacheEntry(runList, GridPosition(GridPosition::DRAW_TEXTUAL_ITEM, GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT, rowNum + 1, titleHeight), titleProps);
135-
return &cachedEntryItem;
136-
}
137-
}
138-
139-
if((isRawTouchMode())) {
140-
return nullptr;
141-
}
142-
143-
// 3. If title is pinned at the top (TITLE_ALWAYS), calculate title height and check if touched
144-
int rowStartY = 0;
145-
if(titleMode == TITLE_ALWAYS) {
146-
auto* titleProps = getDisplayPropertiesFactory().configFor(nullptr, ItemDisplayProperties::COMPTYPE_TITLE);
147-
rowStartY = titleProps->getRequiredHeight() + titleProps->getSpaceAfter();
148-
if(screenPos.y <= rowStartY) {
149-
return itemOrderByRow.itemAtIndex(0);
150-
}
151-
}
152-
153-
// 4a. Set up the iteration for the below, and get the width of the edit/select icon (if any)
154-
auto* icon = getDisplayPropertiesFactory().iconForMenuItem(SPECIAL_ID_ACTIVE_ICON);
155-
int iconWidth = icon ? icon->getDimensions().x : 0;
156-
uint8_t currentRow = -1;
157-
158-
// 4b. Iterate over items from drawingLocation offset to find which row contains screenPos.y
159-
for(bsize_t i=drawingLocation.getCurrentOffset(); i<itemOrderByRow.count(); i++) {
160-
auto* pEntry = itemOrderByRow.itemAtIndex(i);
161-
int rowHeight = heightOfRow(pEntry->getPosition().getRow());
162-
int rowEndY = rowStartY + rowHeight;
163-
164-
// Skip subsequent items on the same row when computing vertical geometry (only process first item per row)
165-
if(pEntry->getPosition().getRow() == currentRow) continue;
166-
currentRow = pEntry->getPosition().getRow();
167-
168-
// 5. Check if screen touch Y position falls within the current row bounds [rowStartY, rowEndY]
169-
if(screenPos.y > rowStartY && screenPos.y < rowEndY) {
170-
localStart.y = rowStartY;
171-
localSize.y = rowHeight;
172-
if(pEntry->getPosition().getGridSize() == 1) {
173-
// Single column: entire row width belongs to this item (adjusted for active icon)
174-
auto iconAdjust = iconWidth + pEntry->getDisplayProperties()->getPadding().left;
175-
localStart.x = iconAdjust;
176-
localSize.x = int(width) - iconAdjust;
177-
return pEntry;
178-
}
179-
else {
180-
// Multi column: divide total width into equal segments based on gridSize
181-
// Calculate zero-based column index from screenPos.x, then lookup 1-based col key (column + 1)
182-
int colWidth = int(width) / pEntry->getPosition().getGridSize();
183-
int column = (screenPos.x / colWidth);
184-
localStart.x = column * colWidth;
185-
localSize.x = colWidth;
186-
return itemOrderByRow.getByKey(rowCol(pEntry->getPosition().getRow(), column + 1));
187-
}
188-
}
189-
// Advance rowStartY past this row and its trailing margin
190-
rowStartY += rowHeight + pEntry->getDisplayProperties()->getSpaceAfter();
191-
}
192-
193-
// 6. No item matched at given screen coordinate
194-
return nullptr;
195-
}
196-
197114
bool BaseGraphicalRenderer::drawTheMenuItems(int startRow, int startY, bool drawEveryLine) {
198115
int16_t ypos = startY;
199116
int lastRow = 0;
200117
int addAmount = 0;
201118
bool didDrawTitle = false;
202119
uint16_t totalHeight = 0;
120+
uint16_t availWidth = width;
121+
122+
if (isHasTouchInterface() && (currentRootMenu->getMenuType() == MENUTYPE_RUNTIME_LIST || totalGridHeight() > height)) {
123+
availWidth -= TC_KEYBOARD_BUTTON_SIZE;
124+
}
203125

204126
for(bsize_t i=startRow; i < itemOrderByRow.count(); i++) {
205127
auto* itemCfg = itemOrderByRow.itemAtIndex(i);
@@ -216,13 +138,13 @@ bool BaseGraphicalRenderer::drawTheMenuItems(int startRow, int startY, bool draw
216138
item->setChanged(displayNumber, false);
217139
taskManager.yieldForMicros(0);
218140
if(itemCfg->getPosition().getGridSize() > 1) {
219-
int colWidth = int(width) / itemCfg->getPosition().getGridSize();
141+
int colWidth = int(availWidth) / itemCfg->getPosition().getGridSize();
220142
int colOffset = colWidth * (itemCfg->getPosition().getGridPosition() - 1);
221143
drawMenuItem(itemCfg, Coord(colOffset, int(ypos)), Coord(colWidth - 1, int(itemCfg->getHeight())),
222144
DrawingFlags(drawEveryLine, item == activeItem, item == menuMgr.getCurrentEditor()));
223145
}
224146
else {
225-
drawMenuItem(itemCfg, Coord(0, ypos), Coord(int(width), int(itemCfg->getHeight())), DrawingFlags(drawEveryLine, item == activeItem, item == menuMgr.getCurrentEditor()));
147+
drawMenuItem(itemCfg, Coord(0, ypos), Coord(int(availWidth), int(itemCfg->getHeight())), DrawingFlags(drawEveryLine, item == activeItem, item == menuMgr.getCurrentEditor()));
226148
}
227149
if(itemCfg->getPosition().getDrawingMode() == GridPosition::DRAW_TITLE_ITEM && itemCfg->getPosition().getRow() == 0) {
228150
didDrawTitle = true;
@@ -258,17 +180,22 @@ void BaseGraphicalRenderer::renderList() {
258180
uint8_t offset = 0;
259181
while((currentActive - offset) > maxOnScreen) offset++;
260182

183+
uint16_t availWidth = width;
184+
if (isHasTouchInterface()) {
185+
availWidth -= TC_KEYBOARD_BUTTON_SIZE;
186+
}
187+
261188
cachedEntryItem = GridPositionRowCacheEntry(runList->asBackMenu(), GridPosition(GridPosition::DRAW_TITLE_ITEM,
262189
titleProps->getDefaultJustification(),
263190
0, titleHeight), titleProps);
264-
drawMenuItem(&cachedEntryItem, Coord(0, 0), Coord((int)width, titleHeight), DrawingFlags(true, currentActive == 0, false));
191+
drawMenuItem(&cachedEntryItem, Coord(0, 0), Coord(availWidth, titleHeight), DrawingFlags(true, currentActive == 0, false));
265192

266193
for (int i = 0; i <= maxOnScreen; i++) {
267194
uint8_t current = offset + i;
268195
if(current >= runList->getNumberOfRows()) break;
269196
RuntimeMenuItem* toDraw = runList->getChildItem(current);
270197
cachedEntryItem = GridPositionRowCacheEntry(toDraw, GridPosition(GridPosition::DRAW_TEXTUAL_ITEM, GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT, current + 1, rowHeight), itemProps);
271-
drawMenuItem(&cachedEntryItem, Coord(0, totalTitleHeight), Coord((int)width, rowHeight), DrawingFlags(true, (currentActive-1) == (offset + i), false));
198+
drawMenuItem(&cachedEntryItem, Coord(0, totalTitleHeight), Coord(availWidth, rowHeight), DrawingFlags(true, (currentActive-1) == (offset + i), false));
272199
taskManager.yieldForMicros(0);
273200
totalTitleHeight += totalRowHeight;
274201
}
@@ -436,6 +363,19 @@ GridPositionRowCacheEntry* BaseGraphicalRenderer::firstItemOnRow(int row) {
436363
return rowData;
437364
}
438365

366+
int BaseGraphicalRenderer::totalGridHeight() const {
367+
int totalItemHeights = 0;
368+
for(int i=0; i<itemOrderByRow.count(); i++) {
369+
auto rowEntry = itemOrderByRow.itemAtIndex(i);
370+
if(rowEntry == nullptr || rowEntry->getPosition().getGridPosition() > 1) continue;
371+
auto itemHeight = rowEntry->getPosition().getGridHeight();
372+
auto actualHeight = itemHeight != 0 ? itemHeight : rowEntry->getDisplayProperties()->getRequiredHeight();
373+
actualHeight += rowEntry->getDisplayProperties()->getSpaceAfter();
374+
totalItemHeights += actualHeight;
375+
}
376+
return totalItemHeights;
377+
}
378+
439379
int BaseGraphicalRenderer::heightOfRow(int row, bool includeSpace) {
440380
GridPositionRowCacheEntry *rowData = firstItemOnRow(row);
441381

@@ -517,6 +457,10 @@ void BaseGraphicalRenderer::setTitleMode(BaseGraphicalRenderer::TitleMode mode)
517457
menuMgr.changeMenu(menuMgr.getCurrentMenu());
518458
}
519459

460+
void BaseGraphicalRenderer::setHasTouchInterface(bool hasTouch) {
461+
bitWrite(flags, GFX_USING_TOUCH_INTERFACE, hasTouch);
462+
}
463+
520464
BaseGraphicalRenderer::BaseGraphicalRenderer(int bufferSize, int wid, int hei, bool lastRowExact,const char *appTitle)
521465
: BaseMenuRenderer(bufferSize, RENDER_TYPE_CONFIGURABLE), navigationListener(this) {
522466
width = wid;

‎src/graphics/BaseGraphicalRenderer.h‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,11 @@ namespace tcgfx {
159159
*/
160160
MenuItem *getCurrentRendererRoot() { return currentRootMenu; }
161161

162-
private:
162+
protected:
163163
RenderingNavigationListener navigationListener;
164164
MenuItem *currentRootMenu;
165165
const char *pgmTitle;
166166
GridPositionRowCacheEntry cachedEntryItem;
167-
protected:
168167
BtreeList<uint16_t, GridPositionRowCacheEntry> itemOrderByRow;
169168
TitleMode titleMode = TITLE_FIRST_ROW;
170169
uint16_t width, height;
@@ -197,7 +196,7 @@ namespace tcgfx {
197196
* Enable touch support within the renderer
198197
* @param hasTouch true to enable touch
199198
*/
200-
void setHasTouchInterface(bool hasTouch) { bitWrite(flags, GFX_USING_TOUCH_INTERFACE, hasTouch); }
199+
virtual void setHasTouchInterface(bool hasTouch);
201200
/**
202201
* Set the title as on, so it appears on the display, somewhat internal to the library, control from the theme
203202
* @param titleOn true to turn on
@@ -316,16 +315,6 @@ namespace tcgfx {
316315
*/
317316
uint8_t itemCount(MenuItem* root, bool) override;
318317

319-
/**
320-
* Provides the menu item grid position and dimensions of it, given a screen position. Usually used by touch screen
321-
* implementations. Note that this will return nullptr if no entry is found.
322-
* @param screenPos the raw screen position
323-
* @param localStart the local menu item start position
324-
* @param localSize the local menu item size
325-
* @return the grid cache entry or nullptr if no item was found.
326-
*/
327-
GridPositionRowCacheEntry* findMenuEntryAndDimensions(const Coord &screenPos, Coord &localStart, Coord &localSize);
328-
329318
/**
330319
* Gets the menu item at a given index, which may be different to the order in the tree.
331320
*/
@@ -377,11 +366,29 @@ namespace tcgfx {
377366
* @param forceDrawWidgets reference to widgets force update flag, will be updated.
378367
*/
379368
virtual void subMenuRender(MenuItem* rootItem, uint8_t& locRedrawMode, bool& forceDrawWidgets);
369+
370+
/**
371+
* Calculates the height of a specific row in the grid, optionally including space after the item.
372+
* @param row the index of the row to calculate the height for
373+
* @param includeSpace whether to include the space after the item in the calculation
374+
* @return the height of the row, including space if specified
375+
*/
380376
int heightOfRow(int row, bool includeSpace=false);
377+
378+
/**
379+
* Calculates the total height of the grid, including space after each item.
380+
* @return the total height of the grid
381+
*/
382+
int totalGridHeight() const;
383+
384+
/**
385+
* Used to render the list of menu items, you can override this method to customize the rendering behavior.
386+
* Normally to provide some extra actions before or after the rendering process.
387+
*/
388+
virtual void renderList();
381389
private:
382390
bool drawTheMenuItems(int startRow, int startY, bool drawEveryLine);
383391

384-
void renderList();
385392

386393
void recalculateDisplayOrder(MenuItem *pItem, bool safeMode);
387394

0 commit comments

Comments
 (0)