Closer to compiling

gui
Blaž Hrastnik 3 years ago
parent 842cd2cc13
commit 842a5fc979
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640

@ -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"

@ -46,9 +46,33 @@ pub mod term {
}
}
#[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")]
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 {

@ -121,4 +121,7 @@ impl compositor::term::Render for Info {
}
}
#[cfg(feature = "ui")]
impl compositor::ui::Render for Info {}
impl Component for Info {}

@ -1397,6 +1397,9 @@ impl compositor::term::Render for EditorView {
}
}
#[cfg(feature = "ui")]
impl compositor::ui::Render for EditorView {}
fn canonicalize_key(key: &mut KeyEvent) {
if let KeyEvent {
code: KeyCode::Char(_),

@ -282,6 +282,9 @@ impl compositor::term::Render for Markdown {
}
}
#[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)> {

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

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

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

@ -455,6 +455,9 @@ impl compositor::term::Render for Prompt {
}
}
#[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 {

Loading…
Cancel
Save