Skip to content

Commit dd30fe2

Browse files
committed
Improve the track page layout
This commit improves the track page layout in various aspects: * An additional column to carry the play/pause state is added. * The track number column is right aligned. Its maximum width is calculated based upon the number of tracks (before it was hardcoded to '4', assuming rightfully so 9999 tracks is pretty large). The track number column title '#' is now visually stable ontop of the actual track number.
1 parent 6faa780 commit dd30fe2

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

spotify_player/src/ui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use anyhow::{Context as AnyhowContext, Result};
1111
use ratatui::{
12-
layout::{Constraint, Layout, Rect},
12+
layout::{Alignment, Constraint, Layout, Rect},
1313
style::{Modifier, Style},
1414
text::{Line, Span, Text},
1515
widgets::{

spotify_player/src/ui/page.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use ratatui::text::Line;
99
use crate::{state::Episode, utils::format_duration};
1010

1111
use super::{
12-
config, utils, utils::construct_and_render_block, Album, Artist, ArtistFocusState, Borders,
12+
config, utils, utils::construct_and_render_block, Album, Alignment, Artist, ArtistFocusState, Borders,
1313
BrowsePageUIState, Cell, Constraint, Context, ContextPageUIState, DataReadGuard, Frame, Id,
1414
Layout, LibraryFocusState, MutableWindowState, Orientation, PageState, Paragraph,
15-
PlaylistFolderItem, Rect, Row, SearchFocusState, SharedState, Style, Table, Track,
15+
PlaylistFolderItem, Rect, Row, SearchFocusState, SharedState, Style, Table, Text, Track,
1616
UIStateGuard,
1717
};
1818
use crate::state::BidiDisplay;
@@ -972,18 +972,20 @@ fn render_track_table(
972972
.into_iter()
973973
.enumerate()
974974
.map(|(id, t)| {
975-
let (id, style) = if playing_track_uri == t.id.uri() {
975+
let track_no = (id +1).to_string();
976+
let (play_pause, style) = if playing_track_uri == t.id.uri() {
976977
(playing_id.to_string(), ui.theme.current_playing())
977978
} else {
978-
((id + 1).to_string(), Style::default())
979+
("".to_string(), Style::default())
979980
};
980981
Row::new(vec![
981982
if data.user_data.is_liked_track(t) {
982983
Cell::from(&configs.app_config.liked_icon as &str).style(ui.theme.like())
983984
} else {
984985
Cell::from("")
985986
},
986-
Cell::from(id),
987+
Cell::from(Text::from(track_no).alignment(Alignment::Right)),
988+
Cell::from(play_pause),
987989
Cell::from(to_bidi_string(&t.display_name())),
988990
Cell::from(to_bidi_string(&t.artists_info())),
989991
Cell::from(to_bidi_string(&t.album_info())),
@@ -1009,11 +1011,18 @@ fn render_track_table(
10091011
.style(style)
10101012
})
10111013
.collect::<Vec<_>>();
1014+
1015+
let n_play_pause_chars = std::cmp::max(
1016+
configs.app_config.play_icon.chars().count(),
1017+
configs.app_config.pause_icon.chars().count(),
1018+
) as u16;
1019+
let n_track_digits = (n_tracks.ilog10()+1) as u16;
10121020
let track_table = Table::new(
10131021
rows,
10141022
[
10151023
Constraint::Length(configs.app_config.liked_icon.chars().count() as u16),
1016-
Constraint::Length(4),
1024+
Constraint::Length(n_track_digits),
1025+
Constraint::Length(n_play_pause_chars),
10171026
Constraint::Fill(4),
10181027
Constraint::Fill(3),
10191028
Constraint::Fill(5),
@@ -1028,7 +1037,8 @@ fn render_track_table(
10281037
.header(
10291038
Row::new(vec![
10301039
Cell::from(""),
1031-
Cell::from("#"),
1040+
Cell::from(Text::from("#").alignment(Alignment::Right)),
1041+
Cell::from(""),
10321042
Cell::from("Title"),
10331043
Cell::from("Artists"),
10341044
Cell::from("Album"),

0 commit comments

Comments
 (0)