use ratatui::layout::Rect;
use ratatui::Frame;
use crate::input::{KeyEvent, MouseEvent};
use crate::operation::{Event, Operation};
use crate::settings::Settings;
use crate::theme::Theme;
pub type WidgetId = &'static str;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FocusOp {
Next,
Prev,
Up,
Down,
Left,
Right,
}
pub struct InputResult {
pub ops: Vec<Operation>,
pub consumed: bool,
}
impl InputResult {
pub fn consumed(ops: Vec<Operation>) -> Self {
Self {
ops,
consumed: true,
}
}
pub fn ignored() -> Self {
Self {
ops: vec![],
consumed: false,
}
}
}
pub trait FocusableWidget {
fn id(&self) -> WidgetId;
fn handle_key(&self, key: KeyEvent) -> InputResult;
fn handle_mouse(&self, _mouse: MouseEvent, _area: Rect) -> InputResult {
InputResult::ignored()
}
fn handle_operation(&mut self, op: &Operation, settings: &Settings) -> Option<Event>;
fn render(&self, frame: &mut Frame, area: Rect, focused: bool, theme: &Theme);
fn captures_tab(&self) -> bool {
false
}
fn focusable(&self) -> bool {
true
}
}