@@ -96,8 +96,8 @@ none =
9696
9797
9898paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99−paragraph =
100− Testable.Paragraph
99+paragraph attrs =
100+ Testable.Paragraph (implicitWidthHeightShrink attrs)
101101
102102
103103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
@@ -366,7 +366,7 @@ widthHelper maybeMin maybeMax len =
366366 )
367367 , test =
368368 \context ->
369− if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
369+ if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
370370 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
371371
372372 else
@@ -374,7 +374,7 @@ widthHelper maybeMin maybeMax len =
374374 parentAvailableWidth =
375375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
376376 in
377− [ case context.location of
377+ [ case context.parentLayout of
378378 Testable.IsNearby _ ->
379379 Testable.true "Nearby Element has fill width"
380380 ((floor context.parent.bbox.width == floor context.self.bbox.width)
@@ -415,36 +415,110 @@ widthHelper maybeMin maybeMax len =
415415 , id = Testable.IsWidth
416416 , test =
417417 \context ->
418− let
419− childWidth child =
420− -- TODO: add margin values to widths
421− child.bbox.width
422−
423− totalChildren =
424− context.children
425− |> List.map childWidth
426− |> List.sum
427−
428− horizontalPadding =
429− context.self.bbox.padding.left + context.self.bbox.padding.right
430−
431− spacingValue =
432− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
433− in
434− if totalChildren == 0 then
435− -- TODO: The issue is that we have a hard time measuring `text` elements
436− -- So if a element has a text child, then it's width isn't going to show up in the system.
437− [ Testable.Todo "Calculate text size for width-shrink calculation"
438− ]
418+ case context.selfElement of
419+ Testable.El _ _ ->
420+ let
421+ childWidth child =
422+ child.bbox.width
423+
424+ totalChildren =
425+ context.children
426+ |> List.map childWidth
427+ |> List.append (List.map .width context.self.textMetrics)
428+ |> List.sum
429+
430+ horizontalPadding =
431+ context.self.bbox.padding.left + context.self.bbox.padding.right
432+ in
433+ [ expectRoundedEquality
434+ { expected = totalChildren + horizontalPadding
435+ , found = context.self.bbox.width
436+ }
437+ ]
438+
439+ Testable.Row _ _ ->
440+ -- width of row is the sum of all children widths
441+ -- both text elements and others.
442+ let
443+ childWidth child =
444+ child.bbox.width
445+
446+ totalChildren =
447+ context.children
448+ |> List.map childWidth
449+ |> List.append (List.map .width context.self.textMetrics)
450+ |> List.sum
451+
452+ horizontalPadding =
453+ context.self.bbox.padding.left + context.self.bbox.padding.right
454+
455+ spacingValue =
456+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
457+ in
458+ [ expectRoundedEquality
459+ { expected = totalChildren + horizontalPadding + spacingValue
460+ , found = context.self.bbox.width
461+ }
462+ ]
463+
464+ Testable.Column _ _ ->
465+ -- The width of the column is the width of the widest child.
466+ let
467+ childWidth child =
468+ child.bbox.width
469+ + context.self.bbox.padding.left
470+ + context.self.bbox.padding.right
471+
472+ textChildren =
473+ List.map
474+ (\txt ->
475+ txt.width
476+ + context.self.bbox.padding.left
477+ + context.self.bbox.padding.right
478+ )
479+ context.self.textMetrics
480+
481+ allChildren =
482+ context.children
483+ |> List.map childWidth
484+ |> List.append textChildren
485+ in
486+ [ expectRoundedEquality
487+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
488+ , found = context.self.bbox.width
489+ }
490+ ]
491+
492+ Testable.TextColumn _ _ ->
493+ []
439494
440− else
441− -- This fails if this element is actually a column
442− -- So we need to capture what this element is in order to do this calculation.
443− [ expectRoundedEquality
444− { expected = totalChildren + horizontalPadding + spacingValue
445− , found = context.self.bbox.width
446− }
447− ]
495+ Testable.Paragraph _ _ ->
496+ -- This should be the size it's text,
497+ -- unless it takes up all available space, in which case it should wrap.
498+ let
499+ childWidth child =
500+ child.bbox.width
501+
502+ totalChildren =
503+ context.children
504+ |> List.map childWidth
505+ |> List.append (List.map .width context.self.textMetrics)
506+ |> List.sum
507+
508+ horizontalPadding =
509+ context.self.bbox.padding.left + context.self.bbox.padding.right
510+ in
511+ [ expectRoundedEquality
512+ { expected = totalChildren + horizontalPadding
513+ , found = context.self.bbox.width
514+ }
515+ ]
516+
517+ Testable.Text _ ->
518+ []
519+
520+ Testable.Empty ->
521+ []
448522 }
449523
450524
@@ -535,7 +609,7 @@ heightHelper maybeMin maybeMax len =
535609 , id = Testable.IsHeight
536610 , test =
537611 \context ->
538− [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
612+ [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
539613 Testable.true "height fill doesn't apply to above/below elements" True
540614
541615 else
@@ -543,7 +617,7 @@ heightHelper maybeMin maybeMax len =
543617 parentAvailableHeight =
544618 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
545619 in
546− case context.location of
620+ case context.parentLayout of
547621 Testable.IsNearby _ ->
548622 Testable.true "Nearby Element has fill height"
549623 ((floor context.parent.bbox.height == floor context.self.bbox.height)
@@ -584,36 +658,86 @@ heightHelper maybeMin maybeMax len =
584658 , id = Testable.IsHeight
585659 , test =
586660 \context ->
587− let
588− childHeight child =
589− -- TODO: add margin values to heights
590− child.bbox.height
591−
592− totalChildren =
593− context.children
594− |> List.map childHeight
595− |> List.sum
596−
597− verticalPadding =
598− context.self.bbox.padding.top + context.self.bbox.padding.bottom
599−
600− spacingValue =
601− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
602− in
603− if totalChildren == 0 then
604− -- TODO: The issue is that we have a hard time measuring `text` elements
605− -- So if a element has a text child, then it's height isn't going to show up in the system.
606− [ Testable.Todo "Calculate expected height shrink"
607− ]
661+ case context.selfElement of
662+ Testable.El _ _ ->
663+ let
664+ childHeight child =
665+ -- TODO: add margin values to heights
666+ child.bbox.height
667+
668+ totalChildren =
669+ context.children
670+ |> List.map childHeight
671+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
672+ |> List.sum
673+
674+ verticalPadding =
675+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
676+
677+ spacingValue =
678+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
679+ in
680+ [ expectRoundedEquality
681+ { expected = totalChildren + verticalPadding + spacingValue
682+ , found = context.self.bbox.height
683+ }
684+ ]
685+
686+ Testable.Row _ _ ->
687+ let
688+ childHeight child =
689+ child.bbox.height
690+
691+ totalChildren =
692+ context.children
693+ |> List.map childHeight
694+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
695+ |> List.maximum
696+ |> Maybe.withDefault 0
697+
698+ verticalPadding =
699+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
700+ in
701+ [ expectRoundedEquality
702+ { expected = totalChildren + verticalPadding
703+ , found = context.self.bbox.height
704+ }
705+ ]
706+
707+ Testable.Column _ _ ->
708+ let
709+ childHeight child =
710+ child.bbox.height
711+
712+ totalChildren =
713+ context.children
714+ |> List.map childHeight
715+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
716+ |> List.sum
717+
718+ verticalPadding =
719+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
720+
721+ spacingValue =
722+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
723+ in
724+ [ expectRoundedEquality
725+ { expected = totalChildren + verticalPadding + spacingValue
726+ , found = context.self.bbox.height
727+ }
728+ ]
729+
730+ Testable.TextColumn _ _ ->
731+ []
608732
609− else
610− -- This fails if this element is actually a column
611− -- So we need to capture what this element is in order to do this calculation.
612− [ expectRoundedEquality
613− { expected = totalChildren + verticalPadding + spacingValue
614− , found = context.self.bbox.height
615− }
616− ]
733+ Testable.Paragraph _ _ ->
734+ []
735+
736+ Testable.Text _ ->
737+ []
738+
739+ Testable.Empty ->
740+ []
617741 }
618742
619743
@@ -716,11 +840,11 @@ alignLeft =
716840 , id = Testable.NoId
717841 , test =
718842 \found ->
719− [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
843+ [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
720844 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
721845
722846 else if
723− List.member found.location
847+ List.member found.parentLayout
724848 [ Testable.IsNearby Testable.InFront
725849 , Testable.IsNearby Testable.Behind
726850 , Testable.IsNearby Testable.Above
@@ -739,7 +863,7 @@ alignLeft =
739863 }
740864
741865 else
742− case found.location of
866+ case found.parentLayout of
743867 Testable.InRow ->
744868 let
745869 siblingsOnLeft =
@@ -785,7 +909,7 @@ centerX =
785909 parentCenter =
786910 found.parent.bbox.left + (found.parent.bbox.width / 2)
787911 in
788− if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
912+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
789913 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
790914
791915 else if List.length found.siblings == 0 then
@@ -796,7 +920,7 @@ centerX =
796920 ]
797921
798922 else
799− case found.location of
923+ case found.parentLayout of
800924 Testable.InRow ->
801925 let
802926 siblingsOnLeft =
@@ -850,11 +974,11 @@ alignRight =
850974 , id = Testable.NoId
851975 , test =
852976 \found ->
853− if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
977+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
854978 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
855979
856980 else if
857− List.member found.location
981+ List.member found.parentLayout
858982 [ Testable.IsNearby Testable.InFront
859983 , Testable.IsNearby Testable.Behind
860984 , Testable.IsNearby Testable.Above
@@ -875,7 +999,7 @@ alignRight =
875999 ]
8761000
8771001 else
878− case found.location of
1002+ case found.parentLayout of
8791003 Testable.InRow ->
8801004 let
8811005 siblingsOnRight =
@@ -913,11 +1037,11 @@ alignTop =
9131037 , id = Testable.NoId
9141038 , test =
9151039 \found ->
916− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1040+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
9171041 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
9181042
9191043 else if
920− List.member found.location
1044+ List.member found.parentLayout
9211045 [ Testable.IsNearby Testable.InFront
9221046 , Testable.IsNearby Testable.Behind
9231047 , Testable.IsNearby Testable.OnRight
@@ -938,7 +1062,7 @@ alignTop =
9381062 ]
9391063
9401064 else
941− case found.location of
1065+ case found.parentLayout of
9421066 Testable.InColumn ->
9431067 let
9441068 siblingsAbove =
@@ -976,11 +1100,11 @@ alignBottom =
9761100 , id = Testable.NoId
9771101 , test =
9781102 \found ->
979− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1103+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
9801104 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
9811105
9821106 else if
983− List.member found.location
1107+ List.member found.parentLayout
9841108 [ Testable.IsNearby Testable.InFront
9851109 , Testable.IsNearby Testable.Behind
9861110 , Testable.IsNearby Testable.OnRight
@@ -1001,7 +1125,7 @@ alignBottom =
10011125 ]
10021126
10031127 else
1004− case found.location of
1128+ case found.parentLayout of
10051129 Testable.InColumn ->
10061130 let
10071131 siblingsBelow =
@@ -1058,7 +1182,7 @@ centerY =
10581182 parentCenter =
10591183 found.parent.bbox.top + (found.parent.bbox.height / 2)
10601184 in
1061− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1185+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
10621186 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
10631187
10641188 else if List.length found.siblings == 0 then
@@ -1069,7 +1193,7 @@ centerY =
10691193 ]
10701194
10711195 else
1072− case found.location of
1196+ case found.parentLayout of
10731197 Testable.InColumn ->
10741198 let
10751199 siblingsOnTop =