@@ -378,8 +378,7 @@ mod tests {
378378 std:: fs:: write ( expected_file_path ( name) , got) . unwrap ( ) ;
379379 }
380380
381- #[ test]
382- fn layout ( ) {
381+ fn draw_layout ( layout_config : LayoutConfig ) -> Pixmap {
383382 let mut pixmap = Pixmap :: new ( 400 , 400 ) . unwrap ( ) ;
384383 pixmap. fill ( Color :: WHITE ) ;
385384
@@ -393,20 +392,15 @@ mod tests {
393392 None ,
394393 ) ;
395394
396- let mut layout = PartLayout :: calc ( LayoutConfig {
397- width : 200 ,
398- height : 200 ,
399- hide_titlebar : false ,
400- hide_border : false ,
401- hide_edges : false ,
402- } ) ;
395+ let layout = PartLayout :: calc ( layout_config) ;
403396
404- for ( part_idx, PartLayout { surface_rect, .. } ) in layout. iter_mut ( ) . enumerate ( ) {
397+ for ( part_idx, PartLayout { surface_rect, .. } ) in layout. iter ( ) . enumerate ( ) {
405398 let color = match part_idx {
406399 PartId :: TOP => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
407400 PartId :: LEFT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
408401 PartId :: RIGHT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
409402 PartId :: BOTTOM => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
403+ PartId :: HEADER if layout_config. hide_titlebar => continue ,
410404 PartId :: HEADER => Color :: from_rgba8 ( 255 , 255 , 0 , 255 ) ,
411405 _ => unreachable ! ( ) ,
412406 } ;
@@ -428,115 +422,58 @@ mod tests {
428422 ) ;
429423 }
430424
425+ pixmap
426+ }
427+
428+ #[ test]
429+ fn layout ( ) {
430+ let pixmap = draw_layout ( LayoutConfig {
431+ width : 200 ,
432+ height : 200 ,
433+ hide_titlebar : false ,
434+ hide_border : false ,
435+ hide_edges : false ,
436+ } ) ;
431437 let got = pixmap. encode_png ( ) . unwrap ( ) ;
432438 png_check ( "layout" , & got) ;
433439 }
434440
435441 #[ test]
436442 fn layout_no_titlebar ( ) {
437- let mut pixmap = Pixmap :: new ( 400 , 400 ) . unwrap ( ) ;
438- pixmap. fill ( Color :: WHITE ) ;
439-
440- pixmap. fill_rect (
441- tiny_skia:: Rect :: from_xywh ( 100.0 , 100.0 , 200.0 , 200.0 ) . unwrap ( ) ,
442- & Paint {
443- shader : Shader :: SolidColor ( Color :: BLACK ) ,
444- ..Default :: default ( )
445- } ,
446- Transform :: identity ( ) ,
447- None ,
448- ) ;
449-
450- let mut layout = PartLayout :: calc ( LayoutConfig {
443+ let pixmap = draw_layout ( LayoutConfig {
451444 width : 200 ,
452445 height : 200 ,
453446 hide_titlebar : true ,
454447 hide_border : false ,
455448 hide_edges : false ,
456449 } ) ;
457-
458- for ( part_idx, PartLayout { surface_rect, .. } ) in layout. iter_mut ( ) . enumerate ( ) {
459- let color = match part_idx {
460- PartId :: TOP => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
461- PartId :: LEFT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
462- PartId :: RIGHT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
463- PartId :: BOTTOM => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
464- PartId :: HEADER => continue ,
465- _ => unreachable ! ( ) ,
466- } ;
467-
468- pixmap. fill_rect (
469- tiny_skia:: Rect :: from_xywh (
470- surface_rect. x as f32 + 100.0 ,
471- surface_rect. y as f32 + 100.0 ,
472- surface_rect. width as f32 ,
473- surface_rect. height as f32 ,
474- )
475- . unwrap ( ) ,
476- & Paint {
477- shader : Shader :: SolidColor ( color) ,
478- ..Default :: default ( )
479- } ,
480- Transform :: identity ( ) ,
481- None ,
482- ) ;
483- }
484-
485450 let got = pixmap. encode_png ( ) . unwrap ( ) ;
486451 png_check ( "layout-no-titlebar" , & got) ;
487452 }
488453
489454 #[ test]
490455 fn layout_no_border ( ) {
491- let mut pixmap = Pixmap :: new ( 400 , 400 ) . unwrap ( ) ;
492- pixmap. fill ( Color :: WHITE ) ;
493-
494- pixmap. fill_rect (
495- tiny_skia:: Rect :: from_xywh ( 100.0 , 100.0 , 200.0 , 200.0 ) . unwrap ( ) ,
496- & Paint {
497- shader : Shader :: SolidColor ( Color :: BLACK ) ,
498- ..Default :: default ( )
499- } ,
500- Transform :: identity ( ) ,
501- None ,
502- ) ;
503-
504- let mut layout = PartLayout :: calc ( LayoutConfig {
456+ let pixmap = draw_layout ( LayoutConfig {
505457 width : 200 ,
506458 height : 200 ,
507459 hide_titlebar : false ,
508460 hide_border : true ,
509461 hide_edges : false ,
510462 } ) ;
511-
512- for ( part_idx, PartLayout { surface_rect, .. } ) in layout. iter_mut ( ) . enumerate ( ) {
513- let color = match part_idx {
514- PartId :: TOP => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
515- PartId :: LEFT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
516- PartId :: RIGHT => Color :: from_rgba8 ( 255 , 0 , 0 , 255 ) ,
517- PartId :: BOTTOM => Color :: from_rgba8 ( 0 , 0 , 255 , 255 ) ,
518- PartId :: HEADER => Color :: from_rgba8 ( 255 , 255 , 0 , 255 ) ,
519- _ => unreachable ! ( ) ,
520- } ;
521-
522- pixmap. fill_rect (
523- tiny_skia:: Rect :: from_xywh (
524- surface_rect. x as f32 + 100.0 ,
525- surface_rect. y as f32 + 100.0 ,
526- surface_rect. width as f32 ,
527- surface_rect. height as f32 ,
528- )
529- . unwrap ( ) ,
530- & Paint {
531- shader : Shader :: SolidColor ( color) ,
532- ..Default :: default ( )
533- } ,
534- Transform :: identity ( ) ,
535- None ,
536- ) ;
537- }
538-
539463 let got = pixmap. encode_png ( ) . unwrap ( ) ;
540464 png_check ( "layout-no-border" , & got) ;
541465 }
466+
467+ #[ test]
468+ fn layout_no_titlebar_and_border ( ) {
469+ let pixmap = draw_layout ( LayoutConfig {
470+ width : 200 ,
471+ height : 200 ,
472+ hide_titlebar : true ,
473+ hide_border : true ,
474+ hide_edges : false ,
475+ } ) ;
476+ let got = pixmap. encode_png ( ) . unwrap ( ) ;
477+ png_check ( "layout-no-titlebar-and-border" , & got) ;
478+ }
542479}
0 commit comments