add widgets TextboxL, TextboxC, and TextboxR

This commit is contained in:
figsoda 2020-11-01 14:56:46 -05:00
parent 1de2d3a0f2
commit b65eeec849
3 changed files with 72 additions and 20 deletions

View file

@ -28,7 +28,8 @@ Config(
selected_style: [Fg(Black), Bg(Indexed(177)), Bold],
),
])),
Fixed(1, Textbox(If(Playing, Parts([
Fixed(1, Columns([
Min(0, Textbox(If(Playing, Parts([
Text("["),
CurrentElapsed,
Text("/"),
@ -49,5 +50,13 @@ Config(
CurrentFile,
)
])))),
Fixed(3, TextboxR(Parts([
If(Repeat,
If(Single, Text("🔂"), Text("🔁")),
),
If(Random, Text("🔀")),
If(Consume, Text("🔥")),
]))),
])),
]),
)

View file

@ -29,7 +29,10 @@ fn ups_default() -> f64 {
pub enum Widget {
Rows(Vec<Constrained<Widget>>),
Columns(Vec<Constrained<Widget>>),
#[serde(alias = "TextboxL")]
Textbox(Texts),
TextboxC(Texts),
TextboxR(Texts),
Queue(Vec<Column>),
}

View file

@ -1,6 +1,6 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
text::{Span, Spans},
widgets::{List, ListItem, ListState, Paragraph},
@ -109,6 +109,46 @@ pub fn render(
);
frame.render_widget(Paragraph::new(Spans::from(spans)), size);
}
Widget::TextboxC(xss) => {
let mut spans = Vec::new();
flatten(
&mut spans,
&xss,
status,
if let Some(Song { pos, .. }) = status.song {
queue.get(pos)
} else {
None
},
None,
false,
Style::default(),
);
frame.render_widget(
Paragraph::new(Spans::from(spans)).alignment(Alignment::Center),
size,
);
}
Widget::TextboxR(xss) => {
let mut spans = Vec::new();
flatten(
&mut spans,
&xss,
status,
if let Some(Song { pos, .. }) = status.song {
queue.get(pos)
} else {
None
},
None,
false,
Style::default(),
);
frame.render_widget(
Paragraph::new(Spans::from(spans)).alignment(Alignment::Right),
size,
);
}
Widget::Queue(xs) => {
let len = xs.capacity();
let mut ws = Vec::with_capacity(len);