| 278 | |
| 279 | #[test] |
| 280 | fn can_draw_using_gc() { |
| 281 | let canvas = Canvas::new(); |
| 282 | let mut stream = canvas.stream(); |
| 283 | |
| 284 | // Draw using a graphics context |
| 285 | canvas.draw(|gc| { |
| 286 | gc.new_path(); |
| 287 | gc.move_to(0.0, 0.0); |
| 288 | gc.line_to(10.0, 0.0); |
| 289 | gc.line_to(10.0, 10.0); |
| 290 | gc.line_to(0.0, 10.0); |
| 291 | }); |
| 292 | |
| 293 | // Check we can get the results via the stream |
| 294 | executor::block_on(async { |
| 295 | assert!(stream.next().await == Some(Draw::ResetFrame)); |
| 296 | assert!(stream.next().await == Some(Draw::StartFrame)); |
| 297 | assert!(stream.next().await == Some(Draw::ClearCanvas(Color::Rgba(0.0, 0.0, 0.0, 0.0)))); |
| 298 | assert!(stream.next().await == Some(Draw::Path(PathOp::NewPath))); |
| 299 | assert!(stream.next().await == Some(Draw::Path(PathOp::Move(0.0, 0.0)))); |
| 300 | assert!(stream.next().await == Some(Draw::Path(PathOp::Line(10.0, 0.0)))); |
| 301 | assert!(stream.next().await == Some(Draw::Path(PathOp::Line(10.0, 10.0)))); |
| 302 | assert!(stream.next().await == Some(Draw::Path(PathOp::Line(0.0, 10.0)))); |
| 303 | assert!(stream.next().await == Some(Draw::ShowFrame)); |
| 304 | }); |
| 305 | } |
| 306 | |
| 307 | #[test] |
| 308 | fn restore_rewinds_canvas() { |