attempt at text
This commit is contained in:
parent
3f7744ef8f
commit
a512b21d23
9 changed files with 137 additions and 44 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2103,6 +2103,7 @@ dependencies = [
|
|||
name = "nite"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"funnylog",
|
||||
"ming",
|
||||
]
|
||||
|
|
13
Cargo.toml
13
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"
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "nite"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
funnylog.workspace = true
|
||||
ming.workspace = true
|
|
@ -1,35 +0,0 @@
|
|||
use ming::*;
|
||||
|
||||
struct Nite {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Render for Nite {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> 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(),
|
||||
})
|
||||
},
|
||||
);
|
||||
})
|
||||
}
|
16
src/buffer.rs
Normal file
16
src/buffer.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub struct Buffer {
|
||||
text: String,
|
||||
path: Option<PathBuf>
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
pub fn read(path: PathBuf) -> anyhow::Result<Self> {
|
||||
Self {
|
||||
text: std::fs::read_to_string(path)
|
||||
}
|
||||
}
|
||||
}
|
14
src/editor.rs
Normal file
14
src/editor.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use super::*;
|
||||
|
||||
mod element;
|
||||
mod input;
|
||||
|
||||
pub struct Editor {
|
||||
buffer: Model<crate::buffer::Buffer>
|
||||
}
|
||||
|
||||
impl Render for Editor {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
element::EditorElement::new(cx.view())
|
||||
}
|
||||
}
|
56
src/editor/element.rs
Normal file
56
src/editor/element.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use super::*;
|
||||
|
||||
pub struct EditorElement {
|
||||
editor: View<Editor>,
|
||||
}
|
||||
|
||||
impl EditorElement {
|
||||
pub fn new(viewref: &View<Editor>) -> 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<Pixels>,
|
||||
request_layout: &mut Self::RequestLayoutState,
|
||||
cx: &mut WindowContext,
|
||||
) -> Self::PrepaintState {
|
||||
EditorLayout {}
|
||||
}
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
id: Option<&GlobalElementId>,
|
||||
bounds: Bounds<Pixels>,
|
||||
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()),
|
||||
);
|
||||
}
|
||||
}
|
13
src/editor/input.rs
Normal file
13
src/editor/input.rs
Normal file
|
@ -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 {}
|
25
src/main.rs
Normal file
25
src/main.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use ming::*;
|
||||
|
||||
mod buffer;
|
||||
mod editor;
|
||||
|
||||
struct Nite {
|
||||
editor: View<editor::Editor>,
|
||||
}
|
||||
|
||||
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(),
|
||||
})
|
||||
},
|
||||
);
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue