diff --git a/src/canvas.rs b/src/canvas.rs index 217b68a8..8dd27a43 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -9,12 +9,7 @@ use tui::{ Frame, Terminal, }; -// use ordered_float::OrderedFloat; - use canvas_colours::*; -use dialogs::*; -use screens::*; -use widgets::*; use crate::{ app::{ diff --git a/src/canvas/dialogs.rs b/src/canvas/dialogs.rs index 7a2a7e20..fe40156e 100644 --- a/src/canvas/dialogs.rs +++ b/src/canvas/dialogs.rs @@ -1,5 +1,2 @@ pub mod dd_dialog; pub mod help_dialog; - -pub use dd_dialog::KillDialog; -pub use help_dialog::HelpDialog; diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index 14e33354..f7edbedd 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -16,20 +16,8 @@ use crate::{ const DD_BASE: &str = " Confirm Kill Process ── Esc to close "; const DD_ERROR_BASE: &str = " Error ── Esc to close "; -pub trait KillDialog { - fn get_dd_spans(&self, app_state: &App) -> Option>; - - fn draw_dd_confirm_buttons( - &self, f: &mut Frame<'_, B>, button_draw_loc: &Rect, app_state: &mut App, - ); - - fn draw_dd_dialog( - &self, f: &mut Frame<'_, B>, dd_text: Option>, app_state: &mut App, draw_loc: Rect, - ) -> bool; -} - -impl KillDialog for Painter { - fn get_dd_spans(&self, app_state: &App) -> Option> { +impl Painter { + pub fn get_dd_spans(&self, app_state: &App) -> Option> { if let Some(dd_err) = &app_state.dd_err { return Some(Text::from(vec![ Spans::default(), @@ -317,7 +305,7 @@ impl KillDialog for Painter { } } - fn draw_dd_dialog( + pub fn draw_dd_dialog( &self, f: &mut Frame<'_, B>, dd_text: Option>, app_state: &mut App, draw_loc: Rect, ) -> bool { if let Some(dd_text) = dd_text { diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index 2e6dd7d8..494da366 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -12,15 +12,9 @@ use tui::{ const HELP_BASE: &str = " Help ── Esc to close "; -pub trait HelpDialog { - fn draw_help_dialog( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, - ); -} - // TODO: [REFACTOR] Make generic dialog boxes to build off of instead? -impl HelpDialog for Painter { - fn draw_help_dialog( +impl Painter { + pub fn draw_help_dialog( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, ) { let help_title = Spans::from(vec![ diff --git a/src/canvas/screens/config_screen.rs b/src/canvas/screens/config_screen.rs index b51a0b73..3b127c63 100644 --- a/src/canvas/screens/config_screen.rs +++ b/src/canvas/screens/config_screen.rs @@ -12,14 +12,8 @@ use tui::{ widgets::{Block, Borders, Paragraph}, }; -pub trait ConfigScreen { - fn draw_config_screen( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, - ); -} - -impl ConfigScreen for Painter { - fn draw_config_screen( +impl Painter { + pub fn draw_config_screen( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, ) { let config_block = Block::default() diff --git a/src/canvas/widgets.rs b/src/canvas/widgets.rs index a76b4591..b753ef53 100644 --- a/src/canvas/widgets.rs +++ b/src/canvas/widgets.rs @@ -9,15 +9,3 @@ pub mod network_basic; pub mod network_graph; pub mod process_table; pub mod temp_table; - -pub use basic_table_arrows::BasicTableArrows; -pub use battery_display::BatteryDisplayWidget; -pub use cpu_basic::CpuBasicWidget; -pub use cpu_graph::CpuGraphWidget; -pub use disk_table::DiskTableWidget; -pub use mem_basic::MemBasicWidget; -pub use mem_graph::MemGraphWidget; -pub use network_basic::NetworkBasicWidget; -pub use network_graph::NetworkGraphWidget; -pub use process_table::ProcessTableWidget; -pub use temp_table::TempTableWidget; diff --git a/src/canvas/widgets/basic_table_arrows.rs b/src/canvas/widgets/basic_table_arrows.rs index 6ab51124..ae87ff7f 100644 --- a/src/canvas/widgets/basic_table_arrows.rs +++ b/src/canvas/widgets/basic_table_arrows.rs @@ -12,14 +12,8 @@ use tui::{ widgets::{Block, Paragraph}, }; -pub trait BasicTableArrows { - fn draw_basic_table_arrows( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl BasicTableArrows for Painter { - fn draw_basic_table_arrows( +impl Painter { + pub fn draw_basic_table_arrows( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { if let Some(current_table) = app_state.widget_map.get(&widget_id) { diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index af5d2963..e020cf2c 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -13,15 +13,8 @@ use tui::{ }; use unicode_segmentation::UnicodeSegmentation; -pub trait BatteryDisplayWidget { - fn draw_battery_display( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); -} - -impl BatteryDisplayWidget for Painter { - fn draw_battery_display( +impl Painter { + pub fn draw_battery_display( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, widget_id: u64, ) { diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index 089502ec..aef2187b 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -15,14 +15,8 @@ use tui::{ widgets::{Block, Paragraph}, }; -pub trait CpuBasicWidget { - fn draw_basic_cpu( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl CpuBasicWidget for Painter { - fn draw_basic_cpu( +impl Painter { + pub fn draw_basic_cpu( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { // Skip the first element, it's the "all" element diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 25362a3f..bee3e30c 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -32,20 +32,8 @@ static CPU_LEGEND_HEADER_LENS: Lazy> = Lazy::new(|| { .collect::>() }); -pub trait CpuGraphWidget { - fn draw_cpu( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); - fn draw_cpu_graph( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); - fn draw_cpu_legend( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl CpuGraphWidget for Painter { - fn draw_cpu( +impl Painter { + pub fn draw_cpu( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { if draw_loc.width as f64 * 0.15 <= 6.0 { diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs index 0928abb5..441269fc 100644 --- a/src/canvas/widgets/disk_table.rs +++ b/src/canvas/widgets/disk_table.rs @@ -27,15 +27,8 @@ static DISK_HEADERS_LENS: Lazy> = Lazy::new(|| { .collect::>() }); -pub trait DiskTableWidget { - fn draw_disk_table( - &self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); -} - -impl DiskTableWidget for Painter { - fn draw_disk_table( +impl Painter { + pub fn draw_disk_table( &self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect, draw_border: bool, widget_id: u64, ) { diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index cecb7b52..16d79572 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -13,14 +13,8 @@ use tui::{ widgets::{Block, Paragraph}, }; -pub trait MemBasicWidget { - fn draw_basic_memory( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl MemBasicWidget for Painter { - fn draw_basic_memory( +impl Painter { + pub fn draw_basic_memory( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { let mem_data: &[(f64, f64)] = &app_state.canvas_data.mem_data; diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index 50a626f1..efb1f341 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -15,14 +15,8 @@ use tui::{ }; use unicode_segmentation::UnicodeSegmentation; -pub trait MemGraphWidget { - fn draw_memory_graph( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl MemGraphWidget for Painter { - fn draw_memory_graph( +impl Painter { + pub fn draw_memory_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { if let Some(mem_widget_state) = app_state.mem_state.widget_states.get_mut(&widget_id) { diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs index fdd5b08a..8a5c5e50 100644 --- a/src/canvas/widgets/network_basic.rs +++ b/src/canvas/widgets/network_basic.rs @@ -8,14 +8,8 @@ use tui::{ widgets::{Block, Paragraph}, }; -pub trait NetworkBasicWidget { - fn draw_basic_network( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl NetworkBasicWidget for Painter { - fn draw_basic_network( +impl Painter { + pub fn draw_basic_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { let divided_loc = Layout::default() diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index e40f294a..3c0aaadb 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -32,23 +32,8 @@ static NETWORK_HEADERS_LENS: Lazy> = Lazy::new(|| { .collect::>() }); -pub trait NetworkGraphWidget { - fn draw_network( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); - - fn draw_network_graph( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - hide_legend: bool, - ); - - fn draw_network_labels( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, - ); -} - -impl NetworkGraphWidget for Painter { - fn draw_network( +impl Painter { + pub fn draw_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { if app_state.app_config_fields.use_old_network_legend { @@ -79,7 +64,7 @@ impl NetworkGraphWidget for Painter { } } - fn draw_network_graph( + pub fn draw_network_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, hide_legend: bool, ) { diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index d54818d1..27c4cdb5 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -87,46 +87,10 @@ const PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_ELSE: &[Option] = &[ Some(0.2), ]; -pub trait ProcessTableWidget { +impl Painter { /// Draws and handles all process-related drawing. Use this. /// - `widget_id` here represents the widget ID of the process widget itself! - fn draw_process_features( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); - - /// Draws the process sort box. - /// - `widget_id` represents the widget ID of the process widget itself. - /// - /// This should not be directly called. - fn draw_processes_table( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); - - /// Draws the process search field. - /// - `widget_id` represents the widget ID of the search box itself --- NOT the process widget - /// state that is stored. - /// - /// This should not be directly called. - fn draw_search_field( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); - - /// Draws the process sort box. - /// - `widget_id` represents the widget ID of the sort box itself --- NOT the process widget - /// state that is stored. - /// - /// This should not be directly called. - fn draw_process_sort( - &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); -} - -impl ProcessTableWidget for Painter { - fn draw_process_features( + pub fn draw_process_features( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, widget_id: u64, ) { @@ -172,6 +136,10 @@ impl ProcessTableWidget for Painter { } } + /// Draws the process sort box. + /// - `widget_id` represents the widget ID of the process widget itself. + /// + /// This should not be directly called. fn draw_processes_table( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, widget_id: u64, @@ -554,6 +522,11 @@ impl ProcessTableWidget for Painter { } } + /// Draws the process search field. + /// - `widget_id` represents the widget ID of the search box itself --- NOT the process widget + /// state that is stored. + /// + /// This should not be directly called. fn draw_search_field( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, widget_id: u64, @@ -773,6 +746,11 @@ impl ProcessTableWidget for Painter { } } + /// Draws the process sort box. + /// - `widget_id` represents the widget ID of the sort box itself --- NOT the process widget + /// state that is stored. + /// + /// This should not be directly called. fn draw_process_sort( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, widget_id: u64, diff --git a/src/canvas/widgets/temp_table.rs b/src/canvas/widgets/temp_table.rs index 7e6c05da..0f565eb7 100644 --- a/src/canvas/widgets/temp_table.rs +++ b/src/canvas/widgets/temp_table.rs @@ -27,15 +27,8 @@ static TEMP_HEADERS_LENS: Lazy> = Lazy::new(|| { .collect::>() }); -pub trait TempTableWidget { - fn draw_temp_table( - &self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect, draw_border: bool, - widget_id: u64, - ); -} - -impl TempTableWidget for Painter { - fn draw_temp_table( +impl Painter { + pub fn draw_temp_table( &self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect, draw_border: bool, widget_id: u64, ) {