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:
+32
-27
@@ -23,7 +23,6 @@ use crate::ui::radarr_ui::system::SystemUi;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::{
|
||||
borderless_block, layout_block, line_gauge_with_label, line_gauge_with_title, title_block,
|
||||
vertical_chunks_with_margin,
|
||||
};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::utils::convert_to_gb;
|
||||
@@ -48,29 +47,30 @@ impl DrawUi for RadarrUi {
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let (content_rect, _) = draw_tabs(f, area, "Movies", &app.data.radarr_data.main_tabs);
|
||||
let content_area = draw_tabs(f, area, "Movies", &app.data.radarr_data.main_tabs);
|
||||
let route = *app.get_current_route();
|
||||
|
||||
match route {
|
||||
_ if LibraryUi::accepts(route) => LibraryUi::draw(f, app, content_rect),
|
||||
_ if CollectionsUi::accepts(route) => CollectionsUi::draw(f, app, content_rect),
|
||||
_ if DownloadsUi::accepts(route) => DownloadsUi::draw(f, app, content_rect),
|
||||
_ if IndexersUi::accepts(route) => IndexersUi::draw(f, app, content_rect),
|
||||
_ if RootFoldersUi::accepts(route) => RootFoldersUi::draw(f, app, content_rect),
|
||||
_ if SystemUi::accepts(route) => SystemUi::draw(f, app, content_rect),
|
||||
_ if LibraryUi::accepts(route) => LibraryUi::draw(f, app, content_area),
|
||||
_ if CollectionsUi::accepts(route) => CollectionsUi::draw(f, app, content_area),
|
||||
_ if DownloadsUi::accepts(route) => DownloadsUi::draw(f, app, content_area),
|
||||
_ if IndexersUi::accepts(route) => IndexersUi::draw(f, app, content_area),
|
||||
_ if RootFoldersUi::accepts(route) => RootFoldersUi::draw(f, app, content_area),
|
||||
_ if SystemUi::accepts(route) => SystemUi::draw(f, app, content_area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_context_row(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let [main, logo] = Layout::horizontal([Constraint::Min(0), Constraint::Length(20)]).areas(area);
|
||||
let [main_area, logo_area] =
|
||||
Layout::horizontal([Constraint::Fill(0), Constraint::Length(20)]).areas(area);
|
||||
|
||||
let [stats, downloads] =
|
||||
Layout::horizontal([Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)]).areas(main);
|
||||
let [stats_area, downloads_area] =
|
||||
Layout::horizontal([Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)]).areas(main_area);
|
||||
|
||||
draw_stats_context(f, app, stats);
|
||||
draw_downloads_context(f, app, downloads);
|
||||
draw_radarr_logo(f, logo);
|
||||
draw_stats_context(f, app, stats_area);
|
||||
draw_downloads_context(f, app, downloads_area);
|
||||
draw_radarr_logo(f, logo_area);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ fn draw_stats_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
.collect(),
|
||||
);
|
||||
|
||||
let chunks = vertical_chunks_with_margin(constraints, area, 1);
|
||||
let stat_item_areas = Layout::vertical(constraints).margin(1).split(area);
|
||||
|
||||
let version_paragraph = Paragraph::new(Text::from(format!(
|
||||
"Radarr Version: {}",
|
||||
@@ -125,9 +125,9 @@ fn draw_stats_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let storage = Paragraph::new(Text::from("Storage:")).block(borderless_block().bold());
|
||||
let folders = Paragraph::new(Text::from("Root Folders:")).block(borderless_block().bold());
|
||||
|
||||
f.render_widget(version_paragraph, chunks[0]);
|
||||
f.render_widget(uptime_paragraph, chunks[1]);
|
||||
f.render_widget(storage, chunks[2]);
|
||||
f.render_widget(version_paragraph, stat_item_areas[0]);
|
||||
f.render_widget(uptime_paragraph, stat_item_areas[1]);
|
||||
f.render_widget(storage, stat_item_areas[2]);
|
||||
|
||||
for i in 0..disk_space_vec.len() {
|
||||
let DiskSpace {
|
||||
@@ -143,10 +143,10 @@ fn draw_stats_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
|
||||
let space_gauge = line_gauge_with_label(title.as_str(), ratio);
|
||||
|
||||
f.render_widget(space_gauge, chunks[i + 3]);
|
||||
f.render_widget(space_gauge, stat_item_areas[i + 3]);
|
||||
}
|
||||
|
||||
f.render_widget(folders, chunks[disk_space_vec.len() + 3]);
|
||||
f.render_widget(folders, stat_item_areas[disk_space_vec.len() + 3]);
|
||||
|
||||
for i in 0..root_folders.items.len() {
|
||||
let RootFolder {
|
||||
@@ -157,7 +157,10 @@ fn draw_stats_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
.block(borderless_block())
|
||||
.default();
|
||||
|
||||
f.render_widget(root_folder_space, chunks[i + disk_space_vec.len() + 4])
|
||||
f.render_widget(
|
||||
root_folder_space,
|
||||
stat_item_areas[i + disk_space_vec.len() + 4],
|
||||
)
|
||||
}
|
||||
} else {
|
||||
loading(f, block, area, app.is_loading);
|
||||
@@ -171,11 +174,13 @@ fn draw_downloads_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
if !downloads_vec.is_empty() {
|
||||
f.render_widget(block, area);
|
||||
|
||||
let constraints = iter::repeat(Constraint::Length(2))
|
||||
.take(downloads_vec.len())
|
||||
.collect::<Vec<Constraint>>();
|
||||
|
||||
let chunks = vertical_chunks_with_margin(constraints, area, 1);
|
||||
let download_item_areas = Layout::vertical(
|
||||
iter::repeat(Constraint::Length(2))
|
||||
.take(downloads_vec.len())
|
||||
.collect::<Vec<Constraint>>(),
|
||||
)
|
||||
.margin(1)
|
||||
.split(area);
|
||||
|
||||
for i in 0..downloads_vec.len() {
|
||||
let DownloadRecord {
|
||||
@@ -187,7 +192,7 @@ fn draw_downloads_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let percent = 1f64 - (*sizeleft as f64 / *size as f64);
|
||||
let download_gauge = line_gauge_with_title(title, percent);
|
||||
|
||||
f.render_widget(download_gauge, chunks[i]);
|
||||
f.render_widget(download_gauge, download_item_areas[i]);
|
||||
}
|
||||
} else {
|
||||
loading(f, block, area, app.is_loading);
|
||||
|
||||
Reference in New Issue
Block a user