modified: src/main.rs

modified:   src/widget.rs
This commit is contained in:
Michael Wain 2024-12-22 18:29:10 +03:00
parent f42ef80bdd
commit 7839160141
2 changed files with 42 additions and 20 deletions

View File

@ -4,7 +4,7 @@ use iced::{Background, Border, Color};
use iced::Length::Fill; use iced::Length::Fill;
use iced::{widget::container, window, Theme, Element, Settings, Task as Command}; 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 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 disk_util;
mod ipod_util; mod ipod_util;
@ -61,6 +61,9 @@ impl App {
return Command::done(Message::ChangeUI); return Command::done(Message::ChangeUI);
} }
App::Loaded(state) => { 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); //state.tab_panel.update(message);
} }
} }

View File

@ -3,7 +3,7 @@ use iced::{widget::{button, column, container, row, text, Column}, Element, Leng
use crate::{theme, Message}; use crate::{theme, Message};
pub fn basic_btn(s: &str) -> button::Button<Message> { 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 { button(container(text(s).center().font(theme::SF_FONT).size(13.0).line_height(1.)).padding(Padding {
top: 1.5, top: 1.5,
right: 2., right: 2.,
@ -13,7 +13,8 @@ pub fn basic_btn(s: &str) -> button::Button<Message> {
} }
// the value T should be something, that inherits ActionWindow // the value T should be something, that inherits ActionWindow
enum SidebarTab { #[derive(Clone)]
pub enum SidebarTab {
Youtube(String), Youtube(String),
Spotify(String), Spotify(String),
Soundcloud(String), Soundcloud(String),
@ -25,6 +26,22 @@ enum SidebarTab {
Settings(String) Settings(String)
} }
impl Into<String> 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 { pub struct SidebarGroup {
tabs: Vec<(SidebarTab, Box<dyn ActionWindow>)>, tabs: Vec<(SidebarTab, Box<dyn ActionWindow>)>,
name: String name: String
@ -38,32 +55,30 @@ impl SidebarGroup {
pub fn name(&self) -> &String { pub fn name(&self) -> &String {
&self.name &self.name
} }
pub fn push_tab(&mut self, t: (SidebarTab, Box<dyn ActionWindow>)) {
self.tabs.push(t);
}
} }
/*impl Into<Element<'_, Message>> for SidebarGroup { impl From<&SidebarGroup> for Element<'_, Message> {
fn into(self) -> Element<'static, Message> { fn from(value: &SidebarGroup) -> Self {
container(row![ container(column![
text!(), text(value.name.clone()),
]).into()
}
}*/
impl From<SidebarGroup> for Element<'_, Message> {
fn from(value: SidebarGroup) -> Self {
container(row![
text(value.name),
column( column(
value.tabs value.tabs
.iter() .iter()
.map(|i| container(text(i.0))) .map(|i| {
.collect() let s: String = i.0.clone().into();
basic_btn(s).into()
})
.collect::<Vec<Element<Message>>>()
) )
]).into() ]).into()
} }
} }
trait ActionWindow { pub trait ActionWindow {
fn view(&self) -> Element<Message>; fn view(&self) -> Element<Message>;
fn update(&mut self, message: Message) -> Command<Message>; fn update(&mut self, message: Message) -> Command<Message>;
} }
@ -101,7 +116,7 @@ impl SplitView {
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
row![ row![
column( column(
self.sidebar.iter_mut() self.sidebar.iter()
.map(|f| f.into()) .map(|f| f.into())
.collect::<Vec<Element<Message>>>() .collect::<Vec<Element<Message>>>()
), ),
@ -117,6 +132,10 @@ impl SplitView {
Command::none() Command::none()
} }
pub fn push_group(&mut self, group: SidebarGroup) {
self.sidebar.push(group);
}
pub fn new() -> Self { pub fn new() -> Self {
Self{ sidebar: Vec::new(), selected: None } Self{ sidebar: Vec::new(), selected: None }
} }