Add Tab and Cover touch kinds to TouchRegistry
Extends the Kind enum with two new touch interaction types: Tab (2) and Cover (3), enabling support for additional UI element touch handling.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
// so add()/hitTest() are a single branch on the C3.
|
||||
class TouchRegistry {
|
||||
public:
|
||||
enum Kind : uint8_t { Item = 0, Back = 1 };
|
||||
enum Kind : uint8_t { Item = 0, Back = 1, Tab = 2, Cover = 3 };
|
||||
|
||||
static TouchRegistry& getInstance();
|
||||
|
||||
@@ -36,7 +36,7 @@ class TouchRegistry {
|
||||
bool hitTest(int x, int y, Kind kind, int& outId) const;
|
||||
|
||||
private:
|
||||
static constexpr size_t CAPACITY = 48; // worst case excl. keyboard grid (Phase 2)
|
||||
static constexpr size_t CAPACITY = 64; // worst case is the keyboard grid (~45 keys)
|
||||
|
||||
struct Target {
|
||||
Rect rect;
|
||||
|
||||
@@ -419,10 +419,16 @@ void BaseTheme::drawTabBar(const GfxRenderer& renderer, const Rect rect, const s
|
||||
|
||||
int currentX = rect.x + BaseMetrics::values.contentSidePadding;
|
||||
|
||||
int tabIndex = 0;
|
||||
for (const auto& tab : tabs) {
|
||||
const int textWidth =
|
||||
renderer.getTextWidth(UI_12_FONT_ID, tab.label, tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
|
||||
|
||||
// Tap target spans the label plus the inter-tab gap, full bar height.
|
||||
TouchRegistry::getInstance().add(
|
||||
Rect{currentX - 3, rect.y, textWidth + BaseMetrics::values.tabSpacing, rect.height}, tabIndex++,
|
||||
TouchRegistry::Tab);
|
||||
|
||||
// Draw underline for selected tab
|
||||
if (tab.selected) {
|
||||
if (selected) {
|
||||
@@ -495,6 +501,11 @@ void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std:
|
||||
const int bookY = rect.y;
|
||||
const int bookHeight = baseHeight;
|
||||
|
||||
// Tapping the continue-reading cover opens recentBooks[0] (home selector 0).
|
||||
if (hasContinueReading) {
|
||||
TouchRegistry::getInstance().add(Rect{bookX, bookY, bookWidth, bookHeight}, 0, TouchRegistry::Cover);
|
||||
}
|
||||
|
||||
// Bookmark dimensions (used in multiple places)
|
||||
const int bookmarkWidth = bookWidth / 8;
|
||||
const int bookmarkHeight = bookHeight / 5;
|
||||
|
||||
@@ -183,9 +183,14 @@ void LyraTheme::drawTabBar(const GfxRenderer& renderer, Rect rect, const std::ve
|
||||
renderer.fillRectDither(rect.x, rect.y, rect.width, rect.height, Color::LightGray);
|
||||
}
|
||||
|
||||
int tabIndex = 0;
|
||||
for (const auto& tab : tabs) {
|
||||
const int textWidth = renderer.getTextWidth(UI_10_FONT_ID, tab.label, EpdFontFamily::REGULAR);
|
||||
|
||||
TouchRegistry::getInstance().add(
|
||||
Rect{currentX, rect.y, textWidth + 2 * hPaddingInSelection + LyraMetrics::values.tabSpacing, rect.height},
|
||||
tabIndex++, TouchRegistry::Tab);
|
||||
|
||||
if (tab.selected) {
|
||||
if (selected) {
|
||||
renderer.fillRoundedRect(currentX, rect.y + 1, textWidth + 2 * hPaddingInSelection, rect.height - 4,
|
||||
@@ -419,6 +424,14 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std:
|
||||
coverWidth = LyraMetrics::values.homeCoverHeight * 0.6;
|
||||
}
|
||||
|
||||
// Tapping the continue-reading cover opens recentBooks[0] (home selector 0).
|
||||
if (hasContinueReading) {
|
||||
TouchRegistry::getInstance().add(
|
||||
Rect{LyraMetrics::values.contentSidePadding, tileY, coverWidth + 2 * hPaddingInSelection,
|
||||
LyraMetrics::values.homeCoverHeight + 2 * hPaddingInSelection},
|
||||
0, TouchRegistry::Cover);
|
||||
}
|
||||
|
||||
// Draw book card regardless, fill with message based on `hasContinueReading`
|
||||
// Draw cover image as background if available (inside the box)
|
||||
// Only load from SD on first render, then use stored buffer
|
||||
|
||||
@@ -99,6 +99,9 @@ void RoundedRaffTheme::drawTabBar(const GfxRenderer& renderer, Rect rect, const
|
||||
const int tabWidth = slotWidth - 8;
|
||||
const auto& tab = tabs[i];
|
||||
|
||||
TouchRegistry::getInstance().add(Rect{slotX, rect.y, slotWidth, rect.height}, static_cast<int>(i),
|
||||
TouchRegistry::Tab);
|
||||
|
||||
if (tab.selected) {
|
||||
renderer.fillRoundedRect(tabX, tabY, tabWidth, tabHeight, 18, selected ? Color::Black : Color::DarkGray);
|
||||
}
|
||||
@@ -126,6 +129,13 @@ void RoundedRaffTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, con
|
||||
const int imgY = tileY + (tileHeight - RoundedRaffMetrics::values.homeCoverHeight) / 2;
|
||||
const int tileX = RoundedRaffMetrics::values.contentSidePadding;
|
||||
|
||||
// Tapping the continue-reading cover opens recentBooks[0] (home selector 0).
|
||||
if (hasContinueReading) {
|
||||
TouchRegistry::getInstance().add(
|
||||
Rect{tileX + (tileWidth - coverWidth) / 2, imgY, coverWidth, RoundedRaffMetrics::values.homeCoverHeight}, 0,
|
||||
TouchRegistry::Cover);
|
||||
}
|
||||
|
||||
// Draw book card regardless, fill with message based on `hasContinueReading`
|
||||
// Draw cover image as background if available (inside the box)
|
||||
// Only load from SD on first render, then use stored buffer
|
||||
|
||||
Reference in New Issue
Block a user