Only redraw when dirty
This commit is contained in:
parent
4d448585ec
commit
0ba8cb0eb8
25
src/main.rs
25
src/main.rs
|
@ -66,7 +66,7 @@ impl Graphics {
|
|||
let width = 2000;
|
||||
let height = 2000;
|
||||
let buffer = vec![0u32; width * height];
|
||||
|
||||
|
||||
let mut colors = Colors::default();
|
||||
Self::load_colors(&mut colors);
|
||||
|
||||
|
@ -155,10 +155,6 @@ impl Graphics {
|
|||
(size.width as usize, size.height as usize)
|
||||
};
|
||||
|
||||
if width != self.width || height != self.height {
|
||||
self.resize(width, height);
|
||||
}
|
||||
|
||||
let mut buffer = vec![0u32; (width * height) as usize];
|
||||
let content = term.renderable_content();
|
||||
|
||||
|
@ -361,6 +357,7 @@ impl App {
|
|||
while let Ok(event) = self.term_events.try_recv() {
|
||||
match event {
|
||||
TermEvent::Exit => self.should_quit = true,
|
||||
TermEvent::Wakeup => self.redraw(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -435,7 +432,7 @@ impl App {
|
|||
|
||||
self.term_channel.send(TermMsg::Resize(term_size)).unwrap();
|
||||
|
||||
self.graphics.resize(width as usize, height as usize);
|
||||
self.redraw();
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> WindowId {
|
||||
|
@ -449,23 +446,15 @@ fn main() {
|
|||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||
let mut app = App::new(window);
|
||||
let mut counter = 0;
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
*control_flow = ControlFlow::Poll;
|
||||
|
||||
app.update();
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == app.window_id() => {
|
||||
counter += 1;
|
||||
|
||||
if counter > 30 {
|
||||
counter = 0;
|
||||
app.redraw();
|
||||
}
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
app.graphics_context.window().request_redraw();
|
||||
app.update();
|
||||
app.redraw();
|
||||
}
|
||||
Event::WindowEvent { event, window_id } if window_id == app.window_id() => {
|
||||
match event {
|
||||
|
|
Loading…
Reference in New Issue