@@ -96,8 +96,8 @@ none =
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99−paragraph =
99+paragraph attrs =
100− Testable.Paragraph
100+ Testable.Paragraph (implicitWidthHeightShrink attrs)
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
@@ -366,7 +366,7 @@ widthHelper maybeMin maybeMax len =
368 \context ->
368 \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
370 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
370 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
@@ -374,7 +374,7 @@ widthHelper maybeMin maybeMax len =
374 parentAvailableWidth =
374 parentAvailableWidth =
375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
377− [ case context.location of
377+ [ case context.parentLayout of
378 Testable.IsNearby _ ->
378 Testable.IsNearby _ ->
379 Testable.true "Nearby Element has fill width"
379 Testable.true "Nearby Element has fill width"
380 ((floor context.parent.bbox.width == floor context.self.bbox.width)
380 ((floor context.parent.bbox.width == floor context.self.bbox.width)
@@ -415,36 +415,110 @@ widthHelper maybeMin maybeMax len =
415 , id = Testable.IsWidth
415 , id = Testable.IsWidth
417 \context ->
417 \context ->
418− let
418+ case context.selfElement of
419− childWidth child =
421+ childWidth child =
420− -- TODO: add margin values to widths
422+ child.bbox.width
426+ |> List.map childWidth
427+ |> List.append (List.map .width context.self.textMetrics)
431+ context.self.bbox.padding.left + context.self.bbox.padding.right
433+ [ expectRoundedEquality
434+ { expected = totalChildren + horizontalPadding
435+ , found = context.self.bbox.width
440+ -- width of row is the sum of all children widths
441+ -- both text elements and others.
421− child.bbox.width
444+ child.bbox.width
423− totalChildren =
446+ totalChildren =
424− context.children
447+ context.children
425− |> List.map childWidth
448+ |> List.map childWidth
449+ |> List.append (List.map .width context.self.textMetrics)
426− |> List.sum
450+ |> List.sum
428− horizontalPadding =
452+ horizontalPadding =
429− context.self.bbox.padding.left + context.self.bbox.padding.right
453+ context.self.bbox.padding.left + context.self.bbox.padding.right
431− spacingValue =
455+ spacingValue =
432− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
456+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
434− if totalChildren == 0 then
458+ [ expectRoundedEquality
435− -- TODO: The issue is that we have a hard time measuring `text` elements
459+ { expected = totalChildren + horizontalPadding + spacingValue
436− -- So if a element has a text child, then it's width isn't going to show up in the system.
460+ , found = context.self.bbox.width
437− [ Testable.Todo "Calculate text size for width-shrink calculation"
461+ }
464+ Testable.Column _ _ ->
465+ -- The width of the column is the width of the widest child.
469+ + context.self.bbox.padding.left
470+ + context.self.bbox.padding.right
476+ + context.self.bbox.padding.left
477+ + context.self.bbox.padding.right
479+ context.self.textMetrics
483+ |> List.map childWidth
484+ |> List.append textChildren
486+ [ expectRoundedEquality
487+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
488+ , found = context.self.bbox.width
492+ Testable.TextColumn _ _ ->
440− else
495+ Testable.Paragraph _ _ ->
441− -- This fails if this element is actually a column
496+ -- This should be the size it's text,
442− -- So we need to capture what this element is in order to do this calculation.
497+ -- unless it takes up all available space, in which case it should wrap.
504+ |> List.map childWidth
505+ |> List.append (List.map .width context.self.textMetrics)
509+ context.self.bbox.padding.left + context.self.bbox.padding.right
443− [ expectRoundedEquality
511+ [ expectRoundedEquality
444− { expected = totalChildren + horizontalPadding + spacingValue
512+ { expected = totalChildren + horizontalPadding
445− , found = context.self.bbox.width
513+ , found = context.self.bbox.width
@@ -535,7 +609,7 @@ heightHelper maybeMin maybeMax len =
535 , id = Testable.IsHeight
609 , id = Testable.IsHeight
537 \context ->
611 \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
539 Testable.true "height fill doesn't apply to above/below elements" True
613 Testable.true "height fill doesn't apply to above/below elements" True
@@ -543,7 +617,7 @@ heightHelper maybeMin maybeMax len =
543 parentAvailableHeight =
617 parentAvailableHeight =
544 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
618 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
546− case context.location of
620+ case context.parentLayout of
547 Testable.IsNearby _ ->
621 Testable.IsNearby _ ->
548 Testable.true "Nearby Element has fill height"
622 Testable.true "Nearby Element has fill height"
549 ((floor context.parent.bbox.height == floor context.self.bbox.height)
623 ((floor context.parent.bbox.height == floor context.self.bbox.height)
@@ -584,36 +658,86 @@ heightHelper maybeMin maybeMax len =
584 , id = Testable.IsHeight
658 , id = Testable.IsHeight
586 \context ->
660 \context ->
661+ case context.selfElement of
588− childHeight child =
664+ childHeight child =
589− -- TODO: add margin values to heights
665+ -- TODO: add margin values to heights
590− child.bbox.height
666+ child.bbox.height
592− totalChildren =
668+ totalChildren =
593− context.children
669+ context.children
594− |> List.map childHeight
670+ |> List.map childHeight
671+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
595− |> List.sum
672+ |> List.sum
597− verticalPadding =
674+ verticalPadding =
598− context.self.bbox.padding.top + context.self.bbox.padding.bottom
675+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
600− spacingValue =
677+ spacingValue =
601− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
678+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
603− if totalChildren == 0 then
680+ [ expectRoundedEquality
604− -- TODO: The issue is that we have a hard time measuring `text` elements
681+ { expected = totalChildren + verticalPadding + spacingValue
605− -- So if a element has a text child, then it's height isn't going to show up in the system.
682+ , found = context.self.bbox.height
606− [ Testable.Todo "Calculate expected height shrink"
683+ }
693+ |> List.map childHeight
694+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
696+ |> Maybe.withDefault 0
699+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
701+ [ expectRoundedEquality
702+ { expected = totalChildren + verticalPadding
703+ , found = context.self.bbox.height
707+ Testable.Column _ _ ->
714+ |> List.map childHeight
715+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
719+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
722+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
724+ [ expectRoundedEquality
725+ { expected = totalChildren + verticalPadding + spacingValue
726+ , found = context.self.bbox.height
730+ Testable.TextColumn _ _ ->
609− else
733+ Testable.Paragraph _ _ ->
610− -- This fails if this element is actually a column
734+ []
611− -- So we need to capture what this element is in order to do this calculation.
735+
612− [ expectRoundedEquality
736+ Testable.Text _ ->
613− { expected = totalChildren + verticalPadding + spacingValue
737+ []
614− , found = context.self.bbox.height
738+
615− }
739+ Testable.Empty ->
@@ -716,11 +840,11 @@ alignLeft =
716 , id = Testable.NoId
840 , id = Testable.NoId
718 \found ->
842 \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
720 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
844 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
723− List.member found.location
847+ List.member found.parentLayout
724 [ Testable.IsNearby Testable.InFront
848 [ Testable.IsNearby Testable.InFront
725 , Testable.IsNearby Testable.Behind
849 , Testable.IsNearby Testable.Behind
726 , Testable.IsNearby Testable.Above
850 , Testable.IsNearby Testable.Above
@@ -739,7 +863,7 @@ alignLeft =
742− case found.location of
866+ case found.parentLayout of
743 Testable.InRow ->
867 Testable.InRow ->
745 siblingsOnLeft =
869 siblingsOnLeft =
@@ -785,7 +909,7 @@ centerX =
785 parentCenter =
909 parentCenter =
786 found.parent.bbox.left + (found.parent.bbox.width / 2)
910 found.parent.bbox.left + (found.parent.bbox.width / 2)
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
789 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
913 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
791 else if List.length found.siblings == 0 then
915 else if List.length found.siblings == 0 then
@@ -796,7 +920,7 @@ centerX =
799− case found.location of
923+ case found.parentLayout of
800 Testable.InRow ->
924 Testable.InRow ->
802 siblingsOnLeft =
926 siblingsOnLeft =
@@ -850,11 +974,11 @@ alignRight =
850 , id = Testable.NoId
974 , id = Testable.NoId
852 \found ->
976 \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
854 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
978 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
857− List.member found.location
981+ List.member found.parentLayout
858 [ Testable.IsNearby Testable.InFront
982 [ Testable.IsNearby Testable.InFront
859 , Testable.IsNearby Testable.Behind
983 , Testable.IsNearby Testable.Behind
860 , Testable.IsNearby Testable.Above
984 , Testable.IsNearby Testable.Above
@@ -875,7 +999,7 @@ alignRight =
878− case found.location of
1002+ case found.parentLayout of
879 Testable.InRow ->
1003 Testable.InRow ->
881 siblingsOnRight =
1005 siblingsOnRight =
@@ -913,11 +1037,11 @@ alignTop =
913 , id = Testable.NoId
1037 , id = Testable.NoId
914 , test =
1038 , test =
915 \found ->
1039 \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
917 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
1041 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
920− List.member found.location
1044+ List.member found.parentLayout
921 [ Testable.IsNearby Testable.InFront
1045 [ Testable.IsNearby Testable.InFront
922 , Testable.IsNearby Testable.Behind
1046 , Testable.IsNearby Testable.Behind
923 , Testable.IsNearby Testable.OnRight
1047 , Testable.IsNearby Testable.OnRight
@@ -938,7 +1062,7 @@ alignTop =
941− case found.location of
1065+ case found.parentLayout of
942 Testable.InColumn ->
1066 Testable.InColumn ->
944 siblingsAbove =
1068 siblingsAbove =
@@ -976,11 +1100,11 @@ alignBottom =
976 , id = Testable.NoId
1100 , id = Testable.NoId
977 , test =
1101 , test =
978 \found ->
1102 \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
980 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
1104 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
983− List.member found.location
1107+ List.member found.parentLayout
984 [ Testable.IsNearby Testable.InFront
1108 [ Testable.IsNearby Testable.InFront
985 , Testable.IsNearby Testable.Behind
1109 , Testable.IsNearby Testable.Behind
986 , Testable.IsNearby Testable.OnRight
1110 , Testable.IsNearby Testable.OnRight
@@ -1001,7 +1125,7 @@ alignBottom =
1004− case found.location of
1128+ case found.parentLayout of
1005 Testable.InColumn ->
1129 Testable.InColumn ->
1007 siblingsBelow =
1131 siblingsBelow =
@@ -1058,7 +1182,7 @@ centerY =
1058 parentCenter =
1182 parentCenter =
1059 found.parent.bbox.top + (found.parent.bbox.height / 2)
1183 found.parent.bbox.top + (found.parent.bbox.height / 2)
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
1062 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1186 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1064 else if List.length found.siblings == 0 then
1188 else if List.length found.siblings == 0 then
@@ -1069,7 +1193,7 @@ centerY =
1072− case found.location of
1196+ case found.parentLayout of
1073 Testable.InColumn ->
1197 Testable.InColumn ->
1075 siblingsOnTop =
1199 siblingsOnTop =