UI: ScrollView: Improve interaction with the scroll bar thingy, avoid accidental clicks

This commit is contained in:
Henrik Rydgård 2024-01-31 09:37:11 +01:00
parent 148ae0dd4a
commit 7af6501a6f
3 changed files with 8 additions and 5 deletions

View file

@ -203,7 +203,6 @@ void GLPushBuffer::Defragment() {
info.localMemory = nullptr;
}
}
return;
}

View file

@ -144,7 +144,8 @@ bool ScrollView::Touch(const TouchInput &input) {
if (orientation_ == ORIENT_VERTICAL) {
Bob bob = ComputeBob();
float internalY = input.y - bounds_.y;
draggingBob_ = internalY >= bob.offset && internalY <= bob.offset + bob.size && input.x >= bounds_.x2() - 20.0f;
float bobMargin = 3.0f; // Add some extra margin for the touch.
draggingBob_ = internalY >= bob.offset - bobMargin && internalY <= bob.offset + bob.size + bobMargin && input.x >= bounds_.x2() - 20.0f;
barDragStart_ = bob.offset;
barDragOffset_ = internalY - bob.offset;
}
@ -165,11 +166,13 @@ bool ScrollView::Touch(const TouchInput &input) {
draggingBob_ = false;
}
// We modify the input2 we send to children, so we can cancel drags if we start scrolling, and stuff like that.
TouchInput input2;
if (CanScroll()) {
if (draggingBob_) {
input2 = input;
// Skip the gesture, do calculations directly.
// Cancel any drags/holds on the children instantly to avoid accidental click-throughs.
input2.flags = TOUCH_UP | TOUCH_CANCEL;
// Skip the gesture manager, do calculations directly.
// Might switch to the gesture later.
Bob bob = ComputeBob();
float internalY = input.y - bounds_.y;
@ -216,7 +219,7 @@ ScrollView::Bob ScrollView::ComputeBob() const {
if (ratio < 1.0f && scrollMax > 0.0f) {
bob.show = true;
bob.thickness = draggingBob_ ? 15.0f : 5.0f;
bob.thickness = draggingBob_ ? 15.0f : 6.0f;
bob.size = ratio * bounds_.h;
bob.offset = (HardClampedScrollPos(scrollPos_) / scrollMax) * (bounds_.h - bob.size);
bob.scrollMax = scrollMax;

View file

@ -219,6 +219,7 @@ void __CtrlSetAnalogXY(int stick, float x, float y)
u8 scaledX = clamp_u8((int)ceilf(x * 127.5f + 127.5f));
// TODO: We might have too many negations of Y...
u8 scaledY = clamp_u8((int)ceilf(-y * 127.5f + 127.5f));
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaledX;
ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaledY;