From 98d6d67ab9a895eef4fa2ab6103253f5fe9ac52b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 6 Jan 2024 20:49:09 -0700 Subject: [PATCH] widget::popover: context menu positioning logic This keeps the popup inside the parent widget bounds, logic that is common for context menus --- src/widget/popover.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/widget/popover.rs b/src/widget/popover.rs index 8e990b31..ba745efe 100644 --- a/src/widget/popover.rs +++ b/src/widget/popover.rs @@ -237,6 +237,13 @@ where // Position is set to the center bottom of the lower widget let width = node.size().width; position.x = (position.x - width / 2.0).clamp(0.0, bounds.width - width); + } else { + // Position is using context menu logic + let size = node.size(); + position.x = position.x.clamp(0.0, bounds.width - size.width); + if position.y + size.height > bounds.height { + position.y = (position.y - size.height).clamp(0.0, bounds.height - size.height); + } } node.move_to(position);