use super::*;
style! {
pub(crate) c_full_col {
FlexDirection::Column
width: Length::Percent(100.0)
height: Length::Percent(100.0)
}
pub(crate) c_action_row {
FlexDirection::Row
FlexWrap::Wrap
AlignItems::Center
width: Length::Percent(100.0)
gap: SPACE_SM
}
}
pub(crate) fn responsive_grid_columns(viewport_w: f32, max_cols: u16) -> u16 {
let fluid: u16 = if viewport_w < GRID_BP_TWO_COLS {
1
} else if viewport_w < GRID_BP_THREE_COLS {
2
} else if viewport_w < GRID_BP_FOUR_COLS {
3
} else {
4
};
fluid.clamp(1, max_cols.max(1))
}
pub(crate) fn mount_responsive_grid(children: Vec<NodeId>, max_cols: u16) -> NodeId {
let vp_sig: Signal<Size> = use_viewport_size();
let grid_style = move || -> Style {
let cols: u16 = responsive_grid_columns(vp_sig.get().get_width(), max_cols);
Style::default()
.grid(cols)
.width(Length::Percent(100.0))
.gap(SPACE_MD)
};
view! {
grid {
bind_style: grid_style
..children
}
}
}
pub(crate) fn adaptive_viewport_height(viewport_h: f32) -> f32 {
(viewport_h - VIEWPORT_CHROME_RESERVE).clamp(VIEWPORT_MIN_HEIGHT, VIEWPORT_MAX_HEIGHT)
}
pub(crate) fn mount_studio_layout(main: NodeId, rail: NodeId) -> NodeId {
let vp_sig: Signal<Size> = use_viewport_size();
let shell_style = move || -> Style {
let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
let base: Style = Style::default()
.width(Length::Percent(100.0))
.gap(SPACE_MD)
.align(AlignItems::Start);
if wide { base.row() } else { base.column() }
};
let main_style = move || -> Style {
let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
let base: Style = Style::default()
.column()
.gap(SPACE_MD)
.min_width(Length::Px(0.0));
if wide {
base.flex_grow(1.0).flex_shrink(1.0)
} else {
base.width(Length::Percent(100.0))
}
};
let rail_style = move || -> Style {
let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
let base: Style = Style::default().column().gap(SPACE_MD).flex_shrink(0.0);
if wide {
base.width(Length::Px(STUDIO_RAIL_WIDTH))
} else {
base.width(Length::Percent(100.0))
}
};
view! {
view {
bind_style: shell_style
column {
bind_style: main_style
{ main }
}
column {
bind_style: rail_style
{ rail }
}
}
}
}