Closer to compiling

This commit is contained in:
Blaž Hrastnik 2022-04-05 15:54:57 +09:00
parent 842cd2cc13
commit 842a5fc979
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640
9 changed files with 49 additions and 0 deletions

View File

@ -15,6 +15,7 @@ lsp = ["helix-lsp", "tokio-runtime"]
dap = ["helix-dap", "tokio-stream", "tokio-runtime"] dap = ["helix-dap", "tokio-stream", "tokio-runtime"]
tokio-runtime = ["tokio"] tokio-runtime = ["tokio"]
term = ["crossterm", "tui"] term = ["crossterm", "tui"]
ui = []
[dependencies] [dependencies]
bitflags = "1.3" bitflags = "1.3"

View File

@ -46,9 +46,33 @@ fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option<Position>, CursorKind) {
} }
} }
#[cfg(feature = "ui")]
pub mod ui {
use super::*;
pub type Surface = ();
pub struct RenderContext<'a> {
pub editor: &'a Editor,
// 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:
}
// TODO: make required_size be layout() instead and part of this trait?
}
}
#[cfg(feature = "term")] #[cfg(feature = "term")]
pub use term::*; pub use term::*;
#[cfg(feature = "ui")]
pub use ui::*;
pub trait Component: Any + AnyComponent + Render { pub trait Component: Any + AnyComponent + Render {
/// Process input events, return true if handled. /// Process input events, return true if handled.
fn handle_event(&mut self, _event: Event, _ctx: &mut Context) -> EventResult { fn handle_event(&mut self, _event: Event, _ctx: &mut Context) -> EventResult {

View File

@ -121,4 +121,7 @@ fn render(&mut self, viewport: Rect, cx: &mut RenderContext<'_>) {
} }
} }
#[cfg(feature = "ui")]
impl compositor::ui::Render for Info {}
impl Component for Info {} impl Component for Info {}

View File

@ -1397,6 +1397,9 @@ fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind)
} }
} }
#[cfg(feature = "ui")]
impl compositor::ui::Render for EditorView {}
fn canonicalize_key(key: &mut KeyEvent) { fn canonicalize_key(key: &mut KeyEvent) {
if let KeyEvent { if let KeyEvent {
code: KeyCode::Char(_), code: KeyCode::Char(_),

View File

@ -282,6 +282,9 @@ fn render(&mut self, area: Rect, cx: &mut RenderContext<'_>) {
} }
} }
#[cfg(feature = "ui")]
impl compositor::ui::Render for Markdown {}
impl Component for Markdown { impl Component for Markdown {
#[cfg(not(feature = "term"))] #[cfg(not(feature = "term"))]
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {

View File

@ -55,6 +55,9 @@ fn cursor(&self, area: Rect, ctx: &Editor) -> (Option<Position>, CursorKind) {
} }
} }
#[cfg(feature = "ui")]
impl<T: Component + 'static> compositor::ui::Render for Overlay<T> {}
impl<T: Component + 'static> Component for Overlay<T> { impl<T: Component + 'static> Component for Overlay<T> {
fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> { fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> {
let area = Rect { let area = Rect {

View File

@ -266,6 +266,9 @@ fn cursor(&self, area: Rect, ctx: &Editor) -> (Option<Position>, CursorKind) {
} }
} }
#[cfg(feature = "ui")]
impl<T: 'static> compositor::ui::Render for FilePicker<T> {}
impl<T: 'static> Component for FilePicker<T> { impl<T: 'static> Component for FilePicker<T> {
fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult { fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult {
// TODO: keybinds for scrolling preview // TODO: keybinds for scrolling preview
@ -658,3 +661,6 @@ fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind)
self.prompt.cursor(area, editor) self.prompt.cursor(area, editor)
} }
} }
#[cfg(feature = "ui")]
impl<T: 'static> compositor::ui::Render for Picker<T> {}

View File

@ -201,3 +201,6 @@ fn render(&mut self, viewport: Rect, cx: &mut RenderContext<'_>) {
self.contents.render(inner, cx); self.contents.render(inner, cx);
} }
} }
#[cfg(feature = "ui")]
impl<T: Component> compositor::ui::Render for Popup<T> {}

View File

@ -455,6 +455,9 @@ fn cursor(&self, area: Rect, _editor: &Editor) -> (Option<Position>, CursorKind)
} }
} }
#[cfg(feature = "ui")]
impl compositor::ui::Render for Prompt {}
impl Component for Prompt { impl Component for Prompt {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let event = match event { let event = match event {