diff --git a/src/view/mod.rs b/src/view/mod.rs index 3213170..7155765 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -327,7 +327,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem } .align_y(iced::Alignment::Center); let alpha = if is_being_dragged { 0.5 } else { 1.0 }; - crate::widgets::toplevel_item( + crate::widgets::size_cross_nth( vec![ row![ widget::button::custom(label) @@ -368,6 +368,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem .into(), ], Axis::Vertical, + 1, // Allocate width to match capture image ) //.spacing(4) //.align_items(iced::Alignment::Center) diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index e4028fd..b14ef14 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -12,8 +12,8 @@ use std::marker::PhantomData; mod image_bg; mod workspace_bar; pub use workspace_bar::workspace_bar; -mod toplevel_item; -pub use toplevel_item::toplevel_item; +mod size_cross_nth; +pub use size_cross_nth::size_cross_nth; mod mouse_interaction_wrapper; mod toplevels; pub use toplevels::toplevels; diff --git a/src/widgets/toplevel_item.rs b/src/widgets/size_cross_nth.rs similarity index 90% rename from src/widgets/toplevel_item.rs rename to src/widgets/size_cross_nth.rs index a422d80..5e9e25d 100644 --- a/src/widgets/toplevel_item.rs +++ b/src/widgets/size_cross_nth.rs @@ -1,6 +1,4 @@ -// combine widgets -// Hack: this widget defines it's width as the second child's width -// So the width of the image will be the overall width. +// This widget defines it's cross axis size as the `index`th child's size use cosmic::iced::{ advanced::{ @@ -44,21 +42,27 @@ impl AxisExt for Axis { } } -pub fn toplevel_item(children: Vec>, axis: Axis) -> ToplevelItem { - ToplevelItem { +pub fn size_cross_nth( + children: Vec>, + axis: Axis, + index: usize, +) -> SizeCrossNth { + SizeCrossNth { axis, children, + index, _msg: PhantomData, } } -pub struct ToplevelItem<'a, Msg> { +pub struct SizeCrossNth<'a, Msg> { axis: Axis, children: Vec>, + index: usize, _msg: PhantomData, } -impl Widget for ToplevelItem<'_, Msg> { +impl Widget for SizeCrossNth<'_, Msg> { fn size(&self) -> Size { Size { // width: Length::Fill @@ -83,10 +87,11 @@ impl Widget for ToplevelItem<'_, Msg> // Get layout of main widget, to set overall cross axis size let (max_width, max_height) = self.axis.pack(max_main, max_cross); let child_limits = layout::Limits::new(Size::ZERO, Size::new(max_width, max_height)); - let layout = - self.children[1] - .as_widget() - .layout(&mut tree.children[1], renderer, &child_limits); + let layout = self.children[self.index].as_widget().layout( + &mut tree.children[self.index], + renderer, + &child_limits, + ); let max_cross = self.axis.cross(layout.size()); @@ -220,8 +225,8 @@ impl Widget for ToplevelItem<'_, Msg> } } -impl<'a, Msg: 'static> From> for cosmic::Element<'a, Msg> { - fn from(widget: ToplevelItem<'a, Msg>) -> Self { +impl<'a, Msg: 'static> From> for cosmic::Element<'a, Msg> { + fn from(widget: SizeCrossNth<'a, Msg>) -> Self { cosmic::Element::new(widget) } }