feat: implement Component trait for modular UI components and refactor TUI views to use it
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
//! Base trait for all TUI components.
|
||||
|
||||
use crossterm::event::Event;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::Frame;
|
||||
use crate::action::Action;
|
||||
use crate::state::AppStateRest;
|
||||
|
||||
/// Base trait for modular UI components in the TUI.
|
||||
pub trait Component {
|
||||
/// Draw the component to the screen.
|
||||
fn draw(&mut self, f: &mut Frame, area: Rect, state: &AppStateRest);
|
||||
|
||||
/// Optional: Pre-render caching phase called before draw.
|
||||
fn pre_render(&mut self, _state: &mut AppStateRest) {}
|
||||
|
||||
/// Handle an input event. Return an optional Action to dispatch.
|
||||
fn handle_event(&mut self, _event: Event, _state: &mut AppStateRest) -> Option<Action> {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,6 @@
|
||||
//!
|
||||
//! This module will grow as shared widgets (buttons, input fields, etc.)
|
||||
//! are extracted from individual overlay and view modules.
|
||||
|
||||
pub mod component;
|
||||
pub use component::Component;
|
||||
|
||||
Reference in New Issue
Block a user