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);
|
.align_y(iced::Alignment::Center);
|
||||||
let alpha = if is_being_dragged { 0.5 } else { 1.0 };
|
let alpha = if is_being_dragged { 0.5 } else { 1.0 };
|
||||||
crate::widgets::toplevel_item(
|
crate::widgets::size_cross_nth(
|
||||||
vec![
|
vec![
|
||||||
row![
|
row![
|
||||||
widget::button::custom(label)
|
widget::button::custom(label)
|
||||||
|
|
@ -368,6 +368,7 @@ fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Elem
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
Axis::Vertical,
|
Axis::Vertical,
|
||||||
|
1, // Allocate width to match capture image
|
||||||
)
|
)
|
||||||
//.spacing(4)
|
//.spacing(4)
|
||||||
//.align_items(iced::Alignment::Center)
|
//.align_items(iced::Alignment::Center)
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ use std::marker::PhantomData;
|
||||||
mod image_bg;
|
mod image_bg;
|
||||||
mod workspace_bar;
|
mod workspace_bar;
|
||||||
pub use workspace_bar::workspace_bar;
|
pub use workspace_bar::workspace_bar;
|
||||||
mod toplevel_item;
|
mod size_cross_nth;
|
||||||
pub use toplevel_item::toplevel_item;
|
pub use size_cross_nth::size_cross_nth;
|
||||||
mod mouse_interaction_wrapper;
|
mod mouse_interaction_wrapper;
|
||||||
mod toplevels;
|
mod toplevels;
|
||||||
pub use toplevels::toplevels;
|
pub use toplevels::toplevels;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
// combine widgets
|
// This widget defines it's cross axis size as the `index`th child's size
|
||||||
// Hack: this widget defines it's width as the second child's width
|
|
||||||
// So the width of the image will be the overall width.
|
|
||||||
|
|
||||||
use cosmic::iced::{
|
use cosmic::iced::{
|
||||||
advanced::{
|
advanced::{
|
||||||
|
|
@ -44,21 +42,27 @@ impl AxisExt for Axis {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toplevel_item<Msg>(children: Vec<cosmic::Element<Msg>>, axis: Axis) -> ToplevelItem<Msg> {
|
pub fn size_cross_nth<Msg>(
|
||||||
ToplevelItem {
|
children: Vec<cosmic::Element<Msg>>,
|
||||||
|
axis: Axis,
|
||||||
|
index: usize,
|
||||||
|
) -> SizeCrossNth<Msg> {
|
||||||
|
SizeCrossNth {
|
||||||
axis,
|
axis,
|
||||||
children,
|
children,
|
||||||
|
index,
|
||||||
_msg: PhantomData,
|
_msg: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ToplevelItem<'a, Msg> {
|
pub struct SizeCrossNth<'a, Msg> {
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
children: Vec<cosmic::Element<'a, Msg>>,
|
children: Vec<cosmic::Element<'a, Msg>>,
|
||||||
|
index: usize,
|
||||||
_msg: PhantomData<Msg>,
|
_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> {
|
fn size(&self) -> Size<Length> {
|
||||||
Size {
|
Size {
|
||||||
// width: Length::Fill
|
// 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
|
// Get layout of main widget, to set overall cross axis size
|
||||||
let (max_width, max_height) = self.axis.pack(max_main, max_cross);
|
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 child_limits = layout::Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||||
let layout =
|
let layout = self.children[self.index].as_widget().layout(
|
||||||
self.children[1]
|
&mut tree.children[self.index],
|
||||||
.as_widget()
|
renderer,
|
||||||
.layout(&mut tree.children[1], renderer, &child_limits);
|
&child_limits,
|
||||||
|
);
|
||||||
|
|
||||||
let max_cross = self.axis.cross(layout.size());
|
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> {
|
impl<'a, Msg: 'static> From<SizeCrossNth<'a, Msg>> for cosmic::Element<'a, Msg> {
|
||||||
fn from(widget: ToplevelItem<'a, Msg>) -> Self {
|
fn from(widget: SizeCrossNth<'a, Msg>) -> Self {
|
||||||
cosmic::Element::new(widget)
|
cosmic::Element::new(widget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue