Skip to content

Commit

Permalink
Add wrapping for bio and move stats
Browse files Browse the repository at this point in the history
  • Loading branch information
so9010 committed Oct 10, 2024
1 parent 66d15c9 commit 5c4cdfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
50 changes: 23 additions & 27 deletions psst-gui/src/ui/artist.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use druid::{
im::Vector,
kurbo::Circle,
widget::{CrossAxisAlignment, Flex, Label, LabelText, LineBreaking, List},
widget::{CrossAxisAlignment, Flex, Label, LabelText, LineBreaking, List, Scroll},
Data, Insets, LensExt, LocalizedString, Menu, MenuItem, Selector, Size, UnitPoint, Widget,
WidgetExt,
};
Expand All @@ -25,10 +25,10 @@ pub const LOAD_DETAIL: Selector<ArtistLink> = Selector::new("app.artist.load-det

pub fn detail_widget() -> impl Widget<AppState> {
Flex::column()
.with_child(Flex::row().with_child(async_artist_info()))
.with_child(async_artist_info().expand_width().padding((theme::grid(1.0), 0.0)))
.with_child(async_top_tracks_widget())
.with_child(async_albums_widget().padding((theme::grid(1.0), 0.0)))
.with_child(async_related_widget().padding((theme::grid(1.0), 0.0)))
.with_child(async_albums_widget().expand_width().padding((theme::grid(1.0), 0.0)))
.with_child(async_related_widget().expand_width().padding((theme::grid(1.0), 0.0)))
}

fn async_top_tracks_widget() -> impl Widget<AppState> {
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn cover_widget(size: f64) -> impl Widget<Artist> {
}

fn artist_info_widget() -> impl Widget<WithCtx<ArtistInfo>> {
let size = theme::grid(10.0);
let size = theme::grid(13.0);

let artist_image = RemoteImage::new(
utils::placeholder_widget(),
Expand All @@ -182,20 +182,18 @@ fn artist_info_widget() -> impl Widget<WithCtx<ArtistInfo>> {
.lens(Ctx::data());

let biography = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(header_widget("Biography"))
.with_child(
Label::raw()
.with_line_break_mode(LineBreaking::WordWrap)
.with_text_size(theme::TEXT_SIZE_SMALL)
.lens(Ctx::data().then(ArtistInfo::bio))
.expand_width(),
)
.fix_width(theme::grid(40.0));
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(header_widget("Biography"))
.with_child(Scroll::new(
Label::new(|data: &ArtistInfo, _env: &_| data.bio.clone()) // Use a closure to fetch the biography
.with_line_break_mode(LineBreaking::WordWrap)
.with_text_size(theme::TEXT_SIZE_SMALL)
.lens(Ctx::data()),)
.vertical()
.fix_height(size-theme::grid(1.5))
);

let artist_stats = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(header_widget("Artist Stats"))
let artist_stats = Flex::row()
.with_child(stat_row("Followers:", |info: &ArtistInfo| {
format!("{} followers", info.stats.followers)
}))
Expand All @@ -205,19 +203,17 @@ fn artist_info_widget() -> impl Widget<WithCtx<ArtistInfo>> {
.with_child(stat_row("Ranking:", |info: &ArtistInfo| {
format!("#{} in the world", info.stats.world_rank)
}))
.fix_width(theme::grid(20.0));
.align_left();

Flex::row()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(artist_image)
.with_spacer(theme::grid(1.0))
.with_flex_child(biography, 1.0)
.with_spacer(theme::grid(1.0))
.with_child(artist_stats)
.expand_width()
.padding(theme::grid(1.5))
.background(theme::BACKGROUND_DARK)
.rounded(theme::BUTTON_BORDER_RADIUS)
.with_flex_child(Flex::column()
.with_child(biography)
.with_spacer(theme::grid(1.0))
.with_child(artist_stats),
1.0
)
.context_menu(|artist| artist_info_menu(&artist.data))
}

Expand Down
7 changes: 1 addition & 6 deletions psst-gui/src/webapi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,7 @@ impl WebApi {
.artist_union.profile.biography.text,
)
.unwrap_or_default();
// This is roughly 3 lines of description, truncated if too long
if desc.chars().count() > 255 {
desc.chars().take(254).collect::<String>() + "..."
} else {
desc
}
desc
.into()
},

Expand Down

0 comments on commit 5c4cdfa

Please sign in to comment.