diff --git a/nested/src/sdf/term.rs b/nested/src/sdf/term.rs index 29b950c..b87212a 100644 --- a/nested/src/sdf/term.rs +++ b/nested/src/sdf/term.rs @@ -43,19 +43,25 @@ pub struct SdfTerm { fg_layers: HashMap, (bool, LayerId2d)>, font_height: u32, - //font: Mutex, + font: Arc>, renderer: Arc> } impl SdfTerm { pub fn new(renderer: Arc>) -> Self { + + let font_path = Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf"); + let mut font_file = File::open(font_path).unwrap(); + let mut font_data = Vec::new(); + font_file.read_to_end(&mut font_data).unwrap(); + SdfTerm { src_view: None, bg_layers: HashMap::new(), fg_layers: HashMap::new(), font_height: 30, - //font: Mutex::new(Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf"),0).unwrap()), + font: Arc::new(font_data), renderer } } @@ -147,8 +153,9 @@ impl SdfTerm { // foreground layer if let Some(c) = atom.c { - let font = Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Light.ttf"),0).unwrap(); - let mut ch = Character::from_font(&font, c).with_size(1.0).with_tesselation_factor(0.01); + let font_index = 0; + let fontkit = Font::from_bytes(self.font.clone(), font_index).unwrap(); + let mut ch = Character::from_font(&fontkit, c).with_size(1.0); let (r,g,b) = atom.style.fg_color.unwrap_or((0, 0, 0)); diff --git a/shell/src/main.rs b/shell/src/main.rs index 10012ee..adad760 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -145,17 +145,6 @@ async fn main() { //now check if a rerender was requested, or if we worked on all //events on that batch - term_port.update(); - renderer.lock().unwrap().set_layer_order( - vec![ - //vec![ color_layer_id.into() ].into_iter(), - sdf_term.read().unwrap().get_order().into_iter() - ] - .into_iter() - .flatten() - .collect::>() - .as_slice() - ); match event{ winit::event::Event::WindowEvent{window_id: _, event: winit::event::WindowEvent::Resized(newsize)} => { @@ -163,6 +152,7 @@ async fn main() { } winit::event::Event::WindowEvent{window_id: _, event: winit::event::WindowEvent::KeyboardInput{ device_id, input, is_synthetic }} => { if input.state == winit::event::ElementState::Pressed { + if let Some(kc) = input.virtual_keycode { match kc { winit::event::VirtualKeyCode::Space => { @@ -321,46 +311,57 @@ async fn main() { } } } + + status_chars.clear(); + let cur = process_list_editor.get_cursor(); + + if cur.tree_addr.len() > 0 { + status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); + for x in cur.tree_addr { + for c in format!("{}", x).chars() { + status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20)))); + } + status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80)))); + } + + status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); + for c in + match cur.leaf_mode { + ListCursorMode::Insert => "INSERT", + ListCursorMode::Select => "SELECT", + ListCursorMode::Modify => "MODIFY" + }.chars() + { + status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); + } + status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); + } else { + for c in "Press to enter".chars() { + status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); + } + } } } winit::event::Event::MainEventsCleared => { window.request_redraw(); } winit::event::Event::RedrawRequested(_) => { - //term_port.update(); + term_port.update(); + renderer.lock().unwrap().set_layer_order( + vec![ + //vec![ color_layer_id.into() ].into_iter(), + sdf_term.read().unwrap().get_order().into_iter() + ] + .into_iter() + .flatten() + .collect::>() + .as_slice() + ); + renderer.lock().unwrap().render(&window); } _ => {}, } - - status_chars.clear(); - let cur = process_list_editor.get_cursor(); - - if cur.tree_addr.len() > 0 { - status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); - for x in cur.tree_addr { - for c in format!("{}", x).chars() { - status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20)))); - } - status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80)))); - } - - status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); - for c in - match cur.leaf_mode { - ListCursorMode::Insert => "INSERT", - ListCursorMode::Select => "SELECT", - ListCursorMode::Modify => "MODIFY" - }.chars() - { - status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); - } - status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)))); - } else { - for c in "Press to enter".chars() { - status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20)))); - } - } }); /*