Skip to main content

container_query

Function container_query 

Source
pub fn container_query<E>(
    render: impl 'static + FnOnce(Size<Pixels>, &mut Window, &mut App) -> E,
) -> ContainerQuery
where E: IntoElement,
Expand description

Construct a container query element with the given render callback. The callback receives the size the element was assigned during layout and returns the contents to display within it.

By default the element fills its parent (equivalent to .size_full()); use the Styled methods to size it differently. Because the contents don’t exist until after layout, they cannot influence the element’s size.

§Example

container_query(|size, _window, _cx| {
    if size.width < px(240.) {
        div().child("Narrow layout")
    } else {
        div().child("Wide layout")
    }
});