diff --git a/rm-main/src/tui/components/misc.rs b/rm-main/src/tui/components/misc.rs new file mode 100644 index 0000000..b6f735c --- /dev/null +++ b/rm-main/src/tui/components/misc.rs @@ -0,0 +1,18 @@ +use ratatui::{ + layout::Alignment, + style::Stylize, + widgets::block::{Position, Title}, +}; +use rm_config::CONFIG; + +pub fn popup_close_button_highlight() -> Title<'static> { + Title::from(" [ CLOSE ] ".fg(CONFIG.general.accent_color).bold()) + .alignment(Alignment::Right) + .position(Position::Bottom) +} + +pub fn popup_close_button() -> Title<'static> { + Title::from(" [CLOSE] ".bold()) + .alignment(Alignment::Right) + .position(Position::Bottom) +} diff --git a/rm-main/src/tui/components/mod.rs b/rm-main/src/tui/components/mod.rs index 2e15a81..5e04366 100644 --- a/rm-main/src/tui/components/mod.rs +++ b/rm-main/src/tui/components/mod.rs @@ -1,8 +1,10 @@ mod input_manager; +mod misc; mod table; mod tabs; pub use input_manager::InputManager; +pub use misc::{popup_close_button, popup_close_button_highlight}; pub use table::GenericTable; pub use tabs::{CurrentTab, TabComponent}; diff --git a/rm-main/src/tui/global_popups/help.rs b/rm-main/src/tui/global_popups/help.rs index 6b4d94e..93c4e6c 100644 --- a/rm-main/src/tui/global_popups/help.rs +++ b/rm-main/src/tui/global_popups/help.rs @@ -2,10 +2,7 @@ use std::collections::BTreeMap; use ratatui::{ prelude::*, - widgets::{ - block::{Position, Title}, - Block, Borders, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, - }, + widgets::{Block, Borders, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState}, }; use rm_config::{ @@ -16,7 +13,7 @@ use rm_shared::action::Action; use crate::tui::{ app, - components::{Component, ComponentAction}, + components::{popup_close_button_highlight, Component, ComponentAction}, main_window::centered_rect, }; @@ -169,11 +166,7 @@ impl Component for HelpPopup { let title_style = Style::new().fg(CONFIG.general.accent_color); let block = Block::bordered() .border_set(symbols::border::ROUNDED) - .title( - Title::from(" [ CLOSE ] ".fg(CONFIG.general.accent_color).bold()) - .alignment(Alignment::Right) - .position(Position::Bottom), - ) + .title(popup_close_button_highlight()) .title(" Help ") .title_style(title_style); diff --git a/rm-main/src/tui/tabs/search/popups/providers.rs b/rm-main/src/tui/tabs/search/popups/providers.rs index bdbfa6e..c47ea6b 100644 --- a/rm-main/src/tui/tabs/search/popups/providers.rs +++ b/rm-main/src/tui/tabs/search/popups/providers.rs @@ -1,20 +1,17 @@ use magnetease::ProviderCategory; use ratatui::{ - layout::{Alignment, Constraint, Margin}, + layout::{Constraint, Margin}, prelude::Rect, style::{Style, Styled, Stylize}, text::Line, - widgets::{ - block::{Position, Title}, - Block, BorderType, Clear, Row, Table, - }, + widgets::{block::Title, Block, BorderType, Clear, Row, Table}, Frame, }; use rm_config::CONFIG; use rm_shared::action::Action; use crate::tui::{ - components::{Component, ComponentAction}, + components::{popup_close_button_highlight, Component, ComponentAction}, main_window::centered_rect, tabs::search::{ConfiguredProvider, ProviderState}, }; @@ -100,11 +97,7 @@ impl Component for ProvidersPopup { let block = Block::bordered() .border_type(BorderType::Rounded) .title(Title::from(" Providers ".set_style(title_style))) - .title( - Title::from(" [ CLOSE ] ".set_style(title_style.bold())) - .alignment(Alignment::Right) - .position(Position::Bottom), - ); + .title(popup_close_button_highlight()); let widths = [ Constraint::Length(10), // Provider name (and icon status prefix) diff --git a/rm-main/src/tui/tabs/torrents/mod.rs b/rm-main/src/tui/tabs/torrents/mod.rs index 06e24be..766cc29 100644 --- a/rm-main/src/tui/tabs/torrents/mod.rs +++ b/rm-main/src/tui/tabs/torrents/mod.rs @@ -165,7 +165,7 @@ impl TorrentsTab { let mut torrents_displaying_no = 0; let mut space_left = rect.height; for torrent in self.table_manager.table.items.iter().skip(offset) { - if space_left <= 0 { + if space_left == 0 { break; } diff --git a/rm-main/src/tui/tabs/torrents/popups/files.rs b/rm-main/src/tui/tabs/torrents/popups/files.rs index e4a42a6..5921e9f 100644 --- a/rm-main/src/tui/tabs/torrents/popups/files.rs +++ b/rm-main/src/tui/tabs/torrents/popups/files.rs @@ -17,7 +17,9 @@ use crate::{ transmission::TorrentAction, tui::{ app, - components::{Component, ComponentAction}, + components::{ + popup_close_button, popup_close_button_highlight, Component, ComponentAction, + }, main_window::centered_rect, }, }; @@ -265,10 +267,10 @@ impl Component for FilesPopup { self.switched_after_fetched_data = true; } - let close_button_style = { + let close_button = { match self.current_focus { - CurrentFocus::CloseButton => highlight_style.bold(), - CurrentFocus::Files => Style::default(), + CurrentFocus::CloseButton => popup_close_button_highlight(), + CurrentFocus::Files => popup_close_button(), } }; @@ -314,11 +316,7 @@ impl Component for FilesPopup { Title::from(format!(" {} ", download_dir).set_style(highlight_style)) .alignment(Alignment::Right), ) - .title( - Title::from(" [ CLOSE ] ".set_style(close_button_style)) - .alignment(Alignment::Right) - .position(Position::Bottom), - ) + .title(close_button) .title( Title::from(keybinding_tip) .alignment(Alignment::Left) @@ -336,11 +334,7 @@ impl Component for FilesPopup { f.render_stateful_widget(tree_widget, block_rect, &mut self.tree_state); } else { let paragraph = Paragraph::new("Loading..."); - let block = block.title( - Title::from(" [ CLOSE ] ".set_style(highlight_style.bold())) - .alignment(Alignment::Right) - .position(Position::Bottom), - ); + let block = block.title(popup_close_button_highlight()); f.render_widget(Clear, popup_rect); f.render_widget(paragraph, info_text_rect); f.render_widget(block, block_rect); @@ -351,7 +345,6 @@ impl Component for FilesPopup { struct TransmissionFile { name: String, id: usize, - // TODO: Change to enum wanted: bool, } diff --git a/rm-main/src/tui/tabs/torrents/popups/stats.rs b/rm-main/src/tui/tabs/torrents/popups/stats.rs index 9f03a47..6a28747 100644 --- a/rm-main/src/tui/tabs/torrents/popups/stats.rs +++ b/rm-main/src/tui/tabs/torrents/popups/stats.rs @@ -3,10 +3,7 @@ use std::sync::Arc; use ratatui::{ prelude::*, style::Styled, - widgets::{ - block::{Position, Title}, - Block, BorderType, Clear, Paragraph, - }, + widgets::{block::Title, Block, BorderType, Clear, Paragraph}, }; use rm_config::CONFIG; use transmission_rpc::types::SessionStats; @@ -14,7 +11,7 @@ use transmission_rpc::types::SessionStats; use rm_shared::{action::Action, utils::bytes_to_human_format}; use crate::tui::{ - components::{Component, ComponentAction}, + components::{popup_close_button_highlight, Component, ComponentAction}, main_window::centered_rect, }; @@ -47,11 +44,7 @@ impl Component for StatisticsPopup { let block = Block::bordered() .border_type(BorderType::Rounded) .title(Title::from(" Statistics ".set_style(title_style))) - .title( - Title::from(" [ CLOSE ] ".set_style(title_style.bold())) - .alignment(Alignment::Right) - .position(Position::Bottom), - ); + .title(popup_close_button_highlight()); let uploaded_bytes = self.stats.cumulative_stats.uploaded_bytes; let downloaded_bytes = self.stats.cumulative_stats.downloaded_bytes;