@@ -4,18 +4,23 @@ use style::{
4
4
properties:: { style_structs:: Font , ComputedValues } ,
5
5
} ;
6
6
7
+ /// Window viewport.
7
8
#[ derive( Default , Debug , Clone ) ]
8
9
pub struct Viewport {
10
+ /// Size of the window.
9
11
pub window_size : ( u32 , u32 ) ,
10
12
11
- hidpi_scale : f32 ,
13
+ /// Font size.
14
+ pub font_size : f32 ,
12
15
13
- zoom : f32 ,
16
+ /// Zoom level.
17
+ pub zoom : f32 ,
14
18
15
- pub font_size : f32 ,
19
+ hidpi_scale : f32 ,
16
20
}
17
21
18
22
impl Viewport {
23
+ /// Create a new viewport from a window's physical size and scale factor.
19
24
pub fn new ( physical_width : u32 , physical_height : u32 , scale_factor : f32 ) -> Self {
20
25
Self {
21
26
window_size : ( physical_width, physical_height) ,
@@ -25,31 +30,21 @@ impl Viewport {
25
30
}
26
31
}
27
32
28
- // Total scaling, the product of the zoom and hdpi scale
33
+ /// Total scaling, the product of the zoom and hdpi scale.
29
34
pub fn scale ( & self ) -> f32 {
30
35
self . hidpi_scale * self . zoom
31
36
}
32
- // Total scaling, the product of the zoom and hdpi scale
37
+
38
+ /// Total scaling, the product of the zoom and hdpi scale (as an `f64`).
33
39
pub fn scale_f64 ( & self ) -> f64 {
34
40
self . scale ( ) as f64
35
41
}
36
42
43
+ /// Set the hidi scale.
37
44
pub fn set_hidpi_scale ( & mut self , scale : f32 ) {
38
45
self . hidpi_scale = scale;
39
46
}
40
47
41
- pub fn zoom ( & self ) -> f32 {
42
- self . zoom
43
- }
44
-
45
- pub fn set_zoom ( & mut self , zoom : f32 ) {
46
- self . zoom = zoom;
47
- }
48
-
49
- pub fn zoom_mut ( & mut self ) -> & mut f32 {
50
- & mut self . zoom
51
- }
52
-
53
48
pub ( crate ) fn make_device ( & self ) -> Device {
54
49
let width = self . window_size . 0 as f32 / self . scale ( ) ;
55
50
let height = self . window_size . 1 as f32 / self . scale ( ) ;
0 commit comments