refactor: move some state code around (#839)

This commit is contained in:
Clement Tsang 2022-10-16 03:10:30 -04:00 committed by GitHub
parent c0a5fd15b2
commit b879c36588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 37 deletions

View file

@ -872,11 +872,11 @@ pub struct BottomWidget {
#[builder(default = None)]
pub parent_reflector: Option<(WidgetDirection, u64)>,
/// Top left corner when drawn, for mouse click detection. (x, y)
/// Top left corner when drawn, for mouse click detection. (x, y)
#[builder(default = None)]
pub top_left_corner: Option<(u16, u16)>,
/// Bottom right corner when drawn, for mouse click detection. (x, y)
/// Bottom right corner when drawn, for mouse click detection. (x, y)
#[builder(default = None)]
pub bottom_right_corner: Option<(u16, u16)>,
}

View file

@ -7,7 +7,10 @@ use crate::{
constants,
};
use super::widgets::{CpuWidgetState, DiskTableWidget, ProcWidget, TempWidgetState};
use super::widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
ProcWidget, TempWidgetState,
};
#[derive(Debug)]
pub enum ScrollDirection {
@ -140,20 +143,6 @@ impl ProcState {
}
}
pub struct NetWidgetState {
pub current_display_time: u64,
pub autohide_timer: Option<Instant>,
}
impl NetWidgetState {
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self {
NetWidgetState {
current_display_time,
autohide_timer,
}
}
}
pub struct NetState {
pub force_update: Option<u64>,
pub widget_states: HashMap<u64, NetWidgetState>,
@ -198,19 +187,6 @@ impl CpuState {
}
}
pub struct MemWidgetState {
pub current_display_time: u64,
pub autohide_timer: Option<Instant>,
}
impl MemWidgetState {
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self {
MemWidgetState {
current_display_time,
autohide_timer,
}
}
}
pub struct MemState {
pub force_update: Option<u64>,
pub widget_states: HashMap<u64, MemWidgetState>,
@ -281,12 +257,6 @@ pub struct BasicTableWidgetState {
pub right_brc: Option<(u16, u16)>,
}
#[derive(Default)]
pub struct BatteryWidgetState {
pub currently_selected_battery_index: usize,
pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>,
}
pub struct BatteryState {
pub widget_states: HashMap<u64, BatteryWidgetState>,
}

View file

@ -11,3 +11,12 @@ pub use disk_table::*;
pub mod cpu_graph;
pub use cpu_graph::*;
pub mod net_graph;
pub use net_graph::*;
pub mod mem_graph;
pub use mem_graph::*;
pub mod battery_widget;
pub use battery_widget::*;

View file

@ -0,0 +1,5 @@
#[derive(Default)]
pub struct BatteryWidgetState {
pub currently_selected_battery_index: usize,
pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>,
}

View file

@ -0,0 +1,15 @@
use std::time::Instant;
pub struct MemWidgetState {
pub current_display_time: u64,
pub autohide_timer: Option<Instant>,
}
impl MemWidgetState {
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self {
MemWidgetState {
current_display_time,
autohide_timer,
}
}
}

View file

@ -0,0 +1,15 @@
use std::time::Instant;
pub struct NetWidgetState {
pub current_display_time: u64,
pub autohide_timer: Option<Instant>,
}
impl NetWidgetState {
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self {
NetWidgetState {
current_display_time,
autohide_timer,
}
}
}

View file

@ -11,7 +11,10 @@ use std::{
use crate::{
app::{
layout_manager::*,
widgets::{CpuWidgetState, DiskTableWidget, ProcWidget, ProcWidgetMode, TempWidgetState},
widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
ProcWidget, ProcWidgetMode, TempWidgetState,
},
*,
},
canvas::{canvas_colours::CanvasColours, ColourScheme},