Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/compositor.rs')
| -rw-r--r-- | helix-view/src/compositor.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/helix-view/src/compositor.rs b/helix-view/src/compositor.rs index e66a8d89..55a15844 100644 --- a/helix-view/src/compositor.rs +++ b/helix-view/src/compositor.rs @@ -23,7 +23,7 @@ pub struct Context<'a> { } #[cfg(feature = "term")] -mod term { +pub mod term { use super::*; pub use tui::buffer::Buffer as Surface; @@ -32,12 +32,24 @@ mod term { pub surface: &'a mut Surface, pub scroll: Option<usize>, } + + pub trait Render { + /// Render the component onto the provided surface. + fn render(&mut self, area: Rect, ctx: &mut RenderContext); + + // TODO: make required_size be layout() instead and part of this trait? + + /// Get cursor position and cursor kind. + fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option<Position>, CursorKind) { + (None, CursorKind::Hidden) + } + } } #[cfg(feature = "term")] pub use term::*; -pub trait Component: Any + AnyComponent { +pub trait Component: Any + AnyComponent + Render { /// Process input events, return true if handled. fn handle_event(&mut self, _event: Event, _ctx: &mut Context) -> EventResult { EventResult::Ignored(None) @@ -48,14 +60,6 @@ pub trait Component: Any + AnyComponent { true } - /// Render the component onto the provided surface. - fn render(&mut self, area: Rect, ctx: &mut RenderContext); - - /// Get cursor position and cursor kind. - fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option<Position>, CursorKind) { - (None, CursorKind::Hidden) - } - /// May be used by the parent component to compute the child area. /// viewport is the maximum allowed area, and the child should stay within those bounds. /// |