Commit 3f2008b 1 parent 2cbea02 commit 3f2008b Copy full SHA for 3f2008b
File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -135,16 +135,29 @@ pub fn resize_canvas_to_screen_size(canvas_id: &str) -> Option<()> {
135
135
let canvas_size_pixels = canvas_size_pixels. min ( max_size_pixels) ;
136
136
let canvas_size_points = canvas_size_pixels / pixels_per_point;
137
137
138
+ // Make sure that the height and width are always even numbers.
139
+ // otherwise, the page renders blurry on some platforms.
140
+ // See https://github.com/emilk/egui/issues/103
141
+ fn round_to_even ( v : f32 ) -> f32 {
142
+ ( v / 2.0 ) . round ( ) * 2.0
143
+ }
144
+
138
145
canvas
139
146
. style ( )
140
- . set_property ( "width" , & format ! ( "{}px" , canvas_size_points. x) )
147
+ . set_property (
148
+ "width" ,
149
+ & format ! ( "{}px" , round_to_even( canvas_size_points. x) ) ,
150
+ )
141
151
. ok ( ) ?;
142
152
canvas
143
153
. style ( )
144
- . set_property ( "height" , & format ! ( "{}px" , canvas_size_points. y) )
154
+ . set_property (
155
+ "height" ,
156
+ & format ! ( "{}px" , round_to_even( canvas_size_points. y) ) ,
157
+ )
145
158
. ok ( ) ?;
146
- canvas. set_width ( canvas_size_pixels. x . round ( ) as u32 ) ;
147
- canvas. set_height ( canvas_size_pixels. y . round ( ) as u32 ) ;
159
+ canvas. set_width ( round_to_even ( canvas_size_pixels. x ) as u32 ) ;
160
+ canvas. set_height ( round_to_even ( canvas_size_pixels. y ) as u32 ) ;
148
161
149
162
Some ( ( ) )
150
163
}
You can’t perform that action at this time.
0 commit comments