add QueueTitleExist, fix QueueFile

This commit is contained in:
figsoda 2022-12-05 10:14:47 -05:00
parent b131fa9776
commit cd646e7914
4 changed files with 18 additions and 5 deletions

View file

@ -21,8 +21,8 @@ Config(
Min(0, Queue([
Column(
item: Ratio(12, If(QueueCurrent,
Styled([Italic], QueueTitle),
QueueTitle,
Styled([Italic], If(QueueTitleExist, QueueTitle, QueueFile)),
If(QueueTitleExist, QueueTitle, QueueFile),
)),
style: [Fg(Indexed(75))],
selected_style: [Fg(Black), Bg(Indexed(75)), Bold],

View file

@ -119,6 +119,7 @@ pub enum Condition {
TitleExist,
ArtistExist,
AlbumExist,
QueueTitleExist,
QueueCurrent,
Selected,
Searching,

View file

@ -87,9 +87,17 @@ pub fn layout() -> Widget {
Condition::QueueCurrent,
Box::new(Texts::Styled(
vec![AddStyle::Italic],
Box::new(Texts::QueueTitle),
Box::new(Texts::If(
Condition::QueueTitleExist,
Box::new(Texts::QueueTitle),
Some(Box::new(Texts::QueueFile)),
)),
)),
Some(Box::new(Texts::QueueTitle)),
Some(Box::new(Texts::If(
Condition::QueueTitleExist,
Box::new(Texts::QueueTitle),
Some(Box::new(Texts::QueueFile)),
))),
),
),
style: vec![AddStyle::Fg(Color::Indexed(75))],

View file

@ -28,6 +28,7 @@ struct FlattenState<'a, 'b> {
struct ConditionState<'a> {
status: &'a Status,
current_track: Option<&'a Track>,
queue_track: Option<&'a Track>,
queue_current: bool,
selected: bool,
searching: bool,
@ -343,7 +344,7 @@ fn _flatten<'a>(spans: &mut Vec<Span<'a>>, xs: &'a Texts, s: &FlattenState<'a, '
}
}
Texts::QueueFile => {
if let Some(Track { file, .. }) = s.current_track {
if let Some(Track { file, .. }) = s.queue_track {
spans.push(Span::styled(file, *s.style));
}
}
@ -398,6 +399,7 @@ fn _flatten<'a>(spans: &mut Vec<Span<'a>>, xs: &'a Texts, s: &FlattenState<'a, '
&ConditionState {
status: s.status,
current_track: s.current_track,
queue_track: s.queue_track,
queue_current: s.queue_current,
selected: s.selected,
searching: s.searching,
@ -417,6 +419,7 @@ fn _flatten<'a>(spans: &mut Vec<Span<'a>>, xs: &'a Texts, s: &FlattenState<'a, '
&ConditionState {
status: s.status,
current_track: s.current_track,
queue_track: s.queue_track,
queue_current: s.queue_current,
selected: s.selected,
searching: s.searching,
@ -517,6 +520,7 @@ fn eval_cond(cond: &Condition, s: &ConditionState) -> bool {
})
),
Condition::AlbumExist => matches!(s.current_track, Some(Track { album: Some(_), .. })),
Condition::QueueTitleExist => matches!(s.queue_track, Some(Track { title: Some(_), .. })),
Condition::QueueCurrent => s.queue_current,
Condition::Selected => s.selected,
Condition::Searching => s.searching,