Skip to content

Commit

Permalink
remove redundant generic
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Dec 25, 2023
1 parent 005861a commit b34539b
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 110 deletions.
84 changes: 32 additions & 52 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl Painter {
})
.split(vertical_dialog_chunk[1]);

self.draw_help_dialog::<B>(f, app_state, middle_dialog_chunk[1]);
self.draw_help_dialog(f, app_state, middle_dialog_chunk[1]);
} else if app_state.delete_dialog_state.is_showing_dd {
let dd_text = self.get_dd_spans(app_state);

Expand Down Expand Up @@ -335,7 +335,7 @@ impl Painter {

// This is a bit nasty, but it works well... I guess.
app_state.delete_dialog_state.is_showing_dd =
self.draw_dd_dialog::<B>(f, dd_text, app_state, middle_dialog_chunk[1]);
self.draw_dd_dialog(f, dd_text, app_state, middle_dialog_chunk[1]);
} else if app_state.is_expanded {
if let Some(frozen_draw_loc) = frozen_draw_loc {
self.draw_frozen_indicator(f, frozen_draw_loc);
Expand All @@ -346,37 +346,32 @@ impl Painter {
.constraints([Constraint::Percentage(100)])
.split(terminal_size);
match &app_state.current_widget.widget_type {
Cpu => self.draw_cpu::<B>(
f,
app_state,
rect[0],
app_state.current_widget.widget_id,
),
CpuLegend => self.draw_cpu::<B>(
Cpu => self.draw_cpu(f, app_state, rect[0], app_state.current_widget.widget_id),
CpuLegend => self.draw_cpu(
f,
app_state,
rect[0],
app_state.current_widget.widget_id - 1,
),
Mem | BasicMem => self.draw_memory_graph::<B>(
Mem | BasicMem => self.draw_memory_graph(
f,
app_state,
rect[0],
app_state.current_widget.widget_id,
),
Disk => self.draw_disk_table::<B>(
Disk => self.draw_disk_table(
f,
app_state,
rect[0],
app_state.current_widget.widget_id,
),
Temp => self.draw_temp_table::<B>(
Temp => self.draw_temp_table(
f,
app_state,
rect[0],
app_state.current_widget.widget_id,
),
Net => self.draw_network_graph::<B>(
Net => self.draw_network_graph(
f,
app_state,
rect[0],
Expand All @@ -391,9 +386,9 @@ impl Painter {
_ => 0,
};

self.draw_process_widget::<B>(f, app_state, rect[0], true, widget_id);
self.draw_process_widget(f, app_state, rect[0], true, widget_id);
}
Battery => self.draw_battery_display::<B>(
Battery => self.draw_battery_display(
f,
app_state,
rect[0],
Expand Down Expand Up @@ -471,13 +466,13 @@ impl Painter {
.split(vertical_chunks[1]);

if vertical_chunks[0].width >= 2 {
self.draw_basic_cpu::<B>(f, app_state, vertical_chunks[0], 1);
self.draw_basic_cpu(f, app_state, vertical_chunks[0], 1);
}
if middle_chunks[0].width >= 2 {
self.draw_basic_memory::<B>(f, app_state, middle_chunks[0], 2);
self.draw_basic_memory(f, app_state, middle_chunks[0], 2);
}
if middle_chunks[1].width >= 2 {
self.draw_basic_network::<B>(f, app_state, middle_chunks[1], 3);
self.draw_basic_network(f, app_state, middle_chunks[1], 3);
}

let mut later_widget_id: Option<u64> = None;
Expand All @@ -486,12 +481,9 @@ impl Painter {
later_widget_id = Some(widget_id);
if vertical_chunks[3].width >= 2 {
match basic_table_widget_state.currently_displayed_widget_type {
Disk => self.draw_disk_table::<B>(
f,
app_state,
vertical_chunks[3],
widget_id,
),
Disk => {
self.draw_disk_table(f, app_state, vertical_chunks[3], widget_id)
}
Proc | ProcSort => {
let wid = widget_id
- match basic_table_widget_state.currently_displayed_widget_type
Expand All @@ -500,21 +492,18 @@ impl Painter {
ProcSort => 2,
_ => 0,
};
self.draw_process_widget::<B>(
self.draw_process_widget(
f,
app_state,
vertical_chunks[3],
false,
wid,
);
}
Temp => self.draw_temp_table::<B>(
f,
app_state,
vertical_chunks[3],
widget_id,
),
Battery => self.draw_battery_display::<B>(
Temp => {
self.draw_temp_table(f, app_state, vertical_chunks[3], widget_id)
}
Battery => self.draw_battery_display(
f,
app_state,
vertical_chunks[3],
Expand All @@ -527,7 +516,7 @@ impl Painter {
}

if let Some(widget_id) = later_widget_id {
self.draw_basic_table_arrows::<B>(f, app_state, vertical_chunks[2], widget_id);
self.draw_basic_table_arrows(f, app_state, vertical_chunks[2], widget_id);
}
} else {
// Draws using the passed in (or default) layout.
Expand Down Expand Up @@ -731,7 +720,7 @@ impl Painter {
);

// Side effect, draw here.
self.draw_widgets_with_constraints::<B>(
self.draw_widgets_with_constraints(
f,
app_state,
widgets,
Expand All @@ -754,7 +743,7 @@ impl Painter {
.flat_map(|col| &col.children)
.zip(self.derived_widget_draw_locs.iter().flatten().flatten())
.for_each(|(widgets, widget_draw_locs)| {
self.draw_widgets_with_constraints::<B>(
self.draw_widgets_with_constraints(
f,
app_state,
widgets,
Expand All @@ -778,7 +767,7 @@ impl Painter {
Ok(())
}

fn draw_widgets_with_constraints<B: Backend>(
fn draw_widgets_with_constraints(
&self, f: &mut Frame<'_>, app_state: &mut App, widgets: &BottomColRow,
widget_draw_locs: &[Rect],
) {
Expand All @@ -787,28 +776,19 @@ impl Painter {
if widget_draw_loc.width >= 2 && widget_draw_loc.height >= 2 {
match &widget.widget_type {
Empty => {}
Cpu => self.draw_cpu::<B>(f, app_state, *widget_draw_loc, widget.widget_id),
Mem => self.draw_memory_graph::<B>(
f,
app_state,
*widget_draw_loc,
widget.widget_id,
),
Net => self.draw_network::<B>(f, app_state, *widget_draw_loc, widget.widget_id),
Temp => {
self.draw_temp_table::<B>(f, app_state, *widget_draw_loc, widget.widget_id)
}
Disk => {
self.draw_disk_table::<B>(f, app_state, *widget_draw_loc, widget.widget_id)
}
Proc => self.draw_process_widget::<B>(
Cpu => self.draw_cpu(f, app_state, *widget_draw_loc, widget.widget_id),
Mem => self.draw_memory_graph(f, app_state, *widget_draw_loc, widget.widget_id),
Net => self.draw_network(f, app_state, *widget_draw_loc, widget.widget_id),
Temp => self.draw_temp_table(f, app_state, *widget_draw_loc, widget.widget_id),
Disk => self.draw_disk_table(f, app_state, *widget_draw_loc, widget.widget_id),
Proc => self.draw_process_widget(
f,
app_state,
*widget_draw_loc,
true,
widget.widget_id,
),
Battery => self.draw_battery_display::<B>(
Battery => self.draw_battery_display(
f,
app_state,
*widget_draw_loc,
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/dialogs/dd_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::cmp::min;

use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame,
text::{Line, Span, Text},
Expand Down Expand Up @@ -351,7 +350,7 @@ impl Painter {
}
}

pub fn draw_dd_dialog<B: Backend>(
pub fn draw_dd_dialog(
&self, f: &mut Frame<'_>, dd_text: Option<Text<'_>>, app_state: &mut App, draw_loc: Rect,
) -> bool {
if let Some(dd_text) = dd_text {
Expand Down
5 changes: 1 addition & 4 deletions src/canvas/dialogs/help_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::{max, min};

use tui::{
backend::Backend,
layout::{Alignment, Rect},
terminal::Frame,
text::Line,
Expand All @@ -16,9 +15,7 @@ const HELP_BASE: &str = " Help ── Esc to close ";

// TODO: [REFACTOR] Make generic dialog boxes to build off of instead?
impl Painter {
pub fn draw_help_dialog<B: Backend>(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect,
) {
pub fn draw_help_dialog(&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect) {
let help_title = Line::from(vec![
Span::styled(" Help ", self.colours.widget_title_style),
Span::styled(
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/widgets/basic_table_arrows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame,
text::Line,
Expand All @@ -13,7 +12,7 @@ use crate::{
};

impl Painter {
pub fn draw_basic_table_arrows<B: Backend>(
pub fn draw_basic_table_arrows(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
if let Some(current_table) = app_state.widget_map.get(&widget_id) {
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/widgets/battery_display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
text::{Line, Span},
Expand All @@ -16,7 +15,7 @@ use crate::{
};

impl Painter {
pub fn draw_battery_display<B: Backend>(
pub fn draw_battery_display(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, draw_border: bool,
widget_id: u64,
) {
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::min;

use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
widgets::Block,
Expand All @@ -17,7 +16,7 @@ use crate::{

impl Painter {
/// Inspired by htop.
pub fn draw_basic_cpu<B: Backend>(
pub fn draw_basic_cpu(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
// Skip the first element, it's the "all" element
Expand Down
19 changes: 8 additions & 11 deletions src/canvas/widgets/cpu_graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;

use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
symbols::Marker,
terminal::Frame,
Expand All @@ -22,9 +21,7 @@ const AVG_POSITION: usize = 1;
const ALL_POSITION: usize = 0;

impl Painter {
pub fn draw_cpu<B: Backend>(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
pub fn draw_cpu(&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64) {
let legend_width = (draw_loc.width as f64 * 0.15) as u16;

if legend_width < 6 {
Expand All @@ -36,7 +33,7 @@ impl Painter {
app_state.move_widget_selection(&WidgetDirection::Left);
}
}
self.draw_cpu_graph::<B>(f, app_state, draw_loc, widget_id);
self.draw_cpu_graph(f, app_state, draw_loc, widget_id);
if let Some(cpu_widget_state) =
app_state.states.cpu_state.widget_states.get_mut(&widget_id)
{
Expand Down Expand Up @@ -80,8 +77,8 @@ impl Painter {
.constraints(constraints)
.split(draw_loc);

self.draw_cpu_graph::<B>(f, app_state, partitioned_draw_loc[graph_index], widget_id);
self.draw_cpu_legend::<B>(
self.draw_cpu_graph(f, app_state, partitioned_draw_loc[graph_index], widget_id);
self.draw_cpu_legend(
f,
app_state,
partitioned_draw_loc[legend_index],
Expand Down Expand Up @@ -175,7 +172,7 @@ impl Painter {
}
}

fn draw_cpu_graph<B: Backend>(
fn draw_cpu_graph(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
const Y_BOUNDS: [f64; 2] = [0.0, 100.5];
Expand Down Expand Up @@ -236,11 +233,11 @@ impl Painter {
legend_constraints: None,
marker,
}
.draw_time_graph::<B>(f, draw_loc, &points);
.draw_time_graph(f, draw_loc, &points);
}
}

fn draw_cpu_legend<B: Backend>(
fn draw_cpu_legend(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
let recalculate_column_widths = app_state.should_get_widget_bounds();
Expand All @@ -262,7 +259,7 @@ impl Painter {
selection_state: SelectionState::new(app_state.is_expanded, is_on_widget),
};

cpu_widget_state.table.draw::<B>(
cpu_widget_state.table.draw(
f,
&draw_info,
app_state.widget_map.get_mut(&widget_id),
Expand Down
6 changes: 3 additions & 3 deletions src/canvas/widgets/disk_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tui::{backend::Backend, layout::Rect, terminal::Frame};
use tui::{layout::Rect, terminal::Frame};

use crate::{
app::{self},
Expand All @@ -7,7 +7,7 @@ use crate::{
};

impl Painter {
pub fn draw_disk_table<B: Backend>(
pub fn draw_disk_table(
&self, f: &mut Frame<'_>, app_state: &mut app::App, draw_loc: Rect, widget_id: u64,
) {
let recalculate_column_widths = app_state.should_get_widget_bounds();
Expand All @@ -26,7 +26,7 @@ impl Painter {
selection_state: SelectionState::new(app_state.is_expanded, is_on_widget),
};

disk_widget_state.table.draw::<B>(
disk_widget_state.table.draw(
f,
&draw_info,
app_state.widget_map.get_mut(&widget_id),
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/widgets/mem_basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
widgets::Block,
Expand All @@ -10,7 +9,7 @@ use crate::{
};

impl Painter {
pub fn draw_basic_memory<B: Backend>(
pub fn draw_basic_memory(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
let mem_data = &app_state.converted_data.mem_data;
Expand Down
Loading

0 comments on commit b34539b

Please sign in to comment.