ScrollView: Don't have drags of the "opposite" orientation cancel clicks.

This commit is contained in:
Henrik Rydgård committed 2026-05-10 23:41:39 +02:00
1 parent 3de6865380
commit 2c0f562ff5
4 files changed
+16 -4

No files matched your search

+2 -2
View File
@@ -48,7 +48,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
const float dragThreshold = 5.0f / g_display.dpi_scale_y;
if (p.distanceY > p.distanceX) {
if ((gestureMask_ & GESTURE_DRAG_VERTICAL) && p.distanceY > p.distanceX) {
if (p.down) {
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceY > dragThreshold) {
@@ -63,7 +63,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
}
}
if (p.distanceX > p.distanceY) {
if ((gestureMask_ & GESTURE_DRAG_HORIZONTAL) && p.distanceX > p.distanceY) {
if (p.down) {
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceX > dragThreshold) {
+4
View File
@@ -13,6 +13,7 @@ enum Gesture {
GESTURE_DRAG_HORIZONTAL = 2,
GESTURE_TWO_FINGER_ZOOM = 4,
GESTURE_TWO_FINGER_ZOOM_ROTATE = 8,
GESTURE_ALL = 15,
};
// May track multiple gestures at the same time. You simply call GetGestureInfo
@@ -24,6 +25,7 @@ public:
void UpdateFrame();
bool IsGestureActive(Gesture gesture, int touchId) const;
bool GetGestureInfo(Gesture gesture, int touchId, float info[4]) const;
void SetGestureMask(Gesture gestureMask) { gestureMask_ = gestureMask; }
private:
enum Locals {
@@ -48,4 +50,6 @@ private:
};
Pointer pointers[MAX_PTRS]{};
Gesture gestureMask_ = GESTURE_ALL;
};
+9
View File
@@ -12,6 +12,15 @@ namespace UI {
float ScrollView::lastScrollPosX = 0;
float ScrollView::lastScrollPosY = 0;
ScrollView::ScrollView(Orientation orientation, LayoutParams *layoutParams)
: ViewGroup(layoutParams), orientation_(orientation) {
if (orientation == ORIENT_HORIZONTAL) {
gesture_.SetGestureMask(GESTURE_DRAG_HORIZONTAL);
} else {
gesture_.SetGestureMask(GESTURE_DRAG_VERTICAL);
}
}
ScrollView::~ScrollView() {
lastScrollPosX = 0;
lastScrollPosY = 0;
+1 -2
View File
@@ -8,8 +8,7 @@ namespace UI {
// A scrollview usually contains just a single child - a linear layout or similar.
class ScrollView : public ViewGroup {
public:
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0)
: ViewGroup(layoutParams), orientation_(orientation) {}
ScrollView(Orientation orientation, LayoutParams *layoutParams = nullptr);
~ScrollView();
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;