Showing
2 changed files
with
72 additions
and
1 deletions
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | - Fix missing smask subtype | 6 | - Fix missing smask subtype |
| 7 | - Add missing final "~>" to Ascii85 encoder | 7 | - Add missing final "~>" to Ascii85 encoder |
| 8 | - Fix typo "horizontalCenter" | 8 | - Fix typo "horizontalCenter" |
| 9 | +- Add OverflowBox | ||
| 9 | 10 | ||
| 10 | ## 3.7.2 | 11 | ## 3.7.2 |
| 11 | 12 |
| @@ -135,6 +135,7 @@ class Transform extends SingleChildWidget { | @@ -135,6 +135,7 @@ class Transform extends SingleChildWidget { | ||
| 135 | this.origin, | 135 | this.origin, |
| 136 | this.alignment, | 136 | this.alignment, |
| 137 | this.adjustLayout = false, | 137 | this.adjustLayout = false, |
| 138 | + this.unconstrained = false, | ||
| 138 | Widget? child, | 139 | Widget? child, |
| 139 | }) : super(child: child); | 140 | }) : super(child: child); |
| 140 | 141 | ||
| @@ -147,6 +148,7 @@ class Transform extends SingleChildWidget { | @@ -147,6 +148,7 @@ class Transform extends SingleChildWidget { | ||
| 147 | Widget? child, | 148 | Widget? child, |
| 148 | }) : transform = Matrix4.rotationZ(angle), | 149 | }) : transform = Matrix4.rotationZ(angle), |
| 149 | adjustLayout = false, | 150 | adjustLayout = false, |
| 151 | + unconstrained = false, | ||
| 150 | super(child: child); | 152 | super(child: child); |
| 151 | 153 | ||
| 152 | /// Creates a widget that transforms its child using a rotation around the | 154 | /// Creates a widget that transforms its child using a rotation around the |
| @@ -154,6 +156,7 @@ class Transform extends SingleChildWidget { | @@ -154,6 +156,7 @@ class Transform extends SingleChildWidget { | ||
| 154 | Transform.rotateBox({ | 156 | Transform.rotateBox({ |
| 155 | required double angle, | 157 | required double angle, |
| 156 | Widget? child, | 158 | Widget? child, |
| 159 | + this.unconstrained = false, | ||
| 157 | }) : transform = Matrix4.rotationZ(angle), | 160 | }) : transform = Matrix4.rotationZ(angle), |
| 158 | adjustLayout = true, | 161 | adjustLayout = true, |
| 159 | alignment = null, | 162 | alignment = null, |
| @@ -168,6 +171,7 @@ class Transform extends SingleChildWidget { | @@ -168,6 +171,7 @@ class Transform extends SingleChildWidget { | ||
| 168 | origin = null, | 171 | origin = null, |
| 169 | alignment = null, | 172 | alignment = null, |
| 170 | adjustLayout = false, | 173 | adjustLayout = false, |
| 174 | + unconstrained = false, | ||
| 171 | super(child: child); | 175 | super(child: child); |
| 172 | 176 | ||
| 173 | /// Creates a widget that scales its child uniformly. | 177 | /// Creates a widget that scales its child uniformly. |
| @@ -178,6 +182,7 @@ class Transform extends SingleChildWidget { | @@ -178,6 +182,7 @@ class Transform extends SingleChildWidget { | ||
| 178 | Widget? child, | 182 | Widget? child, |
| 179 | }) : transform = Matrix4.diagonal3Values(scale, scale, 1), | 183 | }) : transform = Matrix4.diagonal3Values(scale, scale, 1), |
| 180 | adjustLayout = false, | 184 | adjustLayout = false, |
| 185 | + unconstrained = false, | ||
| 181 | super(child: child); | 186 | super(child: child); |
| 182 | 187 | ||
| 183 | /// The matrix to transform the child by during painting. | 188 | /// The matrix to transform the child by during painting. |
| @@ -191,6 +196,8 @@ class Transform extends SingleChildWidget { | @@ -191,6 +196,8 @@ class Transform extends SingleChildWidget { | ||
| 191 | 196 | ||
| 192 | final bool adjustLayout; | 197 | final bool adjustLayout; |
| 193 | 198 | ||
| 199 | + final bool unconstrained; | ||
| 200 | + | ||
| 194 | Matrix4 get _effectiveTransform { | 201 | Matrix4 get _effectiveTransform { |
| 195 | final result = Matrix4.identity(); | 202 | final result = Matrix4.identity(); |
| 196 | if (origin != null) { | 203 | if (origin != null) { |
| @@ -220,7 +227,11 @@ class Transform extends SingleChildWidget { | @@ -220,7 +227,11 @@ class Transform extends SingleChildWidget { | ||
| 220 | } | 227 | } |
| 221 | 228 | ||
| 222 | if (child != null) { | 229 | if (child != null) { |
| 223 | - child!.layout(context, constraints, parentUsesSize: parentUsesSize); | 230 | + child!.layout( |
| 231 | + context, | ||
| 232 | + unconstrained ? const BoxConstraints() : constraints, | ||
| 233 | + parentUsesSize: parentUsesSize, | ||
| 234 | + ); | ||
| 224 | assert(child!.box != null); | 235 | assert(child!.box != null); |
| 225 | 236 | ||
| 226 | final mat = transform; | 237 | final mat = transform; |
| @@ -910,3 +921,62 @@ class VerticalDivider extends StatelessWidget { | @@ -910,3 +921,62 @@ class VerticalDivider extends StatelessWidget { | ||
| 910 | ); | 921 | ); |
| 911 | } | 922 | } |
| 912 | } | 923 | } |
| 924 | + | ||
| 925 | +class OverflowBox extends SingleChildWidget { | ||
| 926 | + /// Creates a widget that lets its child overflow itself. | ||
| 927 | + OverflowBox({ | ||
| 928 | + this.alignment = Alignment.center, | ||
| 929 | + this.minWidth, | ||
| 930 | + this.maxWidth, | ||
| 931 | + this.minHeight, | ||
| 932 | + this.maxHeight, | ||
| 933 | + Widget? child, | ||
| 934 | + }) : super(child: child); | ||
| 935 | + | ||
| 936 | + /// How to align the child. | ||
| 937 | + final Alignment alignment; | ||
| 938 | + | ||
| 939 | + /// The minimum width constraint to give the child. Set this to null (the | ||
| 940 | + /// default) to use the constraint from the parent instead. | ||
| 941 | + final double? minWidth; | ||
| 942 | + | ||
| 943 | + /// The maximum width constraint to give the child. Set this to null (the | ||
| 944 | + /// default) to use the constraint from the parent instead. | ||
| 945 | + final double? maxWidth; | ||
| 946 | + | ||
| 947 | + /// The minimum height constraint to give the child. Set this to null (the | ||
| 948 | + /// default) to use the constraint from the parent instead. | ||
| 949 | + final double? minHeight; | ||
| 950 | + | ||
| 951 | + /// The maximum height constraint to give the child. Set this to null (the | ||
| 952 | + /// default) to use the constraint from the parent instead. | ||
| 953 | + final double? maxHeight; | ||
| 954 | + | ||
| 955 | + BoxConstraints _getInnerConstraints(BoxConstraints constraints) { | ||
| 956 | + return BoxConstraints( | ||
| 957 | + minWidth: minWidth ?? constraints.minWidth, | ||
| 958 | + maxWidth: maxWidth ?? constraints.maxWidth, | ||
| 959 | + minHeight: minHeight ?? constraints.minHeight, | ||
| 960 | + maxHeight: maxHeight ?? constraints.maxHeight, | ||
| 961 | + ); | ||
| 962 | + } | ||
| 963 | + | ||
| 964 | + @override | ||
| 965 | + void layout(Context context, BoxConstraints constraints, | ||
| 966 | + {bool parentUsesSize = false}) { | ||
| 967 | + box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest); | ||
| 968 | + | ||
| 969 | + if (child != null) { | ||
| 970 | + child!.layout(context, _getInnerConstraints(constraints), | ||
| 971 | + parentUsesSize: true); | ||
| 972 | + assert(child!.box != null); | ||
| 973 | + child!.box = alignment.inscribe(child!.box!.size, box!); | ||
| 974 | + } | ||
| 975 | + } | ||
| 976 | + | ||
| 977 | + @override | ||
| 978 | + void paint(Context context) { | ||
| 979 | + super.paint(context); | ||
| 980 | + paintChild(context); | ||
| 981 | + } | ||
| 982 | +} |
-
Please register or login to post a comment