@@ -4,18 +4,24 @@ 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 ,
20
+
16
21
}
17
22
18
23
impl Viewport {
24
+ /// Create a new viewport from a window's physical size and scale factor.
19
25
pub fn new ( physical_width : u32 , physical_height : u32 , scale_factor : f32 ) -> Self {
20
26
Self {
21
27
window_size : ( physical_width, physical_height) ,
@@ -25,31 +31,21 @@ impl Viewport {
25
31
}
26
32
}
27
33
28
- // Total scaling, the product of the zoom and hdpi scale
34
+ /// Total scaling, the product of the zoom and hdpi scale.
29
35
pub fn scale ( & self ) -> f32 {
30
36
self . hidpi_scale * self . zoom
31
37
}
32
- // Total scaling, the product of the zoom and hdpi scale
38
+
39
+ /// Total scaling, the product of the zoom and hdpi scale (as an `f64`).
33
40
pub fn scale_f64 ( & self ) -> f64 {
34
41
self . scale ( ) as f64
35
42
}
36
43
44
+ /// Set the hidi scale.
37
45
pub fn set_hidpi_scale ( & mut self , scale : f32 ) {
38
46
self . hidpi_scale = scale;
39
47
}
40
48
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
49
pub ( crate ) fn make_device ( & self ) -> Device {
54
50
let width = self . window_size . 0 as f32 / self . scale ( ) ;
55
51
let height = self . window_size . 1 as f32 / self . scale ( ) ;
0 commit comments