iced_graphics/
viewport.rs1use crate::core::renderer::Scale;
2use crate::core::{Size, Transformation};
3
4#[derive(Debug, Clone)]
6pub struct Viewport {
7 physical_size: Size<u32>,
8 logical_size: Size<f32>,
9 scale: Scale,
10 projection: Transformation,
11}
12
13impl Viewport {
14 pub fn with_physical_size(size: Size<u32>, scale: Scale) -> Viewport {
17 let scale_factor = scale.total();
18
19 Viewport {
20 physical_size: size,
21 logical_size: Size::new(
22 size.width as f32 / scale_factor,
23 size.height as f32 / scale_factor,
24 ),
25 scale,
26 projection: Transformation::orthographic(size.width, size.height),
27 }
28 }
29
30 pub fn physical_size(&self) -> Size<u32> {
32 self.physical_size
33 }
34
35 pub fn physical_width(&self) -> u32 {
37 self.physical_size.width
38 }
39
40 pub fn physical_height(&self) -> u32 {
42 self.physical_size.height
43 }
44
45 pub fn logical_size(&self) -> Size<f32> {
47 self.logical_size
48 }
49
50 pub fn scale(&self) -> Scale {
52 self.scale
53 }
54
55 pub fn scale_factor(&self) -> f32 {
57 self.scale.total()
58 }
59
60 pub fn projection(&self) -> Transformation {
62 self.projection
63 }
64}