Function clamp_popup_to_viewport

Source
pub fn clamp_popup_to_viewport(
    bounds: Rect,
    viewport: Rect,
) -> Result<Rect, PopupPlacementError>
Expand description

Clamps popup bounds to a viewport without tracking a requested side.

Both size and origin are corrected: oversize dimensions shrink to viewport dimensions, then origin clamps so all edges remain inside. Inputs/output are global logical pixels.

§Errors

Invalid bounds map to UnrepresentableGeometry; invalid/empty viewport uses its specific validation error.

§Examples

use ailloli_ui_core::Rect; use ailloli_ui_runtime::popup::{clamp_popup_to_viewport, PopupPlacementError};
assert_eq!(clamp_popup_to_viewport(Rect::new(-5.0, 8.0, 30.0, 20.0), Rect::new(0.0, 0.0, 10.0, 10.0))?, Rect::new(0.0, 0.0, 10.0, 10.0));