diff --git a/neothesia/src/scene/menu_scene/iced_menu/mod.rs b/neothesia/src/scene/menu_scene/iced_menu/mod.rs index 904f1f8e..49a157b3 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/mod.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/mod.rs @@ -1,4 +1,9 @@ -use super::{icons, neo_btn::NeoBtn, Renderer}; +use super::{ + icons, + layout::{BarLayout, Layout}, + neo_btn::NeoBtn, + Renderer, +}; use iced_core::{ alignment::{Horizontal, Vertical}, image::Handle as ImageHandle, @@ -251,7 +256,7 @@ impl<'a> Step { .spacing(40) .align_items(Alignment::Center); - let mut content = top_padded(column); + let mut layout = Layout::new().body(top_padded(column)); if target.song.is_some() { let tracks = NeoBtn::new( @@ -288,10 +293,10 @@ impl<'a> Step { left: 0.0, }); - content = content.push(container); + layout = layout.bottom(BarLayout::new().right(container)); } - center_x(content).into() + layout.into() } } diff --git a/neothesia/src/scene/menu_scene/iced_menu/tracks.rs b/neothesia/src/scene/menu_scene/iced_menu/tracks.rs index e9510e9a..c531daa7 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/tracks.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/tracks.rs @@ -7,7 +7,12 @@ use iced_widget::{button, column as col, container, row, vertical_space}; use crate::{ iced_utils::iced_state::Element, - scene::menu_scene::{icons, neo_btn::NeoBtn, segment_button, track_card}, + scene::menu_scene::{ + icons, + layout::{BarLayout, Layout}, + neo_btn::NeoBtn, + segment_button, track_card, + }, song::PlayerConfig, target::Target, }; @@ -133,15 +138,6 @@ pub(super) fn view<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message> let column = iced_widget::scrollable(column); - let mut content = { - let content = column.height(Length::Fill); - - col![content] - .width(Length::Fill) - .height(Length::Fill) - .align_items(Alignment::Center) - }; - let right = { let back = NeoBtn::new( icons::left_arrow_icon() @@ -210,13 +206,8 @@ pub(super) fn view<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message> left: 0.0, }); - let left = row![].width(Length::Fill); - let center = row![center].width(Length::Fill); - let right = row![right].width(Length::Fill); - - let main = row![left, center, right].align_items(Alignment::Center); - - content = content.push(main); - - content.into() + Layout::new() + .body(column) + .bottom(BarLayout::new().center(center).right(right)) + .into() } diff --git a/neothesia/src/scene/menu_scene/layout.rs b/neothesia/src/scene/menu_scene/layout.rs new file mode 100644 index 00000000..37df7f81 --- /dev/null +++ b/neothesia/src/scene/menu_scene/layout.rs @@ -0,0 +1,141 @@ +use crate::iced_utils::iced_state::Element; +use iced_core::{Alignment, Length}; +use iced_widget::{column as col, row}; + +pub struct Layout<'a, Message> { + top: Option>, + body: Option>, + bottom: Option>, +} + +impl<'a, M: 'static> Default for Layout<'a, M> { + fn default() -> Self { + Self { + top: None, + body: None, + bottom: None, + } + } +} + +impl<'a, M: 'static> Layout<'a, M> { + pub fn new() -> Self { + Self::default() + } + + #[allow(unused)] + pub fn top(mut self, top: impl Into>) -> Self { + self.top = Some(top.into()); + self + } + + pub fn body(mut self, body: impl Into>) -> Self { + self.body = Some(body.into()); + self + } + + pub fn bottom(mut self, bottom: impl Into>) -> Self { + self.bottom = Some(bottom.into()); + self + } + + pub fn build(self) -> Element<'a, M> { + let mut root = col![].width(Length::Fill).height(Length::Fill); + + if let Some(top) = self.top { + let top = col![top].width(Length::Fill).align_items(Alignment::Center); + root = root.push(top); + } + + let body = if let Some(body) = self.body { + col![body] + } else { + col![] + }; + + let body = col![body] + .width(Length::Fill) + .height(Length::Fill) + .align_items(Alignment::Center); + root = root.push(body); + + if let Some(bottom) = self.bottom { + let bottom = col![bottom] + .width(Length::Fill) + .align_items(Alignment::Center); + root = root.push(bottom); + } + + root.into() + } +} + +impl<'a, M: 'static> From> for Element<'a, M> { + fn from(val: Layout<'a, M>) -> Self { + val.build() + } +} + +pub struct BarLayout<'a, Message> { + left: Option>, + center: Option>, + right: Option>, +} + +impl<'a, M: 'static> Default for BarLayout<'a, M> { + fn default() -> Self { + Self { + left: None, + center: None, + right: None, + } + } +} + +impl<'a, M: 'static> BarLayout<'a, M> { + pub fn new() -> Self { + Self::default() + } + + #[allow(unused)] + pub fn left(mut self, left: impl Into>) -> Self { + self.left = Some(left.into()); + self + } + + pub fn center(mut self, center: impl Into>) -> Self { + self.center = Some(center.into()); + self + } + + pub fn right(mut self, right: impl Into>) -> Self { + self.right = Some(right.into()); + self + } + + pub fn build(self) -> Element<'a, M> { + let mut left = row![].width(Length::Fill); + let mut center = row![].width(Length::Fill); + let mut right = row![].width(Length::Fill); + + if let Some(item) = self.left { + left = left.push(item); + } + if let Some(item) = self.center { + center = center.push(item); + } + if let Some(item) = self.right { + right = right.push(item); + } + + row![left, center, right] + .align_items(Alignment::Center) + .into() + } +} + +impl<'a, M: 'static> From> for Element<'a, M> { + fn from(val: BarLayout<'a, M>) -> Self { + val.build() + } +} diff --git a/neothesia/src/scene/menu_scene/mod.rs b/neothesia/src/scene/menu_scene/mod.rs index 37bfeee9..9580b2e2 100644 --- a/neothesia/src/scene/menu_scene/mod.rs +++ b/neothesia/src/scene/menu_scene/mod.rs @@ -1,6 +1,7 @@ mod iced_menu; mod icons; +mod layout; mod neo_btn; mod segment_button; mod track_card;