use crate::rendering::{Charset, Theme, VideoBuffer};
use crate::window::manager::FocusState;
pub mod battery;
pub mod datetime;
pub mod network;
pub mod new_term;
pub mod system_menu;
pub mod topbar;
pub use battery::BatteryWidget;
pub use datetime::DateTimeWidget;
pub use network::NetworkWidget;
pub use new_term::NewTermWidget;
pub use system_menu::SystemMenuWidget;
pub use topbar::TopBar;
#[derive(Debug, Clone)]
pub enum WidgetClickResult {
NotHandled,
OpenCalendar,
CreateTerminal,
ToggleSystemMenu,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum WidgetAlignment {
Left,
Center,
Right,
}
#[derive(Clone, Copy, Debug)]
pub struct WidgetContext<'a> {
pub cols: u16,
#[allow(dead_code)]
pub rows: u16,
pub focus: FocusState,
#[allow(dead_code)]
pub has_clipboard_content: bool,
#[allow(dead_code)]
pub has_selection: bool,
pub show_date_in_clock: bool,
pub charset: &'a Charset,
}
impl<'a> WidgetContext<'a> {
pub fn new(
cols: u16,
rows: u16,
focus: FocusState,
has_clipboard_content: bool,
has_selection: bool,
show_date_in_clock: bool,
charset: &'a Charset,
) -> Self {
Self {
cols,
rows,
focus,
has_clipboard_content,
has_selection,
show_date_in_clock,
charset,
}
}
}
pub trait Widget {
fn width(&self) -> u16;
fn render(&self, buffer: &mut VideoBuffer, x: u16, theme: &Theme, ctx: &WidgetContext);
fn is_visible(&self, ctx: &WidgetContext) -> bool;
fn contains(&self, point_x: u16, point_y: u16, widget_x: u16) -> bool;
fn update_hover(&mut self, mouse_x: u16, mouse_y: u16, widget_x: u16);
fn handle_click(&mut self, mouse_x: u16, mouse_y: u16, widget_x: u16) -> WidgetClickResult;
fn reset_state(&mut self);
fn update(&mut self, ctx: &WidgetContext);
#[allow(dead_code)]
fn alignment(&self) -> WidgetAlignment;
}