contextmenu: adjust y positioning if less than zero (#1268)

* use clamp for both x and y coords
This commit is contained in:
Jefferson González 2022-12-27 22:51:24 -08:00 committed by GitHub
parent 3fda8c0a09
commit 870d685b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 6 deletions

View File

@ -83,12 +83,8 @@ function ContextMenu:show(x, y)
local w, h = self.items.width, self.items.height
-- by default the box is opened on the right and below
if x + w >= core.root_view.size.x then
x = x - w
end
if y + h >= core.root_view.size.y then
y = y - h
end
x = common.clamp(x, 0, core.root_view.size.x - w - style.padding.x)
y = common.clamp(y, 0, core.root_view.size.y - h)
self.position.x, self.position.y = x, y
self.show_context_menu = true