From 842a5fc979ae0ea9f8f70cc307cc89be51780a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 5 Apr 2022 15:54:57 +0900 Subject: [PATCH] Closer to compiling --- helix-view/Cargo.toml | 1 + helix-view/src/compositor.rs | 24 ++++++++++++++++++++++++ helix-view/src/info.rs | 3 +++ helix-view/src/ui/editor.rs | 3 +++ helix-view/src/ui/markdown.rs | 3 +++ helix-view/src/ui/overlay.rs | 3 +++ helix-view/src/ui/picker.rs | 6 ++++++ helix-view/src/ui/popup.rs | 3 +++ helix-view/src/ui/prompt.rs | 3 +++ 9 files changed, 49 insertions(+) diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 69df49ccf..a73bd8f7a 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -15,6 +15,7 @@ lsp = ["helix-lsp", "tokio-runtime"] dap = ["helix-dap", "tokio-stream", "tokio-runtime"] tokio-runtime = ["tokio"] term = ["crossterm", "tui"] +ui = [] [dependencies] bitflags = "1.3" diff --git a/helix-view/src/compositor.rs b/helix-view/src/compositor.rs index 55a158441..e367e54e0 100644 --- a/helix-view/src/compositor.rs +++ b/helix-view/src/compositor.rs @@ -46,9 +46,33 @@ fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option, 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, + } + + 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")] pub use term::*; +#[cfg(feature = "ui")] +pub use ui::*; + pub trait Component: Any + AnyComponent + Render { /// Process input events, return true if handled. fn handle_event(&mut self, _event: Event, _ctx: &mut Context) -> EventResult { diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs index cb6021bf6..df43937a8 100644 --- a/helix-view/src/info.rs +++ b/helix-view/src/info.rs @@ -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 {} diff --git a/helix-view/src/ui/editor.rs b/helix-view/src/ui/editor.rs index ac2a9c596..2287a0649 100644 --- a/helix-view/src/ui/editor.rs +++ b/helix-view/src/ui/editor.rs @@ -1397,6 +1397,9 @@ fn cursor(&self, _area: Rect, editor: &Editor) -> (Option, CursorKind) } } +#[cfg(feature = "ui")] +impl compositor::ui::Render for EditorView {} + fn canonicalize_key(key: &mut KeyEvent) { if let KeyEvent { code: KeyCode::Char(_), diff --git a/helix-view/src/ui/markdown.rs b/helix-view/src/ui/markdown.rs index 760241d59..b7d1cec8f 100644 --- a/helix-view/src/ui/markdown.rs +++ b/helix-view/src/ui/markdown.rs @@ -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 { #[cfg(not(feature = "term"))] fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { diff --git a/helix-view/src/ui/overlay.rs b/helix-view/src/ui/overlay.rs index 0b13212e9..8f534b60a 100644 --- a/helix-view/src/ui/overlay.rs +++ b/helix-view/src/ui/overlay.rs @@ -55,6 +55,9 @@ fn cursor(&self, area: Rect, ctx: &Editor) -> (Option, CursorKind) { } } +#[cfg(feature = "ui")] +impl compositor::ui::Render for Overlay {} + impl Component for Overlay { fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> { let area = Rect { diff --git a/helix-view/src/ui/picker.rs b/helix-view/src/ui/picker.rs index 91022e442..0bb3a23f6 100644 --- a/helix-view/src/ui/picker.rs +++ b/helix-view/src/ui/picker.rs @@ -266,6 +266,9 @@ fn cursor(&self, area: Rect, ctx: &Editor) -> (Option, CursorKind) { } } +#[cfg(feature = "ui")] +impl compositor::ui::Render for FilePicker {} + impl Component for FilePicker { fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult { // TODO: keybinds for scrolling preview @@ -658,3 +661,6 @@ fn cursor(&self, area: Rect, editor: &Editor) -> (Option, CursorKind) self.prompt.cursor(area, editor) } } + +#[cfg(feature = "ui")] +impl compositor::ui::Render for Picker {} diff --git a/helix-view/src/ui/popup.rs b/helix-view/src/ui/popup.rs index eb6823a7e..329e4a0e5 100644 --- a/helix-view/src/ui/popup.rs +++ b/helix-view/src/ui/popup.rs @@ -201,3 +201,6 @@ fn render(&mut self, viewport: Rect, cx: &mut RenderContext<'_>) { self.contents.render(inner, cx); } } + +#[cfg(feature = "ui")] +impl compositor::ui::Render for Popup {} diff --git a/helix-view/src/ui/prompt.rs b/helix-view/src/ui/prompt.rs index 2d73fb1ea..911ae2ef7 100644 --- a/helix-view/src/ui/prompt.rs +++ b/helix-view/src/ui/prompt.rs @@ -455,6 +455,9 @@ fn cursor(&self, area: Rect, _editor: &Editor) -> (Option, CursorKind) } } +#[cfg(feature = "ui")] +impl compositor::ui::Render for Prompt {} + impl Component for Prompt { fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { let event = match event {