diff --git a/Cargo.lock b/Cargo.lock index 22e79c5..aabfa24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2103,6 +2103,7 @@ dependencies = [ name = "nite" version = "0.1.0" dependencies = [ + "anyhow", "funnylog", "ming", ] diff --git a/Cargo.toml b/Cargo.toml index d5cc810..64fea0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,17 @@ +[package] +name = "nite" +version.workspace = true +edition.workspace = true + +[dependencies] +funnylog.workspace = true +ming.workspace = true +anyhow.workspace = true + [workspace] members = [ - "crates/*" + "crates/*", + "." ] resolver = "2" diff --git a/crates/nite/Cargo.toml b/crates/nite/Cargo.toml deleted file mode 100644 index 2833414..0000000 --- a/crates/nite/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "nite" -version.workspace = true -edition.workspace = true - -[dependencies] -funnylog.workspace = true -ming.workspace = true diff --git a/crates/nite/src/main.rs b/crates/nite/src/main.rs deleted file mode 100644 index de138f3..0000000 --- a/crates/nite/src/main.rs +++ /dev/null @@ -1,35 +0,0 @@ -use ming::*; - -struct Nite { - text: String, -} - -impl Render for Nite { - fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { - div() - .flex() - .size(Length::Definite(DefiniteLength::Fraction(1f32))) - .bg(transparent_black()) - .justify_center() - .items_center() - .text_xl() - .text_color(white()) - .font_family("ComicShannsMono Nerd Font Mono") - .child(format!("HELLO WORLD!!!!! {}", self.text)) - } -} - -fn main() { - App::new().run(|cx| { - cx.open_window( - WindowOptions { - ..Default::default() - }, - |cx| { - cx.new_view(|_cx| Nite { - text: String::new(), - }) - }, - ); - }) -} diff --git a/src/buffer.rs b/src/buffer.rs new file mode 100644 index 0000000..1ff36f1 --- /dev/null +++ b/src/buffer.rs @@ -0,0 +1,16 @@ +use std::path::PathBuf; + +use super::*; + +pub struct Buffer { + text: String, + path: Option +} + +impl Buffer { + pub fn read(path: PathBuf) -> anyhow::Result { + Self { + text: std::fs::read_to_string(path) + } + } +} diff --git a/src/editor.rs b/src/editor.rs new file mode 100644 index 0000000..db6842e --- /dev/null +++ b/src/editor.rs @@ -0,0 +1,14 @@ +use super::*; + +mod element; +mod input; + +pub struct Editor { + buffer: Model +} + +impl Render for Editor { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { + element::EditorElement::new(cx.view()) + } +} diff --git a/src/editor/element.rs b/src/editor/element.rs new file mode 100644 index 0000000..4c3f7fb --- /dev/null +++ b/src/editor/element.rs @@ -0,0 +1,56 @@ +use super::*; + +pub struct EditorElement { + editor: View, +} + +impl EditorElement { + pub fn new(viewref: &View) -> Self { + Self { + editor: viewref.clone(), + } + } +} + +impl IntoElement for EditorElement { + type Element = Self; + + fn into_element(self) -> Self::Element { + self + } +} + +struct EditorLayout {} + +impl Element for EditorElement { + type RequestLayoutState = (); + type PrepaintState = EditorLayout; + + fn prepaint( + &mut self, + id: Option<&GlobalElementId>, + bounds: Bounds, + request_layout: &mut Self::RequestLayoutState, + cx: &mut WindowContext, + ) -> Self::PrepaintState { + EditorLayout {} + } + + fn paint( + &mut self, + id: Option<&GlobalElementId>, + bounds: Bounds, + request_layout: &mut Self::RequestLayoutState, + prepaint: &mut Self::PrepaintState, + cx: &mut WindowContext, + ) { + let focus_handle = self.editor.focus_handle(cx); + let key_context = self.editor.read(cx).key_context(cx); + cx.set_focus_handle(&focus_handle); + cx.set_key_context(key_context); + cx.handle_input( + &focus_handle, + ElementInputHandler::new(bounds, self.editor.clone()), + ); + } +} diff --git a/src/editor/input.rs b/src/editor/input.rs new file mode 100644 index 0000000..085f3c2 --- /dev/null +++ b/src/editor/input.rs @@ -0,0 +1,13 @@ +use super::*; + +impl Editor { + pub fn key_context(&self, cx: &AppContext) -> KeyContext { + let mut c = KeyContext::new_with_defaults(); + + c.add("Editor"); + + c + } +} + +impl ViewInputHandler for Editor {} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a451d79 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,25 @@ +use ming::*; + +mod buffer; +mod editor; + +struct Nite { + editor: View, +} + +fn main() { + App::new().run(|cx| { + cx.open_window( + WindowOptions { + ..Default::default() + }, + |cx| { + let focus = cx.focus_handle(); + + cx.new_view(|_cx| Nite { + text: String::new(), + }) + }, + ); + }) +}