@@ -4,18 +4,24 @@ use style::{
44 properties:: { style_structs:: Font , ComputedValues } ,
55} ;
66
7+ /// Window viewport.
78#[ derive( Default , Debug , Clone ) ]
89pub struct Viewport {
10+ /// Size of the window.
911 pub window_size : ( u32 , u32 ) ,
1012
11- hidpi_scale : f32 ,
13+ /// Font size.
14+ pub font_size : f32 ,
1215
13- zoom : f32 ,
16+ /// Zoom level.
17+ pub zoom : f32 ,
1418
15- pub font_size : f32 ,
19+ hidpi_scale : f32 ,
20+
1621}
1722
1823impl Viewport {
24+ /// Create a new viewport from a window's physical size and scale factor.
1925 pub fn new ( physical_width : u32 , physical_height : u32 , scale_factor : f32 ) -> Self {
2026 Self {
2127 window_size : ( physical_width, physical_height) ,
@@ -25,31 +31,21 @@ impl Viewport {
2531 }
2632 }
2733
28- // Total scaling, the product of the zoom and hdpi scale
34+ /// Total scaling, the product of the zoom and hdpi scale.
2935 pub fn scale ( & self ) -> f32 {
3036 self . hidpi_scale * self . zoom
3137 }
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`).
3340 pub fn scale_f64 ( & self ) -> f64 {
3441 self . scale ( ) as f64
3542 }
3643
44+ /// Set the hidi scale.
3745 pub fn set_hidpi_scale ( & mut self , scale : f32 ) {
3846 self . hidpi_scale = scale;
3947 }
4048
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-
5349 pub ( crate ) fn make_device ( & self ) -> Device {
5450 let width = self . window_size . 0 as f32 / self . scale ( ) ;
5551 let height = self . window_size . 1 as f32 / self . scale ( ) ;
0 commit comments