Skip to content

Commit 97654e5

Browse files
committed
fix(library): stabilize shelf rendering and dragging
1 parent f2bdbae commit 97654e5

5 files changed

Lines changed: 211 additions & 99 deletions

File tree

src/ui/Ui.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,16 @@ namespace ui {
174174
case TouchSampleResult::None:
175175
return false;
176176
case TouchSampleResult::Reset:
177-
resetTouchGesture();
178-
return false;
177+
if (!touchActive_) {
178+
resetTouchGesture();
179+
return false;
180+
}
181+
touchActive_ = false;
182+
touchHoldEmitted_ = false;
183+
touchOutsideSamples_ = 0;
184+
touchStartedAtMs_ = 0;
185+
touchEvent_ = {TouchRelease, touchLastX_, touchLastY_};
186+
return touchPending_ = true;
179187
case TouchSampleResult::Contact:
180188
break;
181189
}

src/ui/Ui.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <Arduino.h>
44
#include <Arduino_GFX_Library.h>
55

6+
#include <algorithm>
67
#include <array>
78
#include <cstdint>
89
#include <expected>
@@ -35,6 +36,14 @@ namespace ui {
3536
return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
3637
}
3738

39+
constexpr Rect intersection(Rect left, Rect right) {
40+
const int16_t x = std::max(left.x, right.x);
41+
const int16_t y = std::max(left.y, right.y);
42+
const int x2 = std::min<int>(left.x + left.w, right.x + right.w);
43+
const int y2 = std::min<int>(left.y + left.h, right.y + right.h);
44+
return {x, y, static_cast<int16_t>(std::max(0, x2 - x)), static_cast<int16_t>(std::max(0, y2 - y))};
45+
}
46+
3847
constexpr Rect rotateClockwise(Rect rect, int16_t sourceWidth) {
3948
return {rect.y, static_cast<int16_t>(sourceWidth - rect.x - rect.w), rect.h, rect.w};
4049
}

0 commit comments

Comments
 (0)