Function resolve_popup_placement

Source
pub fn resolve_popup_placement(
    input: PopupPlacementInput,
    capabilities: PopupBackendCapabilities,
) -> Result<ResolvedPopupPlacement, PopupPlacementError>
Expand description

Resolves popup side, alignment, flip, viewport clamp, and backend fallback.

Flipping occurs only when the preferred side cannot contain the resolved height and the opposite side either can contain it or offers strictly more space. The final rectangle is always clamped to the viewport, including a deterministic size reduction when the desired popup is larger than it. All input/output geometry is in global logical pixels. Validation order is anchor, desired size, viewport, then gap; backend fallback is not an error.

§Errors

Returns PopupPlacementError for invalid/missing representable geometry.

§Examples

use ailloli_ui_core::{Rect, Size}; use ailloli_ui_runtime::popup::*;
let input = PopupPlacementInput::new(Rect::new(40.0, 90.0, 20.0, 5.0), Size::new(30.0, 20.0), Rect::new(0.0, 0.0, 100.0, 100.0));
let result = resolve_popup_placement(input, PopupBackendCapabilities::overlay_only())?;
assert_eq!(result.placement(), PopupPlacement::Top);
assert_eq!(result.bounds(), Rect::new(35.0, 70.0, 30.0, 20.0));