-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use rspotify::model::SimplifiedPlaylist; | ||
|
||
pub mod playlist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use cushy::{styles::components::WidgetBackground, value::{Destination, Dynamic, IntoDynamic, IntoValue, Source, Value}, widget::{MakeWidget, WidgetList}, widgets::{grid::Orientation, Image, Stack}}; | ||
use rspotify::model::SimplifiedPlaylist; | ||
use cushy::kludgine::Color; | ||
|
||
use crate::widgets::{image::ImageExt, ActivePage, SelectedPage}; | ||
|
||
fn playlist_entry(playlist: impl IntoValue<SimplifiedPlaylist>, selected_page: SelectedPage) -> impl MakeWidget { | ||
let playlist: Value<SimplifiedPlaylist> = playlist.into_value(); | ||
let id = playlist.map(|p| p.id.clone()); | ||
let background = selected_page.map_each(move |page| { | ||
match page { | ||
ActivePage::Playlist(p) if p.id == id => { | ||
Color(0xFFFFFF10) | ||
} | ||
_ => Color::CLEAR_WHITE | ||
} | ||
}); | ||
Image::new_empty() | ||
.with_url( | ||
playlist | ||
.map_each(|playlist| playlist.images.first().map(|image| image.url.clone())) | ||
.into_dynamic() | ||
) | ||
|
||
.and( | ||
playlist | ||
.map_each(|p| p.name.clone()) | ||
.align_left() | ||
.expand() | ||
) | ||
.into_columns() | ||
.into_button() | ||
.on_click(move |_| { | ||
selected_page.set(ActivePage::Playlist(playlist.get())); | ||
}) | ||
.with(&WidgetBackground, background) | ||
} | ||
|
||
pub fn playlists_widget(playlists: impl IntoValue<Vec<SimplifiedPlaylist>>, selected_page: SelectedPage) -> impl MakeWidget { | ||
let playlists: Value<Vec<SimplifiedPlaylist>> = playlists.into_value(); | ||
Stack::new( | ||
Orientation::Row, | ||
playlists | ||
.map_each(move |t| { | ||
let mut list = t.clone().into_iter().map(|playlist| playlist_entry(playlist, selected_page.clone())).collect::<WidgetList>(); | ||
list.insert(0, liked_songs_entry(selected_page.clone())); | ||
list | ||
}) | ||
) | ||
.vertical_scroll() | ||
.expand() | ||
} | ||
|
||
pub fn liked_songs_entry(selected_page: SelectedPage) -> impl MakeWidget { | ||
let background = selected_page.map_each(move |page| { | ||
match page { | ||
ActivePage::LikedSongs => { | ||
Color(0xFFFFFF10) | ||
} | ||
_ => Color::CLEAR_WHITE | ||
} | ||
}); | ||
Image::new_empty() | ||
.with_url( | ||
Dynamic::new(Some("https://misc.scdn.co/liked-songs/liked-songs-300.png".to_string())) | ||
) | ||
.and( | ||
"Liked Songs" | ||
.align_left() | ||
.expand() | ||
) | ||
.into_columns() | ||
.into_button() | ||
.on_click(move |_| { | ||
selected_page.set(ActivePage::LikedSongs); | ||
}) | ||
.with(&WidgetBackground, background) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
pub mod image; | ||
use cushy::value::Dynamic; | ||
use rspotify::model::{SimplifiedAlbum, SimplifiedPlaylist}; | ||
|
||
pub mod image; | ||
pub mod library; | ||
|
||
#[derive(PartialEq, Debug, Default)] | ||
pub enum ActivePage { | ||
#[default] | ||
LikedSongs, | ||
Playlist(SimplifiedPlaylist), | ||
Album(SimplifiedAlbum) | ||
} | ||
|
||
type SelectedPage = Dynamic<ActivePage>; |