style changes

This commit is contained in:
Daniel Bulant 2024-11-20 15:52:52 +01:00
parent 16c6a2c2a5
commit 8cf183e5c8
No known key found for this signature in database
5 changed files with 111 additions and 75 deletions

26
Cargo.lock generated
View file

@ -467,9 +467,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "attribute-derive"
version = "0.10.2"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1800e974930e9079c965b9ffbcb6667a40401063a26396c7b4f15edc92da690"
checksum = "0053e96dd3bec5b4879c23a138d6ef26f2cb936c9cdc96274ac2b9ed44b5bb54"
dependencies = [
"attribute-derive-macro",
"derive-where",
@ -481,9 +481,9 @@ dependencies = [
[[package]]
name = "attribute-derive-macro"
version = "0.10.2"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d908eb786ef94296bff86f90130b3b748b49401dc81fd2bb8b3dccd44cfacbd"
checksum = "463b53ad0fd5b460af4b1915fe045ff4d946d025fb6c4dc3337752eaa980f71b"
dependencies = [
"collection_literals",
"interpolator",
@ -1179,7 +1179,7 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
[[package]]
name = "cushy"
version = "0.4.0"
source = "git+https://github.com/khonsulabs/cushy.git?branch=main#620ab2dc44cd3ea9c6c3c61ca0086fee42baef37"
source = "git+https://github.com/khonsulabs/cushy.git?branch=main#477ce9bc45b71f0f7e8ddd53ef3e3800eaea15d1"
dependencies = [
"ahash",
"alot",
@ -1209,7 +1209,7 @@ dependencies = [
[[package]]
name = "cushy-macros"
version = "0.4.0"
source = "git+https://github.com/khonsulabs/cushy.git?branch=main#620ab2dc44cd3ea9c6c3c61ca0086fee42baef37"
source = "git+https://github.com/khonsulabs/cushy.git?branch=main#477ce9bc45b71f0f7e8ddd53ef3e3800eaea15d1"
dependencies = [
"attribute-derive",
"manyhow",
@ -2886,7 +2886,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "kludgine"
version = "0.11.0"
source = "git+https://github.com/khonsulabs/kludgine#3d7b7164230449f914fa48cc4ccdf2d28b7188f2"
source = "git+https://github.com/khonsulabs/kludgine#c4be86b402a0eb911e2489292526f77b8dd0dfc0"
dependencies = [
"ahash",
"alot",
@ -2985,7 +2985,7 @@ dependencies = [
[[package]]
name = "librespot-audio"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"aes",
"bytes",
@ -3005,7 +3005,7 @@ dependencies = [
[[package]]
name = "librespot-core"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"aes",
"base64 0.22.1",
@ -3062,7 +3062,7 @@ dependencies = [
[[package]]
name = "librespot-metadata"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"async-trait",
"bytes",
@ -3079,7 +3079,7 @@ dependencies = [
[[package]]
name = "librespot-oauth"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"log",
"oauth2",
@ -3090,7 +3090,7 @@ dependencies = [
[[package]]
name = "librespot-playback"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"futures-util",
"librespot-audio",
@ -3110,7 +3110,7 @@ dependencies = [
[[package]]
name = "librespot-protocol"
version = "0.5.0"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#b52a176c3076285006c6d39c6a0455e2b1033790"
source = "git+https://github.com/photovoltex/librespot.git?branch=integrate-dealer#1b9192b52a983f5aca2c145621393ac0d12ace1a"
dependencies = [
"protobuf",
"protobuf-codegen",

View file

@ -22,7 +22,7 @@
alsa-lib
cargo-flamegraph
# cargo-flamegraph
];
in {
config.devshells.default = {

View file

@ -40,13 +40,15 @@ static CLIENT: LazyLock<ClientWithMiddleware> = LazyLock::new(|| {
impl ImageExt for Image {
fn new_empty() -> Self {
Image::new(Dynamic::new(get_empty_texture()))
// println!("new empty");
Image::new(Dynamic::new(get_empty_texture())).aspect_fit()
}
/// Makes the image connected to a URL
/// Calling this multiple times on a single image may cause memory leaks
fn load_url(&mut self, url: Dynamic<Option<String>>) -> CallbackHandle {
// let texture = Dynamic::new(get_empty_texture());
// println!("load_url called");
match &mut self.contents {
Value::Constant(_) => self.contents = Value::Dynamic(Dynamic::new(get_empty_texture())),
Value::Dynamic(dynamic) => dynamic.set(get_empty_texture()),
@ -64,7 +66,6 @@ impl ImageExt for Image {
if texture_count <= 1 {
return Err(CallbackDisconnected);
}
println!("loading url {:?}", url);
let guard = tokio_runtime().enter();
let url = url.clone();
let prev_request_join = prev_request_join.clone();
@ -75,7 +76,6 @@ impl ImageExt for Image {
if let Some(prev_request_join) = prev_request_join.take() {
prev_request_join.abort();
}
println!("loading url {:?}", url);
if let Some(url) = url {
let texture = texture.clone();
let client = client.clone();
@ -83,7 +83,7 @@ impl ImageExt for Image {
let response = client.get(url).send().await.unwrap();
let bytes = response.bytes().await.unwrap();
let image = image::load_from_memory(&bytes).unwrap();
// let image = image.resize(128, 128, FilterType::Lanczos3);
let image = image.resize(128, 128, FilterType::Lanczos3);
let image_texture = LazyTexture::from_image(
image,
cushy::kludgine::wgpu::FilterMode::Linear,

View file

@ -1,7 +1,8 @@
use cushy::figures::units::Lp;
use cushy::figures::Size;
use cushy::kludgine::Color;
use cushy::styles::{Dimension, DimensionRange};
use cushy::styles::{CornerRadii, Dimension, DimensionRange};
use cushy::widgets::image::ImageCornerRadius;
use cushy::{
value::{Destination, Dynamic, IntoDynamic, IntoValue, Source, Value},
widget::{MakeWidget, WidgetList},
@ -88,6 +89,8 @@ where
let (background, background_hover) = get_colors(is_active);
Image::new_empty()
.with_url(url)
.with(&ImageCornerRadius, Dimension::Lp(Lp::points(4)))
.size(Size::squared(Dimension::Lp(Lp::points(40))))
.and(text.into_value().align_left())
.into_columns()
.into_button()

View file

@ -3,12 +3,14 @@ use std::{
sync::{Arc, RwLock},
};
use chrono::TimeDelta;
use cushy::{
figures::{units::Lp, Size},
styles::{Dimension, DimensionRange},
styles::{CornerRadii, Dimension, DimensionRange, Edges},
value::{Destination, Dynamic, Source},
widget::{MakeWidget, WidgetInstance},
widgets::{
image::ImageCornerRadius,
label::{Displayable, LabelOverflow},
Image, Label, Space, VirtualList,
},
@ -88,7 +90,7 @@ impl LikedSongsPage {
{
pages_loading.write().unwrap().insert(page);
tokio_runtime().spawn(async move {
println!("Loading page {} idx {}", page, index);
// println!("Loading page {} idx {}", page, index);
let saved_tracks = context
.current_user_saved_tracks(
Some(PER_PAGE as _),
@ -100,7 +102,7 @@ impl LikedSongsPage {
// pages_loading.write().unwrap().remove(&page);
return;
};
println!("Loaded page {} got tracks {}", page, saved_tracks.total);
// println!("Loaded page {} got tracks {}", page, saved_tracks.total);
total_tracks.set(saved_tracks.total as usize);
tracks.map_mut(|mut tracks| {
for (i, track) in saved_tracks.items.into_iter().enumerate() {
@ -114,6 +116,11 @@ impl LikedSongsPage {
let track = tracks.map_each(move |tracks| tracks.get(&index).cloned());
index
.to_string()
.size(Size {
width: Dimension::Lp(Lp::points(40)).into(),
height: DimensionRange::default(),
})
.fit_horizontally()
.and({
get_or_create_track_image(&track_images, index, || {
Image::new_empty()
@ -123,78 +130,104 @@ impl LikedSongsPage {
.map(|track| track.track.album.images[0].url.clone())
}))
.size(Size::squared(Dimension::Lp(Lp::points(40))))
.with(&ImageCornerRadius, Dimension::Lp(Lp::points(4)))
.make_widget()
})
.size(Size::squared(Dimension::Lp(Lp::points(40))))
})
.and(track.map_each(|track| {
.and(
track
.as_ref()
.map(|track| {
Label::new(track.track.name.clone())
.overflow(LabelOverflow::Clip)
.and(
Label::new(
(track.track.artists)
.iter()
.map(|artist| artist.name.clone())
.join(", "),
)
.overflow(LabelOverflow::Clip),
)
.into_rows()
.make_widget()
})
.unwrap_or(Space::primary().make_widget())
}))
.and(track.map_each(|track| {
track
.as_ref()
.map(|track| {
.map_each(|track| {
track
.track
.album
.name
.clone()
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
.as_ref()
.map(|track| {
Label::new(track.track.name.clone())
.overflow(LabelOverflow::Clip)
.align_left()
.and(
Label::new(
(track.track.artists)
.iter()
.map(|artist| artist.name.clone())
.join(", "),
)
.overflow(LabelOverflow::Clip)
.align_left(),
)
.into_rows()
.make_widget()
})
.unwrap_or(Space::primary().make_widget())
})
.unwrap_or(Space::primary().make_widget())
}))
.and(track.map_each(|track| {
.align_left()
.expand_weighted(2),
)
.and(
track
.as_ref()
.map(|track| {
.map_each(|track| {
track
.added_at
.to_string()
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
.as_ref()
.map(|track| {
track
.track
.album
.name
.clone()
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
})
.unwrap_or(Space::primary().make_widget())
})
.unwrap_or(Space::primary().make_widget())
}))
.and(track.map_each(|track| {
.align_left()
.expand_weighted(1),
)
.and(
track
.as_ref()
.map(|track| {
.map_each(|track| {
track
.track
.duration
.to_string()
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
.as_ref()
.map(|track| {
track
.added_at
.format("%B %-e, %Y")
.to_string()
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
})
.unwrap_or(Space::primary().make_widget())
})
.unwrap_or(Space::primary().make_widget())
}))
.align_left()
.expand_weighted(1),
)
.and(
track
.map_each(|track| {
track
.as_ref()
.map(|track| {
format_delta(track.track.duration)
.into_label()
.overflow(LabelOverflow::Clip)
.make_widget()
})
.unwrap_or(Space::primary().make_widget())
})
.pad_by(Edges::default().with_horizontal(Dimension::Lp(Lp::points(5)))),
)
.into_columns()
.size(Size {
width: DimensionRange::default(),
height: Dimension::Lp(Lp::points(60)).into(),
})
.expand_horizontally()
},
)
.expand_horizontally()
}
}
fn format_delta(delta: TimeDelta) -> String {
format!("{}:{:02}", delta.num_minutes(), delta.num_seconds() % 60)
}