Skip to content

Commit

Permalink
ui: improve popups buttons (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski authored Aug 19, 2024
1 parent 47fbb6e commit de167c1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 47 deletions.
18 changes: 18 additions & 0 deletions rm-main/src/tui/components/misc.rs
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions rm-main/src/tui/components/mod.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
13 changes: 3 additions & 10 deletions rm-main/src/tui/global_popups/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
};

Expand Down Expand Up @@ -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);

Expand Down
15 changes: 4 additions & 11 deletions rm-main/src/tui/tabs/search/popups/providers.rs
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/tui/tabs/torrents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 8 additions & 15 deletions rm-main/src/tui/tabs/torrents/popups/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down Expand Up @@ -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(),
}
};

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -351,7 +345,6 @@ impl Component for FilesPopup {
struct TransmissionFile {
name: String,
id: usize,
// TODO: Change to enum
wanted: bool,
}

Expand Down
13 changes: 3 additions & 10 deletions rm-main/src/tui/tabs/torrents/popups/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ 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;

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,
};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit de167c1

Please sign in to comment.