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; info.localMemory = nullptr;
} }
} }
return; return;
} }

View file

@ -144,7 +144,8 @@ bool ScrollView::Touch(const TouchInput &input) {
if (orientation_ == ORIENT_VERTICAL) { if (orientation_ == ORIENT_VERTICAL) {
Bob bob = ComputeBob(); Bob bob = ComputeBob();
float internalY = input.y - bounds_.y; 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; barDragStart_ = bob.offset;
barDragOffset_ = internalY - bob.offset; barDragOffset_ = internalY - bob.offset;
} }
@ -165,11 +166,13 @@ bool ScrollView::Touch(const TouchInput &input) {
draggingBob_ = false; 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; TouchInput input2;
if (CanScroll()) { if (CanScroll()) {
if (draggingBob_) { if (draggingBob_) {
input2 = input; // Cancel any drags/holds on the children instantly to avoid accidental click-throughs.
// Skip the gesture, do calculations directly. input2.flags = TOUCH_UP | TOUCH_CANCEL;
// Skip the gesture manager, do calculations directly.
// Might switch to the gesture later. // Might switch to the gesture later.
Bob bob = ComputeBob(); Bob bob = ComputeBob();
float internalY = input.y - bounds_.y; float internalY = input.y - bounds_.y;
@ -216,7 +219,7 @@ ScrollView::Bob ScrollView::ComputeBob() const {
if (ratio < 1.0f && scrollMax > 0.0f) { if (ratio < 1.0f && scrollMax > 0.0f) {
bob.show = true; bob.show = true;
bob.thickness = draggingBob_ ? 15.0f : 5.0f; bob.thickness = draggingBob_ ? 15.0f : 6.0f;
bob.size = ratio * bounds_.h; bob.size = ratio * bounds_.h;
bob.offset = (HardClampedScrollPos(scrollPos_) / scrollMax) * (bounds_.h - bob.size); bob.offset = (HardClampedScrollPos(scrollPos_) / scrollMax) * (bounds_.h - bob.size);
bob.scrollMax = scrollMax; 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)); u8 scaledX = clamp_u8((int)ceilf(x * 127.5f + 127.5f));
// TODO: We might have too many negations of Y... // TODO: We might have too many negations of Y...
u8 scaledY = clamp_u8((int)ceilf(-y * 127.5f + 127.5f)); u8 scaledY = clamp_u8((int)ceilf(-y * 127.5f + 127.5f));
std::lock_guard<std::mutex> guard(ctrlMutex); std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaledX; ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaledX;
ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaledY; ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = scaledY;