use fission::prelude::*;
const PHONE_BREAKPOINT: f32 = 760.0;
const TABLET_BREAKPOINT: f32 = 1_120.0;
pub struct DashboardScreen;
impl From<DashboardScreen> for Widget {
fn from(_: DashboardScreen) -> Widget {
SafeArea {
id: Some(WidgetId::explicit("dashboard.safe_area")),
child: Responsive::new(DashboardDesktop)
.id(WidgetId::explicit("dashboard.responsive"))
.case(ResponsiveCase::max_width(PHONE_BREAKPOINT, DashboardPhone))
.case(ResponsiveCase::between(
PHONE_BREAKPOINT,
TABLET_BREAKPOINT,
DashboardTablet,
))
.into(),
}
.into()
}
}
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"Declarative","value":"declarative"},{"index":1,"label":"Imperative","value":"imperative"}]}
{"id":"fission-tabs-1","index":0,"label":"Declarative","value":"declarative"}
const REPORT_LIST_MIN_WIDTH: f32 = 280.0;
const REPORT_LIST_MAX_WIDTH: f32 = 420.0;
Container::new(ReportList)
.width_length(Length::clamp(
Length::points(REPORT_LIST_MIN_WIDTH),
Length::percent(34.0),
Length::points(REPORT_LIST_MAX_WIDTH),
))
.flex_shrink(0.0)
.into()
{"id":"fission-tabs-1","index":1,"label":"Imperative","value":"imperative"}
const INSPECTOR_BREAKPOINT: f32 = 1_120.0;
let (_ctx, view) = fission::build::current::<ReportsState>();
let viewport = view.viewport_size();
let inspector_open = view.state().inspector_open;
let content: Widget = if viewport.width >= INSPECTOR_BREAKPOINT && inspector_open {
ReportsWithInspector.into()
} else {
ReportsSingleColumn.into()
};
{"id":"fission-tabs-1"}
const WIDE_CARD_BREAKPOINT: f32 = 520.0;
Responsive::new(CompactCard)
.container_query()
.case(ResponsiveCase::min_width(WIDE_CARD_BREAKPOINT, WideCard))
Question | Recommended answer |
|---|---|
Is the branch only width-based? | Use Responsive. |
Is the width clamped or proportional? | Use Length::clamp, Length::percent, Length::vw, or Length::vh. |
Is the branch driven by app state too? | Use ordinary Rust in From<Component> for Widget. |
Is this a reusable child component? | Prefer .container_query(). |
Does the layout need to be tested? | Add LiveTest resize scenarios and screenshots. |