clean up code

This commit is contained in:
figsoda 2020-10-30 17:41:00 -04:00
parent 9e1ec98d17
commit f6bf51fbf5

View file

@ -33,20 +33,13 @@ pub fn render(
}); });
for x in xs { for x in xs {
match x { let (w, constraint) = match x {
Constrained::Free(w) => { Constrained::Free(w) => (w, Constraint::Min(1)),
ws.push(w); Constrained::Fixed(n, w) => (w, Constraint::Length(*n)),
cs.push(Constraint::Min(0)); Constrained::Ratio(n, w) => (w, Constraint::Ratio(*n, denom)),
} };
Constrained::Fixed(n, w) => { ws.push(w);
ws.push(w); cs.push(constraint);
cs.push(Constraint::Length(*n));
}
Constrained::Ratio(n, w) => {
ws.push(w);
cs.push(Constraint::Ratio(*n, denom));
}
}
} }
let layout = Layout::default() let layout = Layout::default()
@ -74,21 +67,15 @@ pub fn render(
}); });
for x in xs { for x in xs {
match x { let (w, constraint) = match x {
Constrained::Free(w) => { Constrained::Free(w) => (w, Constraint::Min(1)),
ws.push(w); Constrained::Fixed(n, w) => (w, Constraint::Length(*n)),
cs.push(Constraint::Min(0)); Constrained::Ratio(n, w) => (w, Constraint::Ratio(*n, denom)),
} };
Constrained::Fixed(n, w) => { ws.push(w);
ws.push(w); cs.push(constraint);
cs.push(Constraint::Length(*n));
}
Constrained::Ratio(n, w) => {
ws.push(w);
cs.push(Constraint::Ratio(*n, denom));
}
}
} }
let layout = Layout::default() let layout = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints(cs); .constraints(cs);
@ -123,45 +110,26 @@ pub fn render(
} }
}); });
let len = columns.capacity();
let current_track = if let Some(Song { pos, .. }) = status.song { let current_track = if let Some(Song { pos, .. }) = status.song {
queue.get(pos) queue.get(pos)
} else { } else {
None None
}; };
for column in columns { for column in columns {
match column { let (xs, constraint) = match column {
Constrained::Free(xs) => { Constrained::Free(xs) => (xs, Constraint::Min(1)),
let mut items = Vec::with_capacity(len); Constrained::Fixed(n, xs) => (xs, Constraint::Length(*n)),
for x in queue { Constrained::Ratio(n, xs) => (xs, Constraint::Ratio(*n, denom)),
let mut spans = Vec::new(); };
flatten(&mut spans, xs, status, current_track, Some(x)); let mut items = Vec::with_capacity(len);
items.push(ListItem::new(Spans::from(spans))); for x in queue {
} let mut spans = Vec::new();
ws.push(List::new(items)); flatten(&mut spans, xs, status, current_track, Some(x));
cs.push(Constraint::Min(1)); items.push(ListItem::new(Spans::from(spans)));
}
Constrained::Fixed(n, xs) => {
let mut items = Vec::with_capacity(len);
for x in queue {
let mut spans = Vec::new();
flatten(&mut spans, xs, status, current_track, Some(x));
items.push(ListItem::new(Spans::from(spans)));
}
ws.push(List::new(items));
cs.push(Constraint::Length(*n));
}
Constrained::Ratio(n, xs) => {
let mut items = Vec::with_capacity(len);
for x in queue {
let mut spans = Vec::new();
flatten(&mut spans, xs, status, current_track, Some(x));
items.push(ListItem::new(Spans::from(spans)));
}
ws.push(List::new(items));
cs.push(Constraint::Ratio(*n, denom));
}
} }
ws.push(List::new(items));
cs.push(constraint);
} }
let layout = Layout::default() let layout = Layout::default()