Completed the refactor and upgrade to Ratatui v0.26. Next up: Refactoring all of the "draw_" functions into custom widgets for more ergonomic and extensible DevX
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use ratatui::layout::{Alignment, Constraint, Rect};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::text::Text;
|
||||
use ratatui::widgets::{Cell, ListItem, Paragraph, Row};
|
||||
use ratatui::Frame;
|
||||
@@ -13,8 +13,8 @@ use crate::ui::radarr_ui::collections::{draw_collection_details, draw_collection
|
||||
use crate::ui::radarr_ui::library::draw_library;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::{
|
||||
borderless_block, get_width_from_percentage, horizontal_chunks, layout_block,
|
||||
layout_paragraph_borderless, title_block_centered, vertical_chunks_with_margin,
|
||||
borderless_block, get_width_from_percentage, layout_block, layout_paragraph_borderless,
|
||||
title_block_centered,
|
||||
};
|
||||
use crate::ui::{
|
||||
draw_button, draw_drop_down_menu_button, draw_drop_down_popup, draw_error_popup,
|
||||
@@ -40,7 +40,7 @@ impl DrawUi for AddMovieUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Radarr(active_radarr_block, context_option) = *app.get_current_route() {
|
||||
let draw_add_movie_search_popup =
|
||||
|f: &mut Frame<'_>, app: &mut App<'_>, area: Rect| match active_radarr_block {
|
||||
@@ -80,21 +80,9 @@ impl DrawUi for AddMovieUi {
|
||||
match active_radarr_block {
|
||||
_ if ADD_MOVIE_BLOCKS.contains(&active_radarr_block) => {
|
||||
if context_option.is_some() {
|
||||
draw_large_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_collections,
|
||||
draw_add_movie_search_popup,
|
||||
)
|
||||
draw_large_popup_over(f, app, area, draw_collections, draw_add_movie_search_popup)
|
||||
} else {
|
||||
draw_large_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_library,
|
||||
draw_add_movie_search_popup,
|
||||
)
|
||||
draw_large_popup_over(f, app, area, draw_library, draw_add_movie_search_popup)
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
@@ -112,15 +100,13 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
AddMovieSearchResult::default()
|
||||
};
|
||||
|
||||
let chunks = vertical_chunks_with_margin(
|
||||
vec![
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(3),
|
||||
],
|
||||
area,
|
||||
1,
|
||||
);
|
||||
let [search_box_area, results_area, help_area] = Layout::vertical([
|
||||
Constraint::Length(3),
|
||||
Constraint::Fill(0),
|
||||
Constraint::Length(3),
|
||||
])
|
||||
.margin(1)
|
||||
.areas(area);
|
||||
let block_content = &app.data.radarr_data.search.as_ref().unwrap().text;
|
||||
let offset = *app
|
||||
.data
|
||||
@@ -137,7 +123,7 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_text_box(
|
||||
f,
|
||||
TextBoxProps {
|
||||
text_box_area: chunks[0],
|
||||
text_box_area: search_box_area,
|
||||
block_title: Some("Add Movie"),
|
||||
block_content,
|
||||
offset,
|
||||
@@ -146,16 +132,16 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
cursor_after_string: true,
|
||||
},
|
||||
);
|
||||
f.render_widget(layout_block(), chunks[1]);
|
||||
f.render_widget(layout_block(), results_area);
|
||||
|
||||
let help_text = Text::from(build_context_clue_string(&BARE_POPUP_CONTEXT_CLUES).help());
|
||||
let help_paragraph = Paragraph::new(help_text)
|
||||
.block(borderless_block())
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(help_paragraph, chunks[2]);
|
||||
f.render_widget(help_paragraph, help_area);
|
||||
}
|
||||
ActiveRadarrBlock::AddMovieEmptySearchResults => {
|
||||
f.render_widget(layout_block(), chunks[1]);
|
||||
f.render_widget(layout_block(), results_area);
|
||||
draw_error_popup(f, "No movies found matching your query!");
|
||||
}
|
||||
ActiveRadarrBlock::AddMovieSearchResults
|
||||
@@ -171,11 +157,11 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let help_paragraph = Paragraph::new(help_text)
|
||||
.block(borderless_block())
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(help_paragraph, chunks[2]);
|
||||
f.render_widget(help_paragraph, help_area);
|
||||
|
||||
draw_table(
|
||||
f,
|
||||
chunks[1],
|
||||
results_area,
|
||||
layout_block(),
|
||||
TableProps {
|
||||
content: None,
|
||||
@@ -269,7 +255,7 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_text_box(
|
||||
f,
|
||||
TextBoxProps {
|
||||
text_box_area: chunks[0],
|
||||
text_box_area: search_box_area,
|
||||
block_title: Some("Add Movie"),
|
||||
block_content,
|
||||
offset,
|
||||
@@ -280,14 +266,14 @@ fn draw_add_movie_search(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_confirmation_popup(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_confirmation_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Radarr(active_radarr_block, _) = *app.get_current_route() {
|
||||
match active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSelectMonitor => {
|
||||
draw_drop_down_popup(
|
||||
f,
|
||||
app,
|
||||
prompt_area,
|
||||
area,
|
||||
draw_confirmation_prompt,
|
||||
draw_add_movie_select_monitor_popup,
|
||||
);
|
||||
@@ -296,7 +282,7 @@ fn draw_confirmation_popup(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Re
|
||||
draw_drop_down_popup(
|
||||
f,
|
||||
app,
|
||||
prompt_area,
|
||||
area,
|
||||
draw_confirmation_prompt,
|
||||
draw_add_movie_select_minimum_availability_popup,
|
||||
);
|
||||
@@ -305,7 +291,7 @@ fn draw_confirmation_popup(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Re
|
||||
draw_drop_down_popup(
|
||||
f,
|
||||
app,
|
||||
prompt_area,
|
||||
area,
|
||||
draw_confirmation_prompt,
|
||||
draw_add_movie_select_quality_profile_popup,
|
||||
);
|
||||
@@ -314,20 +300,20 @@ fn draw_confirmation_popup(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Re
|
||||
draw_drop_down_popup(
|
||||
f,
|
||||
app,
|
||||
prompt_area,
|
||||
area,
|
||||
draw_confirmation_prompt,
|
||||
draw_add_movie_select_root_folder_popup,
|
||||
);
|
||||
}
|
||||
ActiveRadarrBlock::AddMoviePrompt | ActiveRadarrBlock::AddMovieTagsInput => {
|
||||
draw_confirmation_prompt(f, app, prompt_area)
|
||||
draw_confirmation_prompt(f, app, area)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let (movie_title, movie_overview) = if let Route::Radarr(_, Some(_)) = app.get_current_route() {
|
||||
(
|
||||
&app
|
||||
@@ -386,34 +372,32 @@ fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
let selected_quality_profile = quality_profile_list.current_selection();
|
||||
let selected_root_folder = root_folder_list.current_selection();
|
||||
|
||||
f.render_widget(title_block_centered(&title), prompt_area);
|
||||
f.render_widget(title_block_centered(&title), area);
|
||||
|
||||
let chunks = vertical_chunks_with_margin(
|
||||
vec![
|
||||
let [paragraph_area, root_folder_area, monitor_area, min_availability_area, quality_profile_area, tags_area, _, buttons_area] =
|
||||
Layout::vertical([
|
||||
Constraint::Length(6),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(0),
|
||||
Constraint::Fill(0),
|
||||
Constraint::Length(3),
|
||||
],
|
||||
prompt_area,
|
||||
1,
|
||||
);
|
||||
])
|
||||
.margin(1)
|
||||
.areas(area);
|
||||
|
||||
let prompt_paragraph = layout_paragraph_borderless(&prompt);
|
||||
f.render_widget(prompt_paragraph, chunks[0]);
|
||||
f.render_widget(prompt_paragraph, paragraph_area);
|
||||
|
||||
let horizontal_chunks = horizontal_chunks(
|
||||
vec![Constraint::Percentage(50), Constraint::Percentage(50)],
|
||||
chunks[7],
|
||||
);
|
||||
let [add_area, cancel_area] =
|
||||
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||
.areas(buttons_area);
|
||||
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[1],
|
||||
root_folder_area,
|
||||
"Root Folder",
|
||||
&selected_root_folder.path,
|
||||
selected_block == &ActiveRadarrBlock::AddMovieSelectRootFolder,
|
||||
@@ -421,7 +405,7 @@ fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[2],
|
||||
monitor_area,
|
||||
"Monitor",
|
||||
selected_monitor.to_display_str(),
|
||||
selected_block == &ActiveRadarrBlock::AddMovieSelectMonitor,
|
||||
@@ -429,14 +413,14 @@ fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[3],
|
||||
min_availability_area,
|
||||
"Minimum Availability",
|
||||
selected_minimum_availability.to_display_str(),
|
||||
selected_block == &ActiveRadarrBlock::AddMovieSelectMinimumAvailability,
|
||||
);
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[4],
|
||||
quality_profile_area,
|
||||
"Quality Profile",
|
||||
selected_quality_profile,
|
||||
selected_block == &ActiveRadarrBlock::AddMovieSelectQualityProfile,
|
||||
@@ -446,7 +430,7 @@ fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
draw_text_box_with_label(
|
||||
f,
|
||||
LabeledTextBoxProps {
|
||||
area: chunks[5],
|
||||
area: tags_area,
|
||||
label: "Tags",
|
||||
text: &tags.text,
|
||||
offset: *tags.offset.borrow(),
|
||||
@@ -457,24 +441,14 @@ fn draw_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
);
|
||||
}
|
||||
|
||||
draw_button(
|
||||
f,
|
||||
horizontal_chunks[0],
|
||||
"Add",
|
||||
yes_no_value && highlight_yes_no,
|
||||
);
|
||||
draw_button(
|
||||
f,
|
||||
horizontal_chunks[1],
|
||||
"Cancel",
|
||||
!yes_no_value && highlight_yes_no,
|
||||
);
|
||||
draw_button(f, add_area, "Add", yes_no_value && highlight_yes_no);
|
||||
draw_button(f, cancel_area, "Cancel", !yes_no_value && highlight_yes_no);
|
||||
}
|
||||
|
||||
fn draw_add_movie_select_monitor_popup(f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect) {
|
||||
fn draw_add_movie_select_monitor_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -489,11 +463,11 @@ fn draw_add_movie_select_monitor_popup(f: &mut Frame<'_>, app: &mut App<'_>, pop
|
||||
fn draw_add_movie_select_minimum_availability_popup(
|
||||
f: &mut Frame<'_>,
|
||||
app: &mut App<'_>,
|
||||
popup_area: Rect,
|
||||
area: Rect,
|
||||
) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -505,14 +479,10 @@ fn draw_add_movie_select_minimum_availability_popup(
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_add_movie_select_quality_profile_popup(
|
||||
f: &mut Frame<'_>,
|
||||
app: &mut App<'_>,
|
||||
popup_area: Rect,
|
||||
) {
|
||||
fn draw_add_movie_select_quality_profile_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -524,10 +494,10 @@ fn draw_add_movie_select_quality_profile_popup(
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_add_movie_select_root_folder_popup(f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect) {
|
||||
fn draw_add_movie_select_root_folder_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
|
||||
@@ -22,7 +22,7 @@ impl DrawUi for DeleteMovieUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if matches!(
|
||||
*app.get_current_route(),
|
||||
Route::Radarr(ActiveRadarrBlock::DeleteMoviePrompt, _)
|
||||
@@ -55,7 +55,7 @@ impl DrawUi for DeleteMovieUi {
|
||||
)
|
||||
};
|
||||
|
||||
draw_prompt_popup_over(f, app, content_rect, draw_library, draw_delete_movie_prompt);
|
||||
draw_prompt_popup_over(f, app, area, draw_library, draw_delete_movie_prompt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use ratatui::layout::{Constraint, Rect};
|
||||
use ratatui::prelude::Layout;
|
||||
use ratatui::widgets::ListItem;
|
||||
use ratatui::Frame;
|
||||
|
||||
@@ -11,9 +12,7 @@ use crate::models::Route;
|
||||
use crate::ui::radarr_ui::library::draw_library;
|
||||
use crate::ui::radarr_ui::library::movie_details_ui::MovieDetailsUi;
|
||||
|
||||
use crate::ui::utils::{
|
||||
horizontal_chunks, layout_paragraph_borderless, title_block_centered, vertical_chunks_with_margin,
|
||||
};
|
||||
use crate::ui::utils::{layout_paragraph_borderless, title_block_centered};
|
||||
use crate::ui::{
|
||||
draw_button, draw_checkbox_with_label, draw_drop_down_menu_button, draw_drop_down_popup,
|
||||
draw_large_popup_over_background_fn_with_ui, draw_medium_popup_over, draw_popup,
|
||||
@@ -35,7 +34,7 @@ impl DrawUi for EditMovieUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Radarr(active_radarr_block, context_option) = *app.get_current_route() {
|
||||
let draw_edit_movie_prompt =
|
||||
|f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect| match active_radarr_block {
|
||||
@@ -69,13 +68,13 @@ impl DrawUi for EditMovieUi {
|
||||
if let Some(context) = context_option {
|
||||
match context {
|
||||
ActiveRadarrBlock::Movies => {
|
||||
draw_medium_popup_over(f, app, content_rect, draw_library, draw_edit_movie_prompt);
|
||||
draw_medium_popup_over(f, app, area, draw_library, draw_edit_movie_prompt);
|
||||
}
|
||||
_ if MOVIE_DETAILS_BLOCKS.contains(&context) => {
|
||||
draw_large_popup_over_background_fn_with_ui::<MovieDetailsUi>(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
area,
|
||||
draw_library,
|
||||
);
|
||||
draw_popup(f, app, draw_edit_movie_prompt, 60, 60);
|
||||
@@ -87,7 +86,7 @@ impl DrawUi for EditMovieUi {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let (movie_title, movie_overview) =
|
||||
if let Some(filtered_movies) = app.data.radarr_data.filtered_movies.as_ref() {
|
||||
(
|
||||
@@ -128,34 +127,32 @@ fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, pro
|
||||
let selected_minimum_availability = minimum_availability_list.current_selection();
|
||||
let selected_quality_profile = quality_profile_list.current_selection();
|
||||
|
||||
f.render_widget(title_block_centered(&title), prompt_area);
|
||||
f.render_widget(title_block_centered(&title), area);
|
||||
|
||||
let chunks = vertical_chunks_with_margin(
|
||||
vec![
|
||||
let [paragraph_area, monitored_area, min_availability_area, quality_profile_area, path_area, tags_area, _, buttons_area] =
|
||||
Layout::vertical([
|
||||
Constraint::Length(6),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(0),
|
||||
Constraint::Fill(0),
|
||||
Constraint::Length(3),
|
||||
],
|
||||
prompt_area,
|
||||
1,
|
||||
);
|
||||
])
|
||||
.margin(1)
|
||||
.areas(area);
|
||||
|
||||
let prompt_paragraph = layout_paragraph_borderless(&movie_overview);
|
||||
f.render_widget(prompt_paragraph, chunks[0]);
|
||||
f.render_widget(prompt_paragraph, paragraph_area);
|
||||
|
||||
let horizontal_chunks = horizontal_chunks(
|
||||
vec![Constraint::Percentage(50), Constraint::Percentage(50)],
|
||||
chunks[7],
|
||||
);
|
||||
let [save_area, cancel_area] =
|
||||
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||
.areas(buttons_area);
|
||||
|
||||
draw_checkbox_with_label(
|
||||
f,
|
||||
chunks[1],
|
||||
monitored_area,
|
||||
"Monitored",
|
||||
monitored.unwrap_or_default(),
|
||||
selected_block == &ActiveRadarrBlock::EditMovieToggleMonitored,
|
||||
@@ -163,14 +160,14 @@ fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, pro
|
||||
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[2],
|
||||
min_availability_area,
|
||||
"Minimum Availability",
|
||||
selected_minimum_availability.to_display_str(),
|
||||
selected_block == &ActiveRadarrBlock::EditMovieSelectMinimumAvailability,
|
||||
);
|
||||
draw_drop_down_menu_button(
|
||||
f,
|
||||
chunks[3],
|
||||
quality_profile_area,
|
||||
"Quality Profile",
|
||||
selected_quality_profile,
|
||||
selected_block == &ActiveRadarrBlock::EditMovieSelectQualityProfile,
|
||||
@@ -180,7 +177,7 @@ fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, pro
|
||||
draw_text_box_with_label(
|
||||
f,
|
||||
LabeledTextBoxProps {
|
||||
area: chunks[4],
|
||||
area: path_area,
|
||||
label: "Path",
|
||||
text: &path.text,
|
||||
offset: *path.offset.borrow(),
|
||||
@@ -192,7 +189,7 @@ fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, pro
|
||||
draw_text_box_with_label(
|
||||
f,
|
||||
LabeledTextBoxProps {
|
||||
area: chunks[5],
|
||||
area: tags_area,
|
||||
label: "Tags",
|
||||
text: &tags.text,
|
||||
offset: *tags.offset.borrow(),
|
||||
@@ -203,28 +200,18 @@ fn draw_edit_movie_confirmation_prompt(f: &mut Frame<'_>, app: &mut App<'_>, pro
|
||||
);
|
||||
}
|
||||
|
||||
draw_button(
|
||||
f,
|
||||
horizontal_chunks[0],
|
||||
"Save",
|
||||
yes_no_value && highlight_yes_no,
|
||||
);
|
||||
draw_button(
|
||||
f,
|
||||
horizontal_chunks[1],
|
||||
"Cancel",
|
||||
!yes_no_value && highlight_yes_no,
|
||||
);
|
||||
draw_button(f, save_area, "Save", yes_no_value && highlight_yes_no);
|
||||
draw_button(f, cancel_area, "Cancel", !yes_no_value && highlight_yes_no);
|
||||
}
|
||||
|
||||
fn draw_edit_movie_select_minimum_availability_popup(
|
||||
f: &mut Frame<'_>,
|
||||
app: &mut App<'_>,
|
||||
popup_area: Rect,
|
||||
area: Rect,
|
||||
) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -236,14 +223,10 @@ fn draw_edit_movie_select_minimum_availability_popup(
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_edit_movie_select_quality_profile_popup(
|
||||
f: &mut Frame<'_>,
|
||||
app: &mut App<'_>,
|
||||
popup_area: Rect,
|
||||
) {
|
||||
fn draw_edit_movie_select_quality_profile_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_selectable_list(
|
||||
f,
|
||||
popup_area,
|
||||
area,
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
|
||||
@@ -42,62 +42,46 @@ impl DrawUi for LibraryUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let route = *app.get_current_route();
|
||||
let mut library_ui_matchers = |active_radarr_block: ActiveRadarrBlock| match active_radarr_block
|
||||
{
|
||||
ActiveRadarrBlock::Movies => draw_library(f, app, content_rect),
|
||||
ActiveRadarrBlock::SearchMovie => draw_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_library,
|
||||
draw_movie_search_box,
|
||||
30,
|
||||
13,
|
||||
),
|
||||
ActiveRadarrBlock::Movies => draw_library(f, app, area),
|
||||
ActiveRadarrBlock::SearchMovie => {
|
||||
draw_popup_over(f, app, area, draw_library, draw_movie_search_box, 30, 13)
|
||||
}
|
||||
ActiveRadarrBlock::SearchMovieError => draw_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
area,
|
||||
draw_library,
|
||||
draw_search_movie_error_box,
|
||||
30,
|
||||
8,
|
||||
),
|
||||
ActiveRadarrBlock::FilterMovies => draw_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_library,
|
||||
draw_filter_movies_box,
|
||||
30,
|
||||
13,
|
||||
),
|
||||
ActiveRadarrBlock::FilterMovies => {
|
||||
draw_popup_over(f, app, area, draw_library, draw_filter_movies_box, 30, 13)
|
||||
}
|
||||
ActiveRadarrBlock::FilterMoviesError => draw_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
area,
|
||||
draw_library,
|
||||
draw_filter_movies_error_box,
|
||||
30,
|
||||
8,
|
||||
),
|
||||
ActiveRadarrBlock::UpdateAllMoviesPrompt => draw_prompt_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_library,
|
||||
draw_update_all_movies_prompt,
|
||||
),
|
||||
ActiveRadarrBlock::UpdateAllMoviesPrompt => {
|
||||
draw_prompt_popup_over(f, app, area, draw_library, draw_update_all_movies_prompt)
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
match route {
|
||||
_ if MovieDetailsUi::accepts(route) => MovieDetailsUi::draw(f, app, content_rect),
|
||||
_ if AddMovieUi::accepts(route) => AddMovieUi::draw(f, app, content_rect),
|
||||
_ if EditMovieUi::accepts(route) => EditMovieUi::draw(f, app, content_rect),
|
||||
_ if DeleteMovieUi::accepts(route) => DeleteMovieUi::draw(f, app, content_rect),
|
||||
_ if MovieDetailsUi::accepts(route) => MovieDetailsUi::draw(f, app, area),
|
||||
_ if AddMovieUi::accepts(route) => AddMovieUi::draw(f, app, area),
|
||||
_ if EditMovieUi::accepts(route) => EditMovieUi::draw(f, app, area),
|
||||
_ if DeleteMovieUi::accepts(route) => DeleteMovieUi::draw(f, app, area),
|
||||
Route::Radarr(active_radarr_block, _) if LIBRARY_BLOCKS.contains(&active_radarr_block) => {
|
||||
library_ui_matchers(active_radarr_block)
|
||||
}
|
||||
@@ -208,10 +192,10 @@ pub(super) fn draw_library(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_update_all_movies_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_update_all_movies_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
area,
|
||||
"Update All Movies",
|
||||
"Do you want to update info and scan your disks for all of your movies?",
|
||||
app.data.radarr_data.prompt_confirm,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::iter;
|
||||
|
||||
use ratatui::layout::{Alignment, Constraint, Rect};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Cell, ListItem, Paragraph, Row, Wrap};
|
||||
@@ -14,7 +14,6 @@ use crate::ui::radarr_ui::library::draw_library;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::{
|
||||
borderless_block, get_width_from_percentage, layout_block_bottom_border, layout_block_top_border,
|
||||
vertical_chunks,
|
||||
};
|
||||
use crate::ui::{
|
||||
draw_drop_down_popup, draw_large_popup_over, draw_prompt_box, draw_prompt_box_with_content,
|
||||
@@ -38,10 +37,10 @@ impl DrawUi for MovieDetailsUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Radarr(active_radarr_block, context_option) = *app.get_current_route() {
|
||||
let draw_movie_info_popup = |f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect| {
|
||||
let (content_area, _) = draw_tabs(
|
||||
let content_area = draw_tabs(
|
||||
f,
|
||||
popup_area,
|
||||
"Movie Info",
|
||||
@@ -94,7 +93,7 @@ impl DrawUi for MovieDetailsUi {
|
||||
}
|
||||
};
|
||||
|
||||
draw_large_popup_over(f, app, content_rect, draw_library, draw_movie_info_popup);
|
||||
draw_large_popup_over(f, app, area, draw_library, draw_movie_info_popup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,10 +114,10 @@ fn draw_movie_info(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_search_movie_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_search_movie_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
area,
|
||||
"Automatic Movie Search",
|
||||
format!(
|
||||
"Do you want to trigger an automatic search of your indexers for the movie: {}?",
|
||||
@@ -129,10 +128,10 @@ fn draw_search_movie_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: R
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_update_and_scan_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_update_and_scan_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
area,
|
||||
"Update and Scan",
|
||||
format!(
|
||||
"Do you want to trigger an update and disk scan for the movie: {}?",
|
||||
@@ -143,7 +142,7 @@ fn draw_update_and_scan_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_file_info(f: &mut Frame<'_>, app: &App<'_>, content_area: Rect) {
|
||||
fn draw_file_info(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
match app.data.radarr_data.movie_details_modal.as_ref() {
|
||||
Some(movie_details_modal)
|
||||
if !movie_details_modal.file_details.is_empty() && !app.is_loading =>
|
||||
@@ -151,17 +150,16 @@ fn draw_file_info(f: &mut Frame<'_>, app: &App<'_>, content_area: Rect) {
|
||||
let file_info = movie_details_modal.file_details.to_owned();
|
||||
let audio_details = movie_details_modal.audio_details.to_owned();
|
||||
let video_details = movie_details_modal.video_details.to_owned();
|
||||
let chunks = vertical_chunks(
|
||||
vec![
|
||||
let [file_details_title_area, file_details_area, audio_details_title_area, audio_details_area, video_details_title_area, video_details_area] =
|
||||
Layout::vertical([
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(5),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(6),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(7),
|
||||
],
|
||||
content_area,
|
||||
);
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
let file_details_title_paragraph =
|
||||
Paragraph::new("File Details".bold()).block(layout_block_top_border());
|
||||
@@ -184,18 +182,18 @@ fn draw_file_info(f: &mut Frame<'_>, app: &App<'_>, content_area: Rect) {
|
||||
.block(borderless_block())
|
||||
.wrap(Wrap { trim: false });
|
||||
|
||||
f.render_widget(file_details_title_paragraph, chunks[0]);
|
||||
f.render_widget(file_details_paragraph, chunks[1]);
|
||||
f.render_widget(audio_details_title_paragraph, chunks[2]);
|
||||
f.render_widget(audio_details_paragraph, chunks[3]);
|
||||
f.render_widget(video_details_title_paragraph, chunks[4]);
|
||||
f.render_widget(video_details_paragraph, chunks[5]);
|
||||
f.render_widget(file_details_title_paragraph, file_details_title_area);
|
||||
f.render_widget(file_details_paragraph, file_details_area);
|
||||
f.render_widget(audio_details_title_paragraph, audio_details_title_area);
|
||||
f.render_widget(audio_details_paragraph, audio_details_area);
|
||||
f.render_widget(video_details_title_paragraph, video_details_title_area);
|
||||
f.render_widget(video_details_paragraph, video_details_area);
|
||||
}
|
||||
_ => loading(f, layout_block_top_border(), content_area, app.is_loading),
|
||||
_ => loading(f, layout_block_top_border(), area, app.is_loading),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_movie_details(f: &mut Frame<'_>, app: &App<'_>, content_area: Rect) {
|
||||
fn draw_movie_details(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let block = layout_block_top_border();
|
||||
|
||||
match app.data.radarr_data.movie_details_modal.as_ref() {
|
||||
@@ -230,18 +228,18 @@ fn draw_movie_details(f: &mut Frame<'_>, app: &App<'_>, content_area: Rect) {
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((movie_details.offset, 0));
|
||||
|
||||
f.render_widget(paragraph, content_area);
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
_ => loading(
|
||||
f,
|
||||
block,
|
||||
content_area,
|
||||
area,
|
||||
app.is_loading || app.data.radarr_data.movie_details_modal.is_none(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_movie_history(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
fn draw_movie_history(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Some(movie_details_modal) = app.data.radarr_data.movie_details_modal.as_mut() {
|
||||
let current_selection = if movie_details_modal.movie_history.items.is_empty() {
|
||||
MovieHistoryItem::default()
|
||||
@@ -254,7 +252,7 @@ fn draw_movie_history(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
|
||||
draw_table(
|
||||
f,
|
||||
content_area,
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: Some(&mut movie_details_modal.movie_history),
|
||||
@@ -283,7 +281,7 @@ fn draw_movie_history(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
} = movie_history_item;
|
||||
|
||||
movie_history_item.source_title.scroll_left_or_reset(
|
||||
get_width_from_percentage(content_area, 34),
|
||||
get_width_from_percentage(area, 34),
|
||||
current_selection == *movie_history_item,
|
||||
app.tick_count % app.ticks_until_scroll == 0,
|
||||
);
|
||||
@@ -309,10 +307,10 @@ fn draw_movie_history(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_movie_cast(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
fn draw_movie_cast(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_table(
|
||||
f,
|
||||
content_area,
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: Some(
|
||||
@@ -351,10 +349,10 @@ fn draw_movie_cast(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_movie_crew(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
fn draw_movie_crew(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_table(
|
||||
f,
|
||||
content_area,
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: Some(
|
||||
@@ -395,7 +393,7 @@ fn draw_movie_crew(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_movie_releases(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect) {
|
||||
fn draw_movie_releases(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let (current_selection, is_empty, sort_ascending) =
|
||||
match app.data.radarr_data.movie_details_modal.as_ref() {
|
||||
Some(movie_details_modal) if !movie_details_modal.movie_releases.items.is_empty() => (
|
||||
@@ -447,7 +445,7 @@ fn draw_movie_releases(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
|
||||
draw_table(
|
||||
f,
|
||||
content_area,
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: Some(
|
||||
@@ -494,7 +492,7 @@ fn draw_movie_releases(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
} = release;
|
||||
let age = format!("{age} days");
|
||||
title.scroll_left_or_reset(
|
||||
get_width_from_percentage(content_area, 30),
|
||||
get_width_from_percentage(area, 30),
|
||||
current_selection == *release
|
||||
&& current_route != ActiveRadarrBlock::ManualSearchConfirmPrompt.into(),
|
||||
app.tick_count % app.ticks_until_scroll == 0,
|
||||
@@ -539,7 +537,7 @@ fn draw_movie_releases(f: &mut Frame<'_>, app: &mut App<'_>, content_area: Rect)
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_manual_search_confirm_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_manual_search_confirm_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let current_selection = app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -583,20 +581,14 @@ fn draw_manual_search_confirm_prompt(f: &mut Frame<'_>, app: &mut App<'_>, promp
|
||||
|
||||
draw_prompt_box_with_content(
|
||||
f,
|
||||
prompt_area,
|
||||
area,
|
||||
title,
|
||||
&prompt,
|
||||
Some(content_paragraph),
|
||||
app.data.radarr_data.prompt_confirm,
|
||||
);
|
||||
} else {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
title,
|
||||
&prompt,
|
||||
app.data.radarr_data.prompt_confirm,
|
||||
);
|
||||
draw_prompt_box(f, area, title, &prompt, app.data.radarr_data.prompt_confirm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user