fn calc_relative_position(
    elem: &HtmlElement,
    _top: i32,
    left: i32,
    height: i32,
    width: i32,
) -> ModalAnchor {
    let window = web_sys::window().unwrap();
    let rect = elem.get_bounding_client_rect();
    let inner_width = window.inner_width().unwrap().as_f64().unwrap() as i32;
    let inner_height = window.inner_height().unwrap().as_f64().unwrap() as i32;
    let rect_top = rect.top() as i32;
    let rect_height = rect.height() as i32;
    let rect_width = rect.width() as i32;
    let rect_left = rect.left() as i32;

    let elem_over_y = inner_height < rect_top + rect_height;
    let elem_over_x = inner_width < rect_left + rect_width;
    let target_over_x = inner_width < rect_left + width;
    let target_over_y = inner_height < rect_top + height;

    // modal/target
    match (elem_over_y, elem_over_x, target_over_x, target_over_y) {
        (true, _, true, true) => ModalAnchor::BottomRightTopLeft,
        (true, _, true, false) => ModalAnchor::BottomRightBottomLeft,
        (true, true, false, _) => {
            if left + width - rect_width > 0 {
                ModalAnchor::BottomRightTopRight
            } else {
                ModalAnchor::BottomLeftTopLeft
            }
        }
        (true, false, false, _) => ModalAnchor::BottomLeftTopLeft,
        (false, true, true, _) => ModalAnchor::TopRightTopLeft,
        (false, true, false, _) => {
            if left + width - rect_width > 0 {
                ModalAnchor::TopRightBottomRight
            } else {
                ModalAnchor::TopLeftBottomLeft
            }
        }
        _ => ModalAnchor::TopLeftBottomLeft,
    }
}
/// Given the bounds of the target element as previous computed, as well as the
/// browser's viewport and the bounds of the already-connected
/// `<perspectuve-style-menu>` element itself, determine a new (top, left)
/// coordinates that keeps the element on-screen.
Given the bounds of the target element as previous computed, as well as the
browser's viewport and the bounds of the already-connected
`` element itself, determine a new (top, left)
coordinates that keeps the element on-screen.
Given the bounds of the target element as previous computed as well as the browser ' s viewport and the bounds of the already - connected ` ` element itself determine a new ( top left ) coordinates that keeps the element on - screen .
fn calc_relative_position(
    elem: &HtmlElement,
    _top: i32,
    left: i32,
    height: i32,
    width: i32,
) -> ModalAnchor {
    let window = web_sys::window().unwrap();
    let rect = elem.get_bounding_client_rect();
    let inner_width = window.inner_width().unwrap().as_f64().unwrap() as i32;
    let inner_height = window.inner_height().unwrap().as_f64().unwrap() as i32;
    let rect_top = rect.top() as i32;
    let rect_height = rect.height() as i32;
    let rect_width = rect.width() as i32;
    let rect_left = rect.left() as i32;
    let elem_over_y = inner_height < rect_top + rect_height;
    let elem_over_x = inner_width < rect_left + rect_width;
    let target_over_x = inner_width < rect_left + width;
    let target_over_y = inner_height < rect_top + height;
    // modal/target
    match (elem_over_y, elem_over_x, target_over_x, target_over_y) {
        (true, _, true, true) => ModalAnchor::BottomRightTopLeft,
        (true, _, true, false) => ModalAnchor::BottomRightBottomLeft,
        (true, true, false, _) => {
            if left + width - rect_width > 0 {
                ModalAnchor::BottomRightTopRight
            } else {
                ModalAnchor::BottomLeftTopLeft
            }
        }
        (true, false, false, _) => ModalAnchor::BottomLeftTopLeft,
        (false, true, true, _) => ModalAnchor::TopRightTopLeft,
        (false, true, false, _) => {
            if left + width - rect_width > 0 {
                ModalAnchor::TopRightBottomRight
            } else {
                ModalAnchor::TopLeftBottomLeft
            }
        }
        _ => ModalAnchor::TopLeftBottomLeft,
    }
}
fn calc_relative_position ( elem : & HtmlElement , _top : i32 , left : i32 , height : i32 , width : i32 , ) -> ModalAnchor { let window = web_sys :: window ( ) . unwrap ( ) ; let rect = elem . get_bounding_client_rect ( ) ; let inner_width = window . inner_width ( ) . unwrap ( ) . as_f64 ( ) . unwrap ( ) as i32 ; let inner_height = window . inner_height ( ) . unwrap ( ) . as_f64 ( ) . unwrap ( ) as i32 ; let rect_top = rect . top ( ) as i32 ; let rect_height = rect . height ( ) as i32 ; let rect_width = rect . width ( ) as i32 ; let rect_left = rect . left ( ) as i32 ; let elem_over_y = inner_height < rect_top + rect_height ; let elem_over_x = inner_width < rect_left + rect_width ; let target_over_x = inner_width < rect_left + width ; let target_over_y = inner_height < rect_top + height ; // modal/target match ( elem_over_y , elem_over_x , target_over_x , target_over_y ) { ( true , _ , true , true ) => ModalAnchor :: BottomRightTopLeft , ( true , _ , true , false ) => ModalAnchor :: BottomRightBottomLeft , ( true , true , false , _ ) => { if left + width - rect_width > 0 { ModalAnchor :: BottomRightTopRight } else { ModalAnchor :: BottomLeftTopLeft } } ( true , false , false , _ ) => ModalAnchor :: BottomLeftTopLeft , ( false , true , true , _ ) => ModalAnchor :: TopRightTopLeft , ( false , true , false , _ ) => { if left + width - rect_width > 0 { ModalAnchor :: TopRightBottomRight } else { ModalAnchor :: TopLeftBottomLeft } } _ => ModalAnchor :: TopLeftBottomLeft , } }
Given the bounds of the target element as previous computed, as well as the
browser's viewport and the bounds of the already-connected
`<perspectuve-style-menu>` element itself, determine a new (top, left)
coordinates that keeps the element on-screen.
Given the bounds of the target element as previous computed as well as the browser ' s viewport and the bounds of the already - connected ` <perspectuve - style - menu > ` element itself determine a new ( top left ) coordinates that keeps the element on - screen .
elem
&HtmlElement
_top
i32
left
i32
height
i32
width
i32
elem
&HtmlElement
_top
i32
left
i32
height
i32
width
i32