From 7839160141d8c927c8607a6c99ed3935f47ff7b1 Mon Sep 17 00:00:00 2001 From: "alterwain@protonmail.com" Date: Sun, 22 Dec 2024 18:29:10 +0300 Subject: [PATCH] modified: src/main.rs modified: src/widget.rs --- src/main.rs | 5 ++++- src/widget.rs | 57 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index e729d71..705db7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use iced::{Background, Border, Color}; use iced::Length::Fill; use iced::{widget::container, window, Theme, Element, Settings, Task as Command}; use iced::widget::{button, column, pick_list, radio, row, scrollable, text, Column, Container}; -use widget::SplitView; +use widget::{SidebarGroup, SidebarTab, SplitView, YTWindow}; mod disk_util; mod ipod_util; @@ -61,6 +61,9 @@ impl App { return Command::done(Message::ChangeUI); } App::Loaded(state) => { + let mut g = SidebarGroup::new("Streaming".to_string()); + g.push_tab((SidebarTab::Soundcloud("Soundcloud".to_string()), Box::new(YTWindow {}))); + state.split_view.push_group(g); //state.tab_panel.update(message); } } diff --git a/src/widget.rs b/src/widget.rs index cd0c0ca..5dbebfb 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -3,7 +3,7 @@ use iced::{widget::{button, column, container, row, text, Column}, Element, Leng use crate::{theme, Message}; -pub fn basic_btn(s: &str) -> button::Button { +pub fn basic_btn(s: String) -> button::Button<'static, Message> { button(container(text(s).center().font(theme::SF_FONT).size(13.0).line_height(1.)).padding(Padding { top: 1.5, right: 2., @@ -13,7 +13,8 @@ pub fn basic_btn(s: &str) -> button::Button { } // the value T should be something, that inherits ActionWindow -enum SidebarTab { +#[derive(Clone)] +pub enum SidebarTab { Youtube(String), Spotify(String), Soundcloud(String), @@ -25,6 +26,22 @@ enum SidebarTab { Settings(String) } +impl Into for SidebarTab { + fn into(self) -> String { + match self { + SidebarTab::Youtube(a) => a, + SidebarTab::Spotify(a) => a, + SidebarTab::Soundcloud(a) => a, + SidebarTab::ITunes(a) => a, + SidebarTab::Playlists(a) => a, + SidebarTab::FileSystem(a) => a, + SidebarTab::Metadata(a) => a, + SidebarTab::FindCopies(a) => a, + SidebarTab::Settings(a) => a, + } + } +} + pub struct SidebarGroup { tabs: Vec<(SidebarTab, Box)>, name: String @@ -38,32 +55,30 @@ impl SidebarGroup { pub fn name(&self) -> &String { &self.name } + + pub fn push_tab(&mut self, t: (SidebarTab, Box)) { + self.tabs.push(t); + } } -/*impl Into> for SidebarGroup { - fn into(self) -> Element<'static, Message> { - container(row![ - text!(), - - ]).into() - } -}*/ - -impl From for Element<'_, Message> { - fn from(value: SidebarGroup) -> Self { - container(row![ - text(value.name), +impl From<&SidebarGroup> for Element<'_, Message> { + fn from(value: &SidebarGroup) -> Self { + container(column![ + text(value.name.clone()), column( value.tabs .iter() - .map(|i| container(text(i.0))) - .collect() + .map(|i| { + let s: String = i.0.clone().into(); + basic_btn(s).into() + }) + .collect::>>() ) ]).into() } } -trait ActionWindow { +pub trait ActionWindow { fn view(&self) -> Element; fn update(&mut self, message: Message) -> Command; } @@ -101,7 +116,7 @@ impl SplitView { pub fn view(&self) -> Element { row![ column( - self.sidebar.iter_mut() + self.sidebar.iter() .map(|f| f.into()) .collect::>>() ), @@ -117,6 +132,10 @@ impl SplitView { Command::none() } + pub fn push_group(&mut self, group: SidebarGroup) { + self.sidebar.push(group); + } + pub fn new() -> Self { Self{ sidebar: Vec::new(), selected: None } }