widget/toplevel_item: Rename to size_cross_nth; take index argument
Name is a bit awkward, but useful for other purposes.
This commit is contained in:
parent
4637fcb655
commit
bcb68ab054
3 changed files with 22 additions and 16 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Msg>(children: Vec<cosmic::Element<Msg>>, axis: Axis) -> ToplevelItem<Msg> {
|
||||
ToplevelItem {
|
||||
pub fn size_cross_nth<Msg>(
|
||||
children: Vec<cosmic::Element<Msg>>,
|
||||
axis: Axis,
|
||||
index: usize,
|
||||
) -> SizeCrossNth<Msg> {
|
||||
SizeCrossNth {
|
||||
axis,
|
||||
children,
|
||||
index,
|
||||
_msg: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ToplevelItem<'a, Msg> {
|
||||
pub struct SizeCrossNth<'a, Msg> {
|
||||
axis: Axis,
|
||||
children: Vec<cosmic::Element<'a, Msg>>,
|
||||
index: usize,
|
||||
_msg: PhantomData<Msg>,
|
||||
}
|
||||
|
||||
impl<Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for ToplevelItem<'_, Msg> {
|
||||
impl<Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for SizeCrossNth<'_, Msg> {
|
||||
fn size(&self) -> Size<Length> {
|
||||
Size {
|
||||
// width: Length::Fill
|
||||
|
|
@ -83,10 +87,11 @@ impl<Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> 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<Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for ToplevelItem<'_, Msg>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Msg: 'static> From<ToplevelItem<'a, Msg>> for cosmic::Element<'a, Msg> {
|
||||
fn from(widget: ToplevelItem<'a, Msg>) -> Self {
|
||||
impl<'a, Msg: 'static> From<SizeCrossNth<'a, Msg>> for cosmic::Element<'a, Msg> {
|
||||
fn from(widget: SizeCrossNth<'a, Msg>) -> Self {
|
||||
cosmic::Element::new(widget)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue