From 80b91b4eb84e9d4637951bdb84d20ae3d953a638 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Mon, 1 Jan 2024 22:36:11 -0500 Subject: [PATCH] add widget trait --- src/widgets.rs | 8 ++++++++ src/widgets/battery_info.rs | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 src/widgets/battery_info.rs diff --git a/src/widgets.rs b/src/widgets.rs index 21cf0479..a477e1d2 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -13,3 +13,11 @@ pub use mem_graph::*; pub use net_graph::*; pub use process_table::*; pub use temperature_table::*; + +use tui::{layout::Rect, Frame}; + +/// A [`Widget`] converts raw data into something that a user can see and interact with. +pub trait Widget { + /// How to actually draw the widget to the terminal. + fn draw(&self, f: &mut Frame<'_>, draw_location: Rect, widget_id: u64); +} diff --git a/src/widgets/battery_info.rs b/src/widgets/battery_info.rs new file mode 100644 index 00000000..68bbca79 --- /dev/null +++ b/src/widgets/battery_info.rs @@ -0,0 +1,5 @@ +#[derive(Default)] +pub struct BatteryWidgetState { + pub currently_selected_battery_index: usize, + pub tab_click_locs: Option>, +}