Make `canvas_minimal` example rerender on refresh
@@ -81,9 +81,17 @@ fn main() {
let resource_loader = EmbeddedResourceLoader::new();
let mut renderer = Renderer::new(pathfinder_device, &resource_loader, mode, options);
- // Make a canvas. We're going to draw a house.
let font_context = CanvasFontContext::from_system_source();
- let mut canvas = Canvas::new(framebuffer_size.to_f32()).get_context_2d(font_context);
+ // Wait for a keypress.
+ event_loop.run_forever(|event| {
+ match event {
+ Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
+ Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {
+ ControlFlow::Break
+ }
+ Event::WindowEvent { event: WindowEvent::Refresh, .. } => {
+ // Make a canvas. We're going to draw a house.
+ let mut canvas = Canvas::new(framebuffer_size.to_f32()).get_context_2d(font_context.clone());
// Set line width.
canvas.set_line_width(10.0);
@@ -113,12 +121,7 @@ fn main() {
device.present_surface(&mut context, &mut surface).unwrap();
device.bind_surface_to_context(&mut context, surface).unwrap();
- // Wait for a keypress.
- event_loop.run_forever(|event| {
- match event {
- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
- Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {
- ControlFlow::Break
+ ControlFlow::Continue
}
_ => ControlFlow::Continue,
}
