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,7 +1,7 @@
|
||||
use std::ops::Sub;
|
||||
|
||||
use chrono::Utc;
|
||||
use ratatui::layout::Alignment;
|
||||
use ratatui::layout::{Alignment, Layout};
|
||||
use ratatui::text::{Span, Text};
|
||||
use ratatui::widgets::{Cell, Paragraph, Row};
|
||||
use ratatui::{
|
||||
@@ -20,11 +20,7 @@ use crate::ui::utils::layout_block_top_border;
|
||||
use crate::ui::{draw_table, ListProps, TableProps};
|
||||
use crate::{
|
||||
models::Route,
|
||||
ui::{
|
||||
draw_list_box,
|
||||
utils::{horizontal_chunks, title_block, vertical_chunks},
|
||||
DrawUi,
|
||||
},
|
||||
ui::{draw_list_box, utils::title_block, DrawUi},
|
||||
};
|
||||
|
||||
mod system_details_ui;
|
||||
@@ -60,13 +56,13 @@ impl DrawUi for SystemUi {
|
||||
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();
|
||||
|
||||
match route {
|
||||
_ if SystemDetailsUi::accepts(route) => SystemDetailsUi::draw(f, app, content_rect),
|
||||
_ if SystemDetailsUi::accepts(route) => SystemDetailsUi::draw(f, app, area),
|
||||
_ if matches!(route, Route::Radarr(ActiveRadarrBlock::System, _)) => {
|
||||
draw_system_ui_layout(f, app, content_rect)
|
||||
draw_system_ui_layout(f, app, area)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
@@ -74,24 +70,20 @@ impl DrawUi for SystemUi {
|
||||
}
|
||||
|
||||
pub(super) fn draw_system_ui_layout(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let vertical_chunks = vertical_chunks(
|
||||
vec![
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Min(2),
|
||||
],
|
||||
area,
|
||||
);
|
||||
let [activities_area, logs_area, help_area] = Layout::vertical([
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Min(2),
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
let horizontal_chunks = horizontal_chunks(
|
||||
vec![Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
|
||||
vertical_chunks[0],
|
||||
);
|
||||
let [tasks_area, events_area] =
|
||||
Layout::horizontal([Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)]).areas(activities_area);
|
||||
|
||||
draw_tasks(f, app, horizontal_chunks[0]);
|
||||
draw_queued_events(f, app, horizontal_chunks[1]);
|
||||
draw_logs(f, app, vertical_chunks[1]);
|
||||
draw_help(f, app, vertical_chunks[2]);
|
||||
draw_tasks(f, app, tasks_area);
|
||||
draw_queued_events(f, app, events_area);
|
||||
draw_logs(f, app, logs_area);
|
||||
draw_help(f, app, help_area);
|
||||
}
|
||||
|
||||
fn draw_tasks(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
|
||||
@@ -16,8 +16,9 @@ use crate::ui::radarr_ui::system::{
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::{borderless_block, title_block};
|
||||
use crate::ui::{
|
||||
draw_help_and_get_content_rect, draw_large_popup_over, draw_list_box, draw_medium_popup_over,
|
||||
draw_prompt_box, draw_prompt_popup_over, draw_table, loading, DrawUi, ListProps, TableProps,
|
||||
draw_help_footer_and_get_content_area, draw_large_popup_over, draw_list_box,
|
||||
draw_medium_popup_over, draw_prompt_box, draw_prompt_popup_over, draw_table, loading, DrawUi,
|
||||
ListProps, TableProps,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -35,35 +36,21 @@ impl DrawUi for SystemDetailsUi {
|
||||
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, _) = *app.get_current_route() {
|
||||
match active_radarr_block {
|
||||
ActiveRadarrBlock::SystemLogs => {
|
||||
draw_large_popup_over(f, app, content_rect, draw_system_ui_layout, draw_logs_popup)
|
||||
draw_large_popup_over(f, app, area, draw_system_ui_layout, draw_logs_popup)
|
||||
}
|
||||
ActiveRadarrBlock::SystemTasks | ActiveRadarrBlock::SystemTaskStartConfirmPrompt => {
|
||||
draw_large_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_system_ui_layout,
|
||||
draw_tasks_popup,
|
||||
)
|
||||
draw_large_popup_over(f, app, area, draw_system_ui_layout, draw_tasks_popup)
|
||||
}
|
||||
ActiveRadarrBlock::SystemQueuedEvents => {
|
||||
draw_medium_popup_over(f, app, area, draw_system_ui_layout, draw_queued_events)
|
||||
}
|
||||
ActiveRadarrBlock::SystemUpdates => {
|
||||
draw_large_popup_over(f, app, area, draw_system_ui_layout, draw_updates_popup)
|
||||
}
|
||||
ActiveRadarrBlock::SystemQueuedEvents => draw_medium_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_system_ui_layout,
|
||||
draw_queued_events,
|
||||
),
|
||||
ActiveRadarrBlock::SystemUpdates => draw_large_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_system_ui_layout,
|
||||
draw_updates_popup,
|
||||
),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -97,7 +84,7 @@ fn draw_tasks_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let tasks_popup_table = |f: &mut Frame<'_>, app: &mut App<'_>, area: Rect| {
|
||||
f.render_widget(title_block("Tasks"), area);
|
||||
|
||||
let context_area = draw_help_and_get_content_rect(
|
||||
let context_area = draw_help_footer_and_get_content_area(
|
||||
f,
|
||||
area,
|
||||
Some(build_context_clue_string(&SYSTEM_TASKS_CONTEXT_CLUES)),
|
||||
@@ -141,10 +128,10 @@ fn draw_tasks_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_start_task_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
fn draw_start_task_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
area,
|
||||
"Start Task",
|
||||
format!(
|
||||
"Do you want to manually start this task: {}?",
|
||||
@@ -158,7 +145,7 @@ fn draw_start_task_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rec
|
||||
fn draw_updates_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
f.render_widget(title_block("Updates"), area);
|
||||
|
||||
let content_rect = draw_help_and_get_content_rect(
|
||||
let content_area = draw_help_footer_and_get_content_area(
|
||||
f,
|
||||
area,
|
||||
Some(format!(
|
||||
@@ -174,8 +161,8 @@ fn draw_updates_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
.block(block)
|
||||
.scroll((app.data.radarr_data.updates.offset, 0));
|
||||
|
||||
f.render_widget(updates_paragraph, content_rect);
|
||||
f.render_widget(updates_paragraph, content_area);
|
||||
} else {
|
||||
loading(f, block, content_rect, app.is_loading);
|
||||
loading(f, block, content_area, app.is_loading);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user