@@ -836,6 +836,160 @@ public void TestSetContentByIndex()
836
836
void assertContentChangeEventWasFired ( ) => AddAssert ( "Content change event was fired" , ( ) => gridContentChangeEventWasFired ) ;
837
837
}
838
838
839
+ [ Test ]
840
+ public void TestPaddingRelativeSingle ( )
841
+ {
842
+ FillBox box = null ;
843
+
844
+ AddStep ( "set content" , ( ) =>
845
+ {
846
+ grid . Content = new [ ] { new Drawable [ ] { box = new FillBox ( ) } , } ;
847
+ grid . RowDimensions = grid . ColumnDimensions = new [ ] { new Dimension ( GridSizeMode . Relative , 1f ) } ;
848
+ } ) ;
849
+
850
+ checkCorrectBoxSize ( new MarginPadding ( 20 ) ) ;
851
+ checkCorrectBoxSize ( new MarginPadding { Horizontal = 20 } ) ;
852
+ checkCorrectBoxSize ( new MarginPadding { Vertical = 20 } ) ;
853
+ checkCorrectBoxSize ( new MarginPadding { Left = 20 } ) ;
854
+ checkCorrectBoxSize ( new MarginPadding { Right = 20 } ) ;
855
+ checkCorrectBoxSize ( new MarginPadding { Top = 20 } ) ;
856
+ checkCorrectBoxSize ( new MarginPadding { Bottom = 20 } ) ;
857
+ return ;
858
+
859
+ void checkCorrectBoxSize ( MarginPadding padding )
860
+ {
861
+ setPadding ( padding ) ;
862
+ AddAssert ( "box size is correct" , ( ) => Precision . AlmostEquals ( grid . DrawSize - padding . Total , box . DrawSize ) ) ;
863
+ }
864
+ }
865
+
866
+ [ Test ]
867
+ public void TestPaddingAutosizeSingle ( )
868
+ {
869
+ FillBox box = null ;
870
+
871
+ AddStep ( "set content" , ( ) =>
872
+ {
873
+ gridParent . RelativeSizeAxes = Axes . None ;
874
+ gridParent . AutoSizeAxes = Axes . Both ;
875
+
876
+ grid . RelativeSizeAxes = Axes . None ;
877
+ grid . AutoSizeAxes = Axes . Both ;
878
+ grid . Content = new [ ] { new Drawable [ ] { box = new FillBox { RelativeSizeAxes = Axes . None , Size = new Vector2 ( 100 ) } } , } ;
879
+ grid . RowDimensions = grid . ColumnDimensions = new [ ] { new Dimension ( GridSizeMode . AutoSize ) } ;
880
+ } ) ;
881
+
882
+ checkCorrectGridSize ( new MarginPadding ( 20 ) ) ;
883
+ checkCorrectGridSize ( new MarginPadding { Horizontal = 20 } ) ;
884
+ checkCorrectGridSize ( new MarginPadding { Vertical = 20 } ) ;
885
+ checkCorrectGridSize ( new MarginPadding { Left = 20 } ) ;
886
+ checkCorrectGridSize ( new MarginPadding { Right = 20 } ) ;
887
+ checkCorrectGridSize ( new MarginPadding { Top = 20 } ) ;
888
+ checkCorrectGridSize ( new MarginPadding { Bottom = 20 } ) ;
889
+ return ;
890
+
891
+ void checkCorrectGridSize ( MarginPadding padding )
892
+ {
893
+ setPadding ( padding ) ;
894
+ AddAssert ( "grid size is correct" , ( ) => Precision . AlmostEquals ( grid . DrawSize , box . DrawSize + padding . Total ) ) ;
895
+ }
896
+ }
897
+
898
+ [ Test ]
899
+ public void TestPaddingAutosizeMultiple ( )
900
+ {
901
+ FillBox [ ] boxes = new FillBox [ 3 ] ;
902
+ const float box_size = 100f ;
903
+
904
+ AddStep ( "set content" , ( ) =>
905
+ {
906
+ gridParent . RelativeSizeAxes = Axes . None ;
907
+ gridParent . AutoSizeAxes = Axes . Both ;
908
+
909
+ grid . RelativeSizeAxes = Axes . None ;
910
+ grid . AutoSizeAxes = Axes . Both ;
911
+ grid . RowDimensions = new [ ] { new Dimension ( GridSizeMode . AutoSize ) } ;
912
+ grid . ColumnDimensions = new [ ]
913
+ {
914
+ new Dimension ( GridSizeMode . AutoSize ) ,
915
+ new Dimension ( GridSizeMode . AutoSize ) ,
916
+ new Dimension ( GridSizeMode . AutoSize )
917
+ } ;
918
+ grid . Content = new [ ]
919
+ {
920
+ new Drawable [ ]
921
+ {
922
+ boxes [ 0 ] = new FillBox
923
+ {
924
+ RelativeSizeAxes = Axes . None ,
925
+ Size = new Vector2 ( box_size )
926
+ } ,
927
+ boxes [ 1 ] = new FillBox
928
+ {
929
+ RelativeSizeAxes = Axes . None ,
930
+ Size = new Vector2 ( box_size )
931
+ } ,
932
+ boxes [ 2 ] = new FillBox
933
+ {
934
+ RelativeSizeAxes = Axes . None ,
935
+ Size = new Vector2 ( box_size )
936
+ }
937
+ }
938
+ } ;
939
+ } ) ;
940
+
941
+ checkCorrectGridSize ( new MarginPadding ( 20 ) ) ;
942
+ checkCorrectGridSize ( new MarginPadding { Horizontal = 20 } ) ;
943
+ checkCorrectGridSize ( new MarginPadding { Vertical = 20 } ) ;
944
+ checkCorrectGridSize ( new MarginPadding { Left = 20 } ) ;
945
+ checkCorrectGridSize ( new MarginPadding { Right = 20 } ) ;
946
+ checkCorrectGridSize ( new MarginPadding { Top = 20 } ) ;
947
+ checkCorrectGridSize ( new MarginPadding { Bottom = 20 } ) ;
948
+ return ;
949
+
950
+ void checkCorrectGridSize ( MarginPadding padding )
951
+ {
952
+ setPadding ( padding ) ;
953
+ AddAssert ( "grid size is correct" , ( ) => Precision . AlmostEquals ( grid . DrawSize , new Vector2 ( box_size * 3 , box_size ) + padding . Total ) ) ;
954
+ }
955
+ }
956
+
957
+ [ TestCase ( false ) ]
958
+ [ TestCase ( true ) ]
959
+ public void TestPaddingRelativeMultiple ( bool row )
960
+ {
961
+ FillBox [ ] boxes = new FillBox [ 3 ] ;
962
+
963
+ setSingleDimensionContent ( ( ) => new [ ]
964
+ {
965
+ new Drawable [ ] { boxes [ 0 ] = new FillBox ( ) , boxes [ 1 ] = new FillBox ( ) , boxes [ 2 ] = new FillBox ( ) }
966
+ } , row : row ) ;
967
+
968
+ checkSizes ( new MarginPadding ( 20 ) ) ;
969
+ checkSizes ( new MarginPadding { Horizontal = 20 } ) ;
970
+ checkSizes ( new MarginPadding { Vertical = 20 } ) ;
971
+ checkSizes ( new MarginPadding { Left = 20 } ) ;
972
+ checkSizes ( new MarginPadding { Right = 20 } ) ;
973
+ checkSizes ( new MarginPadding { Top = 20 } ) ;
974
+ checkSizes ( new MarginPadding { Bottom = 20 } ) ;
975
+ return ;
976
+
977
+ void checkSizes ( MarginPadding padding )
978
+ {
979
+ setPadding ( padding ) ;
980
+
981
+ for ( int i = 0 ; i < 3 ; i ++ )
982
+ {
983
+ int local = i ;
984
+
985
+ if ( row )
986
+ AddAssert ( $ "box { local } has correct size", ( ) => Precision . AlmostEquals ( boxes [ local ] . DrawSize , new Vector2 ( ( grid . DrawWidth - padding . TotalHorizontal ) / 3f , grid . DrawHeight - padding . TotalVertical ) ) ) ;
987
+ else
988
+ AddAssert ( $ "box { local } has correct size", ( ) => Precision . AlmostEquals ( boxes [ local ] . DrawSize , new Vector2 ( grid . DrawWidth - padding . TotalHorizontal , ( grid . DrawHeight - padding . TotalVertical ) / 3f ) ) ) ;
989
+ }
990
+ }
991
+ }
992
+
839
993
/// <summary>
840
994
/// Returns drawable dimension along desired axis.
841
995
/// </summary>
@@ -888,6 +1042,11 @@ private void setSingleDimensionContent(Func<Drawable[][]> contentFunc, Dimension
888
1042
grid . ColumnDimensions = dimensions ;
889
1043
} ) ;
890
1044
1045
+ private void setPadding ( MarginPadding padding ) => AddStep ( $ "set padding { padding . Left } , { padding . Top } , { padding . Right } , { padding . Bottom } ", ( ) =>
1046
+ {
1047
+ grid . Padding = padding ;
1048
+ } ) ;
1049
+
891
1050
private partial class FillBox : Box
892
1051
{
893
1052
public FillBox ( )
0 commit comments