row_col_toplevel_layout: Add a new method

This commit is contained in:
Ian Douglas Scott 2025-04-08 15:58:49 -07:00 committed by Ian Douglas Scott
parent 5349f0f3d0
commit 1fd7a86ecc
2 changed files with 6 additions and 5 deletions

View file

@ -15,11 +15,8 @@ use toplevel_layout::{LayoutToplevel, RowColToplevelLayout, ToplevelLayout};
pub fn toplevels<Msg>(children: Vec<cosmic::Element<Msg>>) -> Toplevels<Msg> {
Toplevels {
layout: RowColToplevelLayout {
// TODO configurable
spacing: 16,
axis: Axis::Horizontal,
},
// TODO configurable
layout: RowColToplevelLayout::new(Axis::Horizontal, 16),
children,
_msg: PhantomData,
}

View file

@ -11,6 +11,10 @@ pub(crate) struct RowColToplevelLayout {
}
impl RowColToplevelLayout {
pub fn new(axis: Axis, spacing: u32) -> Self {
Self { axis, spacing }
}
// Get total requested main axis length if widget could have all the space
pub fn requested_main_total(&self, toplevels: &[LayoutToplevel<'_, AxisSize>]) -> f32 {
let total_spacing = self.spacing as usize * (toplevels.len().saturating_sub(1)).max(0);