aboutsummaryrefslogtreecommitdiff
path: root/src/ui.rs
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-04-26 23:10:08 +0530
committerkrolxon <krolyxon@tutanota.com>2024-04-26 23:10:08 +0530
commit59eed99c85957c193dba53e7311f960a6b8e916c (patch)
tree3bce84c4a52e58508a27b0ae19715ddd571e87e7 /src/ui.rs
parent8269766147962df1fce10c6617baf7d5d9300f40 (diff)
add to playlist feature
Diffstat (limited to 'src/ui.rs')
-rwxr-xr-xsrc/ui.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 2010362..0bd87af 100755
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -21,11 +21,6 @@ impl InputMode {
/// Renders the user interface widgets
pub fn render(app: &mut App, frame: &mut Frame) {
- // This is where you add new widgets.
- // See the following resources:
- // - https://docs.rs/ratatui/latest/ratatui/widgets/index.html
- // - https://github.com/ratatui-org/ratatui/tree/master/examples
-
// Layout
let layout = Layout::default()
.direction(Direction::Vertical)
@@ -46,6 +41,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
draw_search_bar(frame, app, layout[1]);
}
}
+
+ if app.playlist_popup {
+ draw_add_to_playlist(frame, app, layout[0]);
+ }
}
/// Draws the file tree browser
@@ -238,3 +237,42 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
frame.render_widget(progress_bar, size);
}
+
+fn draw_add_to_playlist(frame: &mut Frame, app: &mut App, area: Rect) {
+ let area = centered_rect(40, 50, area);
+ let mut state = ListState::default();
+ let title = Block::default()
+ .title(Title::from("Add Selected Item to: "))
+ .title(Title::from("<Esc> to Cancel".green().bold()).alignment(Alignment::Right));
+ let list = List::new(app.append_list.list.clone())
+ .block(title.borders(Borders::ALL))
+ .highlight_style(
+ Style::new()
+ .fg(Color::Cyan)
+ .bg(Color::Black)
+ .add_modifier(Modifier::BOLD)
+ .add_modifier(Modifier::REVERSED),
+ )
+ .highlight_symbol(">>")
+ .repeat_highlight_symbol(true);
+
+ state.select(Some(app.append_list.index));
+ frame.render_widget(Clear, area); //this clears out the background
+ frame.render_stateful_widget(list, area, &mut state);
+}
+
+fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
+ let popup_layout = Layout::vertical([
+ Constraint::Percentage((100 - percent_y) / 2),
+ Constraint::Percentage(percent_y),
+ Constraint::Percentage((100 - percent_y) / 2),
+ ])
+ .split(r);
+
+ Layout::horizontal([
+ Constraint::Percentage((100 - percent_x) / 2),
+ Constraint::Percentage(percent_x),
+ Constraint::Percentage((100 - percent_x) / 2),
+ ])
+ .split(popup_layout[1])[1]
+}