feat: implement Component trait for modular UI components and refactor TUI views to use it

This commit is contained in:
asepharyana
2026-07-21 06:08:00 +07:00
parent 6ab532018a
commit d59713d3e3
10 changed files with 326 additions and 272 deletions
@@ -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;