Quick cell cull + backup resize events

This commit is contained in:
mars 2022-10-04 17:52:23 -06:00
parent 188dae668a
commit 7129429e88
1 changed files with 25 additions and 11 deletions

View File

@ -47,6 +47,8 @@ pub struct App {
should_quit: bool,
cell_width: usize,
cell_height: usize,
current_width: usize,
current_height: usize,
colors: Colors,
term_loop: JoinHandle<(TermEventLoop<Pty, TermListener>, TermState)>,
term_channel: MioSender<TermMsg>,
@ -66,9 +68,12 @@ impl App {
let cell_width = normal_font.bounds().width as usize;
let cell_height = normal_font.bounds().height as usize;
let current_width = 2000;
let current_height = 2000;
let term_size = alacritty_terminal::term::SizeInfo::new(
2000.0,
2000.0,
current_width as f32,
current_height as f32,
cell_width as f32,
cell_height as f32,
0.0,
@ -113,6 +118,8 @@ impl App {
should_quit: false,
cell_width,
cell_height,
current_width,
current_height,
term,
term_channel,
term_events,
@ -176,6 +183,10 @@ impl App {
(size.width as usize, size.height as usize)
};
if width != self.current_width || height != self.current_height {
self.on_resize(width as u32, height as u32);
}
let mut buffer = vec![0u32; (width * height) as usize];
let term = self.term.lock();
let content = term.renderable_content();
@ -185,6 +196,15 @@ impl App {
use alacritty_terminal::term::cell::Flags as CellFlags;
for cell in content.display_iter.into_iter() {
let term_row = cell.point.line.0 as usize;
let term_col = cell.point.column.0 as usize;
if (term_row + 1) * self.cell_height >= height
|| (term_col + 1) * self.cell_width >= width
{
continue;
}
if cell.flags.contains(CellFlags::HIDDEN) {
continue;
}
@ -196,15 +216,6 @@ impl App {
};
if let Some(glyph) = font.glyphs().get(&cell.c) {
let term_row = cell.point.line.0 as usize;
let term_col = cell.point.column.0 as usize;
if (term_row + 1) * self.cell_height >= height
|| (term_col + 1) * self.cell_width >= width
{
continue;
}
let (bg, fg) = if cell.flags.contains(CellFlags::INVERSE) {
(&cell.fg, &cell.bg)
} else {
@ -361,6 +372,9 @@ impl App {
);
self.term_channel.send(TermMsg::Resize(term_size)).unwrap();
self.current_width = width as usize;
self.current_height = height as usize;
}
}