Merge pull request #17172 from hrydgard/touch-dialog-close-fix

UI: Fix weird misbehavior dragging outside a popup dialog
This commit is contained in:
Henrik Rydgård 2023-03-24 00:29:55 +01:00 committed by GitHub
commit a6e5d59d9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -48,7 +48,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceY * timeDown > 3) {
p.active |= GESTURE_DRAG_VERTICAL;
// Kill the drag
// Kill the drag. TODO: Only cancel the drag in one direction.
TouchInput inp2 = touch;
inp2.flags = TOUCH_UP | TOUCH_CANCEL;
return inp2;
@ -63,7 +63,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds
double timeDown = time_now_d() - p.downTime;
if (!p.active && p.distanceX * timeDown > 3) {
p.active |= GESTURE_DRAG_HORIZONTAL;
// Kill the drag
// Kill the drag. TODO: Only cancel the drag in one direction.
TouchInput inp2 = touch;
inp2.flags = TOUCH_UP | TOUCH_CANCEL;
return inp2;

View file

@ -228,12 +228,15 @@ PopupScreen::PopupScreen(std::string title, std::string button1, std::string but
void PopupScreen::touch(const TouchInput &touch) {
if (!box_ || (touch.flags & TOUCH_DOWN) == 0) {
// Handle down-presses here.
UIDialogScreen::touch(touch);
return;
}
// Extra bounds to avoid closing the dialog while trying to aim for something
// near the edge.
if (!box_->GetBounds().Expand(100.0f, 60.0f).Contains(touch.x, touch.y)) {
// near the edge. Now that we only close on actual down-events, we can shrink
// this border a bit.
if (!box_->GetBounds().Expand(30.0f, 30.0f).Contains(touch.x, touch.y)) {
TriggerFinish(DR_CANCEL);
}