This commit is contained in:
mars 2022-10-04 13:01:05 -06:00
parent c2e202a743
commit 12b3bf2f14
1 changed files with 27 additions and 15 deletions

View File

@ -17,9 +17,6 @@ use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Window, WindowBuilder};
const WINDOW_WIDTH: usize = 900;
const WINDOW_HEIGHT: usize = 600;
static FONT_DATA: &[u8] = include_bytes!("/usr/share/fonts/local/TamzenForPowerline10x20r.bdf");
pub struct TermListener {}
@ -47,8 +44,8 @@ impl App {
let cell_height = font.bounds().height as usize;
let term_size = alacritty_terminal::term::SizeInfo::new(
WINDOW_WIDTH as f32,
WINDOW_HEIGHT as f32,
2000.0,
2000.0,
cell_width as f32,
cell_height as f32,
0.0,
@ -157,12 +154,10 @@ impl App {
}
pub fn redraw(&mut self) {
/*let (width, height) = {
let (width, height) = {
let size = self.graphics.window().inner_size();
(size.width as usize, size.height as usize)
};*/
let (width, height) = (WINDOW_WIDTH, WINDOW_HEIGHT);
};
let mut buffer = vec![0u32; (width * height) as usize];
let term = self.term.lock();
@ -182,7 +177,11 @@ impl App {
let mut px_row = term_row * width * self.cell_height;
if px_row >= buffer.len() {
if (term_row + 1) * self.cell_height >= height {
continue;
}
if (term_col + 1) * self.cell_width >= width {
continue;
}
@ -196,11 +195,7 @@ impl App {
bg
};
let off = px_start + x as usize;
// if off < buffer.len() {
buffer[off] = color;
// }
buffer[px_start + x as usize] = color;
}
px_row += width;
@ -243,6 +238,20 @@ impl App {
}
}
}
pub fn on_resize(&mut self, width: u32, height: u32) {
let term_size = alacritty_terminal::term::SizeInfo::new(
width as f32,
height as f32,
self.cell_width as f32,
self.cell_height as f32,
0.0,
0.0,
false,
);
self.term_channel.send(TermMsg::Resize(term_size)).unwrap();
}
}
fn virtual_keycode_to_byte(keycode: winit::event::VirtualKeyCode) -> Option<u8> {
@ -329,6 +338,9 @@ fn main() {
WindowEvent::KeyboardInput { input, .. } => {
app.on_keyboard_input(&input);
}
WindowEvent::Resized(size) => {
app.on_resize(size.width, size.height);
}
_ => {}
}
}