diff --git a/src/app/graph.rs b/src/app/cpu_graph.rs similarity index 84% rename from src/app/graph.rs rename to src/app/cpu_graph.rs index 7f158b8..9fe439c 100644 --- a/src/app/graph.rs +++ b/src/app/cpu_graph.rs @@ -2,36 +2,38 @@ use std::collections::VecDeque; use iced::{Color, Point, Renderer, Theme, mouse, widget::canvas}; +use crate::app; + const CYAN: Color = Color::from_rgb8(0, 255, 255); #[derive(Default)] -pub struct Graph { +pub struct CpuGraph { timeline: VecDeque, pub cache: canvas::Cache, } -impl Graph { - pub fn new(value: f32) -> Self { +impl CpuGraph { + pub fn new(usage: f32) -> Self { Self { timeline: { let mut vec = VecDeque::new(); - vec.push_front(value); + vec.push_front(usage); vec }, ..Default::default() } } - pub fn update(&mut self, value: f32) { - self.timeline.push_back(value); + pub fn update(&mut self, usage: f32) { + self.timeline.push_back(usage); if self.timeline.len() > 1000 { self.timeline.pop_front(); } } } -impl canvas::Program<(), Theme, Renderer> for Graph { +impl canvas::Program for CpuGraph { type State = (); fn draw( &self, diff --git a/src/app/mod.rs b/src/app/mod.rs index bcc6e52..acc8959 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -4,9 +4,9 @@ use iced::{ }; use smol::Timer; -use crate::{app::graph::Graph, sysinfo_snapshot::SysinfoSnapshot}; +use crate::{app::cpu_graph::CpuGraph, sysinfo_snapshot::SysinfoSnapshot}; -mod graph; +mod cpu_graph; enum Message { Info(SysinfoSnapshot), @@ -14,8 +14,8 @@ enum Message { #[derive(Default)] struct State { - total_cpu_graph: Graph, - cpu_graphs: Vec, + total_cpu_graph: CpuGraph, + cpu_graphs: Vec, } impl State { @@ -51,12 +51,12 @@ impl State { self.cpu_graphs = snapshot .cpus .into_iter() - .map(|value| Graph::new(value)) + .map(|usage| CpuGraph::new(usage)) .collect(); } else { - for (graph, value) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter()) + for (graph, usage) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter()) { - graph.update(value); + graph.update(usage); graph.cache.clear(); } }