@@ -398,12 +398,27 @@ impl TextureManager {
398
398
/// Requires eyes and a magnifying glass to verify.
399
399
pub fn pixel_test ( ui : & mut Ui ) {
400
400
ui. heading ( "Pixel alignment test" ) ;
401
+ ui. label ( "If anything is blurry, then everything will be blurry, including text." ) ;
402
+ ui. label ( "You might need a magnifying glass to check this test." ) ;
403
+
404
+ if cfg ! ( target_arch = "wasm32" ) {
405
+ ui. label ( "Make sure these test pass even when you zoom in/out and resize the browser." ) ;
406
+ }
407
+
408
+ ui. add_space ( 4.0 ) ;
409
+
410
+ pixel_test_lines ( ui) ;
411
+
412
+ ui. add_space ( 4.0 ) ;
413
+
414
+ pixel_test_squares ( ui) ;
415
+ }
416
+
417
+ fn pixel_test_squares ( ui : & mut Ui ) {
401
418
ui. label ( "The first square should be exactly one physical pixel big." ) ;
402
419
ui. label ( "They should be exactly one physical pixel apart." ) ;
403
420
ui. label ( "Each subsequent square should be one physical pixel larger than the previous." ) ;
404
421
ui. label ( "They should be perfectly aligned to the physical pixel grid." ) ;
405
- ui. label ( "If these squares are blurry, everything will be blurry, including text." ) ;
406
- ui. label ( "You might need a magnifying glass to check this test." ) ;
407
422
408
423
let color = if ui. style ( ) . visuals . dark_mode {
409
424
egui:: Color32 :: WHITE
@@ -412,6 +427,7 @@ pub fn pixel_test(ui: &mut Ui) {
412
427
} ;
413
428
414
429
let pixels_per_point = ui. ctx ( ) . pixels_per_point ( ) ;
430
+
415
431
let num_squares = ( pixels_per_point * 10.0 ) . round ( ) . max ( 10.0 ) as u32 ;
416
432
let size_pixels = vec2 (
417
433
( ( num_squares + 1 ) * ( num_squares + 2 ) / 2 ) as f32 ,
@@ -427,17 +443,58 @@ pub fn pixel_test(ui: &mut Ui) {
427
443
. ceil ( ) ;
428
444
for size in 1 ..=num_squares {
429
445
let rect_points = Rect :: from_min_size (
430
- Pos2 :: new (
431
- cursor_pixel. x / pixels_per_point,
432
- cursor_pixel. y / pixels_per_point,
433
- ) ,
434
- Vec2 :: splat ( size as f32 ) / pixels_per_point,
446
+ Pos2 :: new ( cursor_pixel. x , cursor_pixel. y ) ,
447
+ Vec2 :: splat ( size as f32 ) ,
435
448
) ;
436
- painter. rect_filled ( rect_points, 0.0 , color) ;
449
+ painter. rect_filled ( rect_points / pixels_per_point , 0.0 , color) ;
437
450
cursor_pixel. x += ( 1 + size) as f32 ;
438
451
}
439
452
}
440
453
454
+ fn pixel_test_lines ( ui : & mut Ui ) {
455
+ let pixels_per_point = ui. ctx ( ) . pixels_per_point ( ) ;
456
+ let n = ( 96.0 * pixels_per_point) as usize ;
457
+
458
+ ui. label ( "The lines should be exactly one physical pixel wide, one physical pixel apart." ) ;
459
+ ui. label ( "They should be perfectly white and black." ) ;
460
+
461
+ let hspace_px = pixels_per_point * 4.0 ;
462
+
463
+ let size_px = Vec2 :: new ( 2.0 * n as f32 + hspace_px, n as f32 ) ;
464
+ let size_points = size_px / pixels_per_point + Vec2 :: splat ( 2.0 ) ;
465
+ let ( response, painter) = ui. allocate_painter ( size_points, Sense :: hover ( ) ) ;
466
+
467
+ let mut cursor_px = Pos2 :: new (
468
+ response. rect . min . x * pixels_per_point,
469
+ response. rect . min . y * pixels_per_point,
470
+ )
471
+ . ceil ( ) ;
472
+
473
+ // Vertical stripes:
474
+ for x in 0 ..n / 2 {
475
+ let rect_px = Rect :: from_min_size (
476
+ Pos2 :: new ( cursor_px. x + 2.0 * x as f32 , cursor_px. y ) ,
477
+ Vec2 :: new ( 1.0 , n as f32 ) ,
478
+ ) ;
479
+ painter. rect_filled ( rect_px / pixels_per_point, 0.0 , egui:: Color32 :: WHITE ) ;
480
+ let rect_px = rect_px. translate ( vec2 ( 1.0 , 0.0 ) ) ;
481
+ painter. rect_filled ( rect_px / pixels_per_point, 0.0 , egui:: Color32 :: BLACK ) ;
482
+ }
483
+
484
+ cursor_px. x += n as f32 + hspace_px;
485
+
486
+ // Horizontal stripes:
487
+ for y in 0 ..n / 2 {
488
+ let rect_px = Rect :: from_min_size (
489
+ Pos2 :: new ( cursor_px. x , cursor_px. y + 2.0 * y as f32 ) ,
490
+ Vec2 :: new ( n as f32 , 1.0 ) ,
491
+ ) ;
492
+ painter. rect_filled ( rect_px / pixels_per_point, 0.0 , egui:: Color32 :: WHITE ) ;
493
+ let rect_px = rect_px. translate ( vec2 ( 0.0 , 1.0 ) ) ;
494
+ painter. rect_filled ( rect_px / pixels_per_point, 0.0 , egui:: Color32 :: BLACK ) ;
495
+ }
496
+ }
497
+
441
498
fn blending_and_feathering_test ( ui : & mut Ui ) {
442
499
ui. label ( "The left side shows how lines of different widths look." ) ;
443
500
ui. label ( "The right side tests text rendering at different opacities and sizes." ) ;
0 commit comments