use ratatui::layout::Rect;
use crate::{Element, RenderCtx, Size, Surface, View};
pub struct Responsive {
breakpoint: u16,
compact: Element,
wide: Element,
}
impl Responsive {
pub fn new(breakpoint: u16, compact: Element, wide: Element) -> Self {
Self {
breakpoint,
compact,
wide,
}
}
fn select(&self, width: u16) -> &Element {
if width < self.breakpoint {
&self.compact
} else {
&self.wide
}
}
}
impl View for Responsive {
fn measure(&self, available: Size) -> Size {
self.select(available.width).measure(available)
}
fn render(&self, area: Rect, surface: &mut Surface, ctx: &RenderCtx) {
self.select(area.width).render(area, surface, ctx);
}
}