mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Completer] Fix popup going offscreen by clamping in screen coordinates
The position clamping in applyPopupWidth() was comparing popup->pos() (parent coordinates) against screen->availableGeometry() (screen coordinates). When the parent widget is not at the screen origin the clamping computed a position in the wrong coordinate space, placing the popup offscreen. Convert to global coordinates first, clamp, then map back to parent coordinates.
This commit is contained in:
parent
674e32988b
commit
bb4c489327
1 changed files with 6 additions and 3 deletions
|
|
@ -169,9 +169,12 @@ void CardCompleterStyler::applyPopupWidth()
|
|||
popup->resize(minWidth, popup->height());
|
||||
|
||||
if (!available.isEmpty()) {
|
||||
QPoint pos = popup->pos();
|
||||
pos.setX(qBound(available.left(), pos.x(), qMax(available.left(), available.right() - popup->width() + 1)));
|
||||
popup->move(pos);
|
||||
// Clamp in screen coordinates, then map back to parent coordinates.
|
||||
QPoint globalPos = popup->mapToGlobal(QPoint(0, 0));
|
||||
int clampedGlobalX =
|
||||
qBound(available.left(), globalPos.x(), qMax(available.left(), available.right() - popup->width() + 1));
|
||||
QPoint parentPos = popup->mapFromGlobal(QPoint(clampedGlobalX, globalPos.y()));
|
||||
popup->move(parentPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue