iced_graphics/
viewport.rs
1use crate::core::{Size, Transformation};
2
3#[derive(Debug, Clone)]
5pub struct Viewport {
6 physical_size: Size<u32>,
7 logical_size: Size<f32>,
8 scale_factor: f64,
9 projection: Transformation,
10}
11
12impl Viewport {
13 pub fn with_physical_size(size: Size<u32>, scale_factor: f64) -> Viewport {
16 Viewport {
17 physical_size: size,
18 logical_size: Size::new(
19 (size.width as f64 / scale_factor) as f32,
20 (size.height as f64 / scale_factor) as f32,
21 ),
22 scale_factor,
23 projection: Transformation::orthographic(size.width, size.height),
24 }
25 }
26
27 pub fn physical_size(&self) -> Size<u32> {
29 self.physical_size
30 }
31
32 pub fn physical_width(&self) -> u32 {
34 self.physical_size.width
35 }
36
37 pub fn physical_height(&self) -> u32 {
39 self.physical_size.height
40 }
41
42 pub fn logical_size(&self) -> Size<f32> {
44 self.logical_size
45 }
46
47 pub fn scale_factor(&self) -> f64 {
49 self.scale_factor
50 }
51
52 pub fn projection(&self) -> Transformation {
54 self.projection
55 }
56}