refactor(DisplayManager): add hitTestRaw() and remove touch coordinate filtering
This commit is contained in:
@@ -182,16 +182,42 @@ public:
|
||||
int height() { return _drv ? _drv->height() : 0; }
|
||||
|
||||
/// Handle dashboard touch - returns action for tapped tile, or NONE
|
||||
/// Note: x,y are already in display coordinates (transformed by driver)
|
||||
TileAction handleDashboardTouch(int x, int y) const {
|
||||
HitResult hr = hitTest(x, y);
|
||||
Serial.printf("[HIT] x=%d y=%d type=%d idx=%d _headerHeight=%d\n", x, y, (int)hr.type,
|
||||
hr.index, _headerHeight);
|
||||
HitResult hr = hitTestRaw(x, y);
|
||||
if(hr.type == UIElementType::TILE && hr.index >= 0 && hr.index < DASHBOARD_TILE_COUNT) {
|
||||
return DASHBOARD_TILES[hr.index].action;
|
||||
}
|
||||
return TileAction::NONE;
|
||||
}
|
||||
|
||||
/// Perform hit test at coordinates (already in display space, no transform)
|
||||
HitResult hitTestRaw(int x, int y) const {
|
||||
if(!_drv)
|
||||
return HitResult();
|
||||
|
||||
int dispW = _drv->width();
|
||||
int dispH = _drv->height();
|
||||
int headerH = _headerHeight;
|
||||
|
||||
// Check header
|
||||
Rect headerRect = UIElements::header(dispW, headerH);
|
||||
if(headerRect.contains(x, y)) {
|
||||
return HitResult(UIElementType::HEADER, 0, headerRect);
|
||||
}
|
||||
|
||||
// Check tiles
|
||||
for(int i = 0; i < _tileCount; i++) {
|
||||
const TileLayout& lay = _layouts[i];
|
||||
Rect tileRect(lay.x, lay.y, lay.w, lay.h);
|
||||
if(tileRect.contains(x, y)) {
|
||||
return HitResult(UIElementType::TILE, i, tileRect);
|
||||
}
|
||||
}
|
||||
|
||||
return HitResult();
|
||||
}
|
||||
|
||||
/// Perform hit test at coordinates - returns element type, index, and bounds
|
||||
HitResult hitTest(int x, int y) const {
|
||||
if(!_drv)
|
||||
|
||||
@@ -312,7 +312,7 @@ void DoorbellLogic::onSerialCommand(const String& cmd) {
|
||||
if(comma > 0) {
|
||||
int x = args.substring(0, comma).toInt();
|
||||
int y = args.substring(comma + 1).toInt();
|
||||
HitResult hr = _display->hitTest(x, y);
|
||||
HitResult hr = _display->hitTestRaw(x, y);
|
||||
Serial.printf("[Hittest] raw:(%d,%d) type:%d index:%d bounds:(%d,%d,%d,%d)\n", x, y,
|
||||
(int)hr.type, hr.index, hr.bounds.x, hr.bounds.y, hr.bounds.w, hr.bounds.h);
|
||||
Serial.printf("[Display] w:%d h:%d headerH:%d\n", _display->width(), _display->height(),
|
||||
|
||||
Reference in New Issue
Block a user