Skip to content

Instantly share code, notes, and snippets.

@unktomi
Last active December 24, 2015 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unktomi/715718af279d9660258f to your computer and use it in GitHub Desktop.
Save unktomi/715718af279d9660258f to your computer and use it in GitHub Desktop.
FGeometry ComputeMenuPlacement(const FGeometry& AllottedGeometry, const FVector2D& PopupDesiredSize, EMenuPlacement PlacementMode)
{
// Compute the popup size, offset, and anchor rect in local space
const FPopupPlacement Placement(AllottedGeometry, PopupDesiredSize, PlacementMode);
// ask the application to compute the proper desktop offset for the anchor. This requires the offsets to be in desktop space.
const FVector2D NewPositionDesktopSpace = FSlateApplication::Get().CalculatePopupWindowPosition(
TransformRect(AllottedGeometry.GetAccumulatedLayoutTransform(), FSlateRect(Placement.AnchorLocalSpace.GetTopLeft() + Placement.LocalPopupOffset, Placement.AnchorLocalSpace\
.GetBottomRight() + Placement.LocalPopupOffset)),
TransformVector(AllottedGeometry.GetAccumulatedLayoutTransform(), Placement.LocalPopupSize),
Placement.Orientation);
// transform the desktop offset into local space and use that as the layout transform for the child content.
return AllottedGeometry.MakeChild(
Placement.LocalPopupSize,
FSlateLayoutTransform(TransformPoint(Inverse(AllottedGeometry.GetAccumulatedLayoutTransform()), NewPositionDesktopSpace)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment