import Foundation import CoreGraphics /// Screen coordinates: prefer the parent's right side, otherwise use its left. nonisolated enum DetailPlacement { static func frame(anchor: CGRect, parent: CGRect, content: CGSize, visible: CGRect) -> CGRect { let gap: CGFloat = 4 let width = min(content.width, visible.width) let height = min(content.height, visible.height) let right = parent.maxX + gap let left = parent.minX - gap - width let candidate = right + width <= visible.maxX ? right : left let x = max(visible.minX, min(candidate, visible.maxX - width)) let y = max(visible.minY, min(anchor.maxY - height, visible.maxY - height)) return CGRect(x: x, y: y, width: width, height: height) } }