Skip to main content

responsive

Function responsive 

Source
pub fn responsive<F, V>(f: F) -> Responsive<F>
where F: Fn(Size) -> V, V: View,
Expand description

Builds a view from the viewport size (in logical pixels), like SwiftUI’s GeometryReader: use it to switch layouts at breakpoints.

use ravenrs_widgets::{HStack, Text, VStack, View, responsive, AnyView};

let layout = responsive(|size| -> AnyView {
    if size.width < 600.0 { Box::new(VStack::new((Text::new("A"), Text::new("B")))) }
    else { Box::new(HStack::new((Text::new("A"), Text::new("B")))) }
});