ombre: Move `Canvas::size` to `PaintSurface` trait
748d7dc30ed973f40e63a134c581e72163cb21a3
1 parent
a23e08b9
ombre/src/paint/canvas.rs
+4 -5
| 401 | 401 | /// Canvas configuration. |
|
| 402 | 402 | config: Config, |
|
| 403 | 403 | } |
|
| 404 | 404 | ||
| 405 | 405 | impl<R: RenderBackend, const N: usize> Canvas<R, N> { |
|
| 406 | - | /// Returns the current size of the drawable area in logical pixels. |
|
| 407 | - | pub fn size(&self) -> Size<f32> { |
|
| 408 | - | self.size |
|
| 409 | - | } |
|
| 410 | - | ||
| 411 | 406 | /// Returns a reference to the font library used by this canvas. |
|
| 412 | 407 | pub fn fonts(&self) -> &Fonts<Image> { |
|
| 413 | 408 | &self.fonts |
|
| 414 | 409 | } |
|
| 415 | 410 |
| 507 | 502 | }) |
|
| 508 | 503 | } |
|
| 509 | 504 | } |
|
| 510 | 505 | ||
| 511 | 506 | impl<R: RenderBackend, const N: usize> PaintSurface<R> for Canvas<R, N> { |
|
| 507 | + | fn size(&self) -> Size<f32> { |
|
| 508 | + | self.size / self.scale |
|
| 509 | + | } |
|
| 510 | + | ||
| 512 | 511 | fn clear(&mut self) { |
|
| 513 | 512 | self.render.batch.clear(); |
|
| 514 | 513 | self.action = Some(PassAction::Clear { |
|
| 515 | 514 | color: Some(Rgba::TRANSPARENT), |
|
| 516 | 515 | depth: Some(ZDepth::from(1.)), |
ombre/src/paint/traits.rs
+4 -1
| 2 | 2 | // (c) 2019 the Piet Authors, the traits and docs here are heavily drawn from `piet`. |
|
| 3 | 3 | #![warn(missing_docs)] |
|
| 4 | 4 | ||
| 5 | 5 | use crate::gfx::RenderBackend; |
|
| 6 | 6 | use crate::gfx::{Image, Point2D, Rect, Rgba, Rgba8, Transform2D}; |
|
| 7 | - | use crate::math::{Local, Screen}; |
|
| 7 | + | use crate::math::{Local, Screen, Size}; |
|
| 8 | 8 | use crate::text::Text; |
|
| 9 | 9 | ||
| 10 | 10 | use super::shape::{Shape, ToGeometry}; |
|
| 11 | 11 | ||
| 12 | 12 | /// Errors that can occur during paint operations. |
| 43 | 43 | /// Drawing operations may cause internal errors, which may also occur |
|
| 44 | 44 | /// asynchronously after the drawing command was issued. This method reports |
|
| 45 | 45 | /// any such error that has been detected. |
|
| 46 | 46 | fn status(&mut self) -> Result<(), Error>; |
|
| 47 | 47 | ||
| 48 | + | /// Return the size of the paint surface in logical pixels. |
|
| 49 | + | fn size(&self) -> Size<f32>; |
|
| 50 | + | ||
| 48 | 51 | /// Clear the canvas. |
|
| 49 | 52 | /// |
|
| 50 | 53 | /// Clears the surface of anything that was drawn. Also clears any |
|
| 51 | 54 | /// pending drawing operations. |
|
| 52 | 55 | fn clear(&mut self); |