66#include "BaseGraphicalRenderer.h"
77#include "BaseDialog.h"
88#include "RuntimeTitleMenuItem.h"
9+ #include "TcTouchKeyboardController.h"
910
1011namespace 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-
197114bool 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+
439379int 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+
520464BaseGraphicalRenderer::BaseGraphicalRenderer(int bufferSize, int wid, int hei, bool lastRowExact,const char *appTitle)
521465 : BaseMenuRenderer(bufferSize, RENDER_TYPE_CONFIGURABLE), navigationListener(this) {
522466 width = wid;
0 commit comments