Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 92c6fe67 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

AMADEUS: Add tabs to handle the different views

parent d13dd8e1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -54,8 +54,10 @@ dependencies = [ ...@@ -54,8 +54,10 @@ dependencies = [
"clap", "clap",
"commons", "commons",
"getset", "getset",
"hashbrown 0.13.2",
"iced", "iced",
"serde", "serde",
"smallstring",
] ]
[[package]] [[package]]
......
...@@ -6,10 +6,12 @@ authors.workspace = true ...@@ -6,10 +6,12 @@ authors.workspace = true
license.workspace = true license.workspace = true
[dependencies] [dependencies]
hashbrown.workspace = true
serde.workspace = true serde.workspace = true
clap.workspace = true clap.workspace = true
iced.workspace = true iced.workspace = true
smallstring = { path = "../smallstring" }
commons = { path = "../commons" } commons = { path = "../commons" }
amalib = { path = "../amalib" } amalib = { path = "../amalib" }
getset = { path = "../getset" } getset = { path = "../getset" }
...@@ -3,7 +3,8 @@ mod client; ...@@ -3,7 +3,8 @@ mod client;
mod constants; mod constants;
mod queue_control; mod queue_control;
mod side_panel; mod side_panel;
mod window_content; mod tabs;
mod window;
use crate::AmadeusConfig; use crate::AmadeusConfig;
use iced::{ use iced::{
...@@ -20,7 +21,7 @@ pub struct Amadeus { ...@@ -20,7 +21,7 @@ pub struct Amadeus {
client: client::Client, client: client::Client,
queue_control: queue_control::QueueControl, queue_control: queue_control::QueueControl,
side_panel: side_panel::SidePanel, side_panel: side_panel::SidePanel,
window_content: window_content::WindowContent, window: window::Window,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
...@@ -53,7 +54,7 @@ pub enum Message { ...@@ -53,7 +54,7 @@ pub enum Message {
/// Got a message for the different tabs inside the window / the main /// Got a message for the different tabs inside the window / the main
/// content returned a message. /// content returned a message.
WindowContent(window_content::Message), Window(window::Message),
} }
impl Application for Amadeus { impl Application for Amadeus {
...@@ -71,7 +72,7 @@ impl Application for Amadeus { ...@@ -71,7 +72,7 @@ impl Application for Amadeus {
client: client::Client::new(), client: client::Client::new(),
queue_control: queue_control::QueueControl::new(), queue_control: queue_control::QueueControl::new(),
side_panel: side_panel::SidePanel::new(), side_panel: side_panel::SidePanel::new(),
window_content: window_content::WindowContent::new(), window: window::Window::new(),
}, },
Command::none(), Command::none(),
) )
...@@ -136,10 +137,7 @@ impl Application for Amadeus { ...@@ -136,10 +137,7 @@ impl Application for Amadeus {
Message::SidePanel(message) => self.side_panel.update(message).map(Message::SidePanel), Message::SidePanel(message) => self.side_panel.update(message).map(Message::SidePanel),
// Dispatch to main window content. // Dispatch to main window content.
Message::WindowContent(message) => self Message::Window(message) => self.window.update(message).map(Message::Window),
.window_content
.update(message)
.map(Message::WindowContent),
// On notifications we update only the queue controler for now, in // On notifications we update only the queue controler for now, in
// the future we may update something else. // the future we may update something else.
...@@ -169,7 +167,7 @@ impl Application for Amadeus { ...@@ -169,7 +167,7 @@ impl Application for Amadeus {
row![ row![
column![self.side_panel.view().map(Message::SidePanel)].padding(10), column![self.side_panel.view().map(Message::SidePanel)].padding(10),
vertical_rule(2), vertical_rule(2),
column![self.window_content.view().map(Message::WindowContent)].padding(10), column![self.window.view().map(Message::Window)].padding(10),
] ]
] ]
.into() .into()
......
use super::constants::*; use super::constants::*;
use commons::log;
use iced::{widget::text, Command, Element}; use iced::{widget::text, Command, Element};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
...@@ -16,6 +17,7 @@ impl SidePanel { ...@@ -16,6 +17,7 @@ impl SidePanel {
} }
pub fn update(&mut self, message: Message) -> Command<Message> { pub fn update(&mut self, message: Message) -> Command<Message> {
log::info!("got message {message:?}");
Command::none() Command::none()
} }
......
pub mod playlist;
pub mod queue;
pub mod search;
use crate::amadeus::constants::*;
use commons::log;
use iced::{widget::text, Command, Element};
use smallstring::SmallString;
#[derive(Debug, Clone, Copy)]
pub enum Message {}
#[derive(Debug, Clone)]
pub struct Playlist {
name: SmallString,
}
impl Playlist {
pub fn new(name: SmallString) -> Self {
Self { name }
}
pub fn update(&mut self, message: Message) -> Command<Message> {
log::info!("got message {message:?} for playlist {}", self.name);
Command::none()
}
pub fn view(&self) -> Element<Message> {
text(format!("playlist {}...", self.name))
.size(TEXT_SIZE)
.into()
}
}
use super::constants::*; use crate::amadeus::constants::*;
use commons::log;
use iced::{widget::text, Command, Element}; use iced::{widget::text, Command, Element};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
...@@ -8,18 +9,19 @@ pub enum Message {} ...@@ -8,18 +9,19 @@ pub enum Message {}
struct State {} struct State {}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct WindowContent {} pub struct Queue {}
impl WindowContent { impl Queue {
pub fn new() -> Self { pub fn new() -> Self {
Self {} Self {}
} }
pub fn update(&mut self, message: Message) -> Command<Message> { pub fn update(&mut self, message: Message) -> Command<Message> {
log::info!("got message {message:?}");
Command::none() Command::none()
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
text("window content...").size(TEXT_SIZE).into() text("queue...").size(TEXT_SIZE).into()
} }
} }
use crate::amadeus::constants::*;
use commons::log;
use iced::{widget::text, Command, Element};
#[derive(Debug, Clone, Copy)]
pub enum Message {}
#[derive(Debug, Clone)]
struct State {}
#[derive(Debug, Clone)]
pub struct Search {}
impl Search {
pub fn new() -> Self {
Self {}
}
pub fn update(&mut self, message: Message) -> Command<Message> {
log::info!("got message {message:?}");
Command::none()
}
pub fn view(&self) -> Element<Message> {
text("search...").size(TEXT_SIZE).into()
}
}
use crate::amadeus::{constants::*, tabs};
use commons::log;
use hashbrown::HashMap;
use iced::{widget::text, Command, Element};
use smallstring::SmallString;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub enum View {
#[default]
Queue,
Search,
Playlist(SmallString),
}
#[derive(Debug, Clone)]
pub enum Message {
Playlist(SmallString, tabs::playlist::Message),
Search(tabs::search::Message),
Queue(tabs::queue::Message),
ChangeView(View),
LoadPlaylistAndRetry(SmallString, tabs::playlist::Message),
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct State(View);
#[derive(Debug, Clone)]
pub struct Window {
state: State,
tab_search: tabs::search::Search,
tab_queue: tabs::queue::Queue,
tabs_playlists: HashMap<SmallString, tabs::playlist::Playlist>,
}
impl Window {
pub fn new() -> Self {
Self {
state: State(Default::default()),
tab_search: tabs::search::Search::new(),
tab_queue: tabs::queue::Queue::new(),
tabs_playlists: Default::default(),
}
}
pub fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Playlist(name, message) => match self.tabs_playlists.get_mut(&name) {
Some(tab_playlist) => tab_playlist
.update(message)
.map(move |message| Message::Playlist(name.clone(), message)),
None => Command::perform(async { () }, move |()| {
Message::LoadPlaylistAndRetry(name, message)
}),
},
Message::Search(message) => self.tab_search.update(message).map(Message::Search),
Message::Queue(message) => self.tab_queue.update(message).map(Message::Queue),
Message::ChangeView(view) => {
log::info!("change window view to {view:?}");
log::error!("handle playlist loading and queue refresh...");
self.state = State(view);
Command::none()
}
message => {
log::info!("ignored message {message:?}");
Command::none()
}
}
}
pub fn view(&self) -> Element<Message> {
match self.state.0 {
View::Queue => self.tab_queue.view().map(Message::Queue),
View::Search => self.tab_search.view().map(Message::Search),
View::Playlist(ref name) => match self.tabs_playlists.get(name) {
Some(tab_playlist) => tab_playlist
.view()
.map(move |message| Message::Playlist(name.clone(), message)),
None => text(format!("playlist {name} is not loaded..."))
.size(TITLE_SIZE)
.into(),
},
}
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter