-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcore.dart
More file actions
4104 lines (3655 loc) · 128 KB
/
Copy pathcore.dart
File metadata and controls
4104 lines (3655 loc) · 128 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import 'dart:collection';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'auxiliary.dart';
/// A super powerful Stack, build flexible layouts with constraints.
/// Similar to ConstraintLayout for Android and AutoLayout for iOS.
/// But the code implementation is much more efficient, it has O(n)
/// layout time complexity and no linear equation solving is required.
///
/// It is a layout and a more modern general layout framework.
///
/// No matter how complex the layout is and how deep the constraints are
/// it has almost the same performance as a single Flex or Stack.
/// When facing complex layouts, it provides better performance, flexibility
/// and a very flat code hierarchy than Flex and Stack. Say no to 'nested hell'.
///
/// Flutter ConstraintLayout has extremely high layout performance.
/// It does not require linear equations to solve. At any time, each
/// child element will only be laid out once. When its own width or
/// height is set to wrapContent, some child elements may calculate
/// the offset twice.
///
/// ConstraintLayout itself can be arbitrarily nested without performance
/// issues, each child element in the render tree is only laid out once, and
/// the time complexity is O(n) instead of O(2n) or worse.
///
/// Warning: For layout performance considerations, constraints are always
/// one-way, and there should be no two child elements directly or indirectly
/// restrain each other(for example, the right side of A is constrained to the
/// left side of B, and the left side of B is in turn constrained to A right). Each
/// constraint should describe exactly where the child elements are located. Although
/// constraints can only be one-way, you can still better handle things that were
/// previously (Android ConstraintLayout) two-way constraints, such as
/// chains(not yet supported, please use with Flex).
///
/// author: hackware
/// home page: https:///github.com/hackware1993
/// email: hackware1993@gmail.com
class ConstraintLayout extends MultiChildRenderObjectWidget {
/// Constraints can be separated from widgets
final List<ConstraintDefine>? childConstraints;
/// It will display the time-consuming of constraint calculation, layout, and drawing
final bool showLayoutPerformanceOverlay;
/// Guideline and Barrier will be displayed
final bool showHelperWidgets;
/// Will show the click area of each child element
final bool showClickArea;
/// Will show the z-index of each child element
final bool showZIndex;
/// Will show the constraint depth (layout priority) of each child element
final bool showChildDepth;
final bool debugPrintConstraints;
// fixed size、matchParent、wrapContent
final double width;
final double height;
/// When size is non-null, both width and height are set to size
final double? size;
/// Every frame, ConstraintLayout compares the parameters and decides the following things:
/// 1. Does the constraint need to be recalculated?
/// 2. Does it need to be relayout?
/// 3. Does it need to be redrawn?
/// 4. Do you need to rearrange the drawing order?
/// 5. Do you need to rearrange the order of event distribution?
///These comparisons will not be a performance bottleneck, but will increase CPU usage. If you know
///enough about the internals of ConstraintLayout, you can use ConstraintLayoutController to manually trigger
///these operations to stop parameter comparison.
final ConstraintLayoutController? controller;
final bool? rtl;
ConstraintLayout({
Key? key,
this.childConstraints,
List<Widget>? children,
this.showLayoutPerformanceOverlay = false,
this.showHelperWidgets = false,
this.showClickArea = false,
this.showZIndex = false,
this.showChildDepth = false,
this.debugPrintConstraints = false,
this.width = matchParent,
this.height = matchParent,
this.size,
this.controller,
this.rtl,
}) : super(
key: key,
children: children ?? [],
);
@override
RenderObject createRenderObject(BuildContext context) {
assert(width >= 0 || width == matchParent || width == wrapContent);
assert(height >= 0 || height == matchParent || height == wrapContent);
assert(size == null ||
(size! >= 0 || size == matchParent || size == wrapContent));
double selfWidth = width;
double selfHeight = height;
if (size != null) {
selfWidth = size!;
selfHeight = size!;
}
return _ConstraintRenderBox()
.._rtl = rtl ?? Directionality.of(context) == TextDirection.rtl
..childConstraints = childConstraints
.._showLayoutPerformanceOverlay = showLayoutPerformanceOverlay
.._showHelperWidgets = showHelperWidgets
.._showClickArea = showClickArea
.._showZIndex = showZIndex
.._showChildDepth = showChildDepth
.._debugPrintConstraints = debugPrintConstraints
.._width = selfWidth
.._height = selfHeight
.._controller = controller?._copy();
}
@override
void updateRenderObject(
BuildContext context,
covariant RenderObject renderObject,
) {
assert(width >= 0 || width == matchParent || width == wrapContent);
assert(height >= 0 || height == matchParent || height == wrapContent);
assert(size == null ||
(size! >= 0 || size == matchParent || size == wrapContent));
double selfWidth = width;
double selfHeight = height;
if (size != null) {
selfWidth = size!;
selfHeight = size!;
}
(renderObject as _ConstraintRenderBox)
..rtl = rtl ?? Directionality.of(context) == TextDirection.rtl
..childConstraints = childConstraints
..showLayoutPerformanceOverlay = showLayoutPerformanceOverlay
..showHelperWidgets = showHelperWidgets
..showClickArea = showClickArea
..showZIndex = showZIndex
..showChildDepth = showChildDepth
..debugPrintConstraints = debugPrintConstraints
..width = selfWidth
..height = selfHeight
..controller = controller?._copy();
}
}
/// Wrapper constraints design for simplicity of use, it will eventually convert to base constraints.
const Object _wrapperConstraint = Object();
const Object _baseConstraint = Object();
final ConstraintId parent = ConstraintId('parent');
const double matchConstraint = -3.1415926;
const double matchParent = -2.7182818;
const double wrapContent = -0.6180339;
const CLVisibility visible = CLVisibility.visible;
const CLVisibility gone = CLVisibility.gone;
const CLVisibility invisible = CLVisibility.invisible;
enum CLVisibility {
visible,
gone,
invisible,
}
enum BarrierDirection {
left,
top,
right,
bottom,
}
/// For percentage layout
enum PercentageAnchor {
/// Based on the size of the constraint
constraint,
/// Based on the size of the parent
parent,
}
/// Each child element can be set with an id so that they can be referenced
/// by other child elements. If not set, other child elements can be referenced
/// by relative id. But once an id is defined, it cannot be referenced using
/// a relative id.
class ConstraintId {
/// Uniqueness must be guaranteed
final String id;
/// To simplify the setting of margins
/// margin can be negative
double? _leftMargin;
double? _topMargin;
double? _rightMargin;
double? _bottomMargin;
double? _leftGoneMargin;
double? _topGoneMargin;
double? _rightGoneMargin;
double? _bottomGoneMargin;
/// Speed up constraint calculation
ConstrainedNode? _contextCacheNode;
int? _contextHash;
ConstraintId(this.id);
@protected
ConstraintId _copy() {
return ConstraintId(id);
}
bool _isMarginSet() {
return _leftMargin != null ||
_topMargin != null ||
_rightMargin != null ||
_bottomMargin != null ||
_leftGoneMargin != null ||
_topGoneMargin != null ||
_rightGoneMargin != null ||
_bottomGoneMargin != null;
}
ConstraintId leftMargin(double margin) {
if (_isMarginSet()) {
_leftMargin = margin;
return this;
} else {
return _copy().._leftMargin = margin;
}
}
ConstraintId topMargin(double margin) {
if (_isMarginSet()) {
_topMargin = margin;
return this;
} else {
return _copy().._topMargin = margin;
}
}
ConstraintId rightMargin(double margin) {
if (_isMarginSet()) {
_rightMargin = margin;
return this;
} else {
return _copy().._rightMargin = margin;
}
}
ConstraintId bottomMargin(double margin) {
if (_isMarginSet()) {
_bottomMargin = margin;
return this;
} else {
return _copy().._bottomMargin = margin;
}
}
ConstraintId leftGoneMargin(double margin) {
if (_isMarginSet()) {
_leftGoneMargin = margin;
return this;
} else {
return _copy().._leftGoneMargin = margin;
}
}
ConstraintId topGoneMargin(double margin) {
if (_isMarginSet()) {
_topGoneMargin = margin;
return this;
} else {
return _copy().._topGoneMargin = margin;
}
}
ConstraintId rightGoneMargin(double margin) {
if (_isMarginSet()) {
_rightGoneMargin = margin;
return this;
} else {
return _copy().._rightGoneMargin = margin;
}
}
ConstraintId bottomGoneMargin(double margin) {
if (_isMarginSet()) {
_bottomGoneMargin = margin;
return this;
} else {
return _copy().._bottomGoneMargin = margin;
}
}
ConstrainedNode? _getCacheNode(int hash) {
if (_contextHash == hash) {
return _contextCacheNode!;
}
return null;
}
void _setCacheNode(int hash, ConstrainedNode node) {
_contextHash = hash;
_contextCacheNode = node;
}
late final ConstraintAlign left =
ConstraintAlign(this, ConstraintAlignType.left)
.._margin = _leftMargin
.._goneMargin = _leftGoneMargin;
late final ConstraintAlign top =
ConstraintAlign(this, ConstraintAlignType.top)
.._margin = _topMargin
.._goneMargin = _topGoneMargin;
late final ConstraintAlign right =
ConstraintAlign(this, ConstraintAlignType.right)
.._margin = _rightMargin
.._goneMargin = _rightGoneMargin;
late final ConstraintAlign bottom =
ConstraintAlign(this, ConstraintAlignType.bottom)
.._margin = _bottomMargin
.._goneMargin = _bottomGoneMargin;
late final ConstraintAlign baseline =
ConstraintAlign(this, ConstraintAlignType.baseline)
.._margin = _bottomMargin
.._goneMargin = _bottomGoneMargin;
late final ConstraintAlign _leftReverse =
ConstraintAlign(this, ConstraintAlignType.left)
.._margin = _rightMargin
.._goneMargin = _rightGoneMargin;
late final ConstraintAlign _topReverse =
ConstraintAlign(this, ConstraintAlignType.top)
.._margin = _bottomMargin
.._goneMargin = _bottomGoneMargin;
late final ConstraintAlign _rightReverse =
ConstraintAlign(this, ConstraintAlignType.right)
.._margin = _leftMargin
.._goneMargin = _leftGoneMargin;
late final ConstraintAlign _bottomReverse =
ConstraintAlign(this, ConstraintAlignType.bottom)
.._margin = _topMargin
.._goneMargin = _topGoneMargin;
late final ConstraintAlign center =
ConstraintAlign(this, ConstraintAlignType.center);
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other is! ConstraintId) {
return false;
}
if (other.runtimeType != runtimeType) {
return false;
}
return (other).id == id;
}
@override
int get hashCode {
return id.hashCode;
}
@override
String toString() {
return 'ConstraintId{name: $id}';
}
}
/// A relative id type that refers to a child element by its index
class IndexConstraintId extends ConstraintId {
/// [0, childCount-1]
/// -1 represents the last element
/// -2 represents the second to last element, and so on
final int _siblingIndex;
IndexConstraintId(this._siblingIndex)
: super('parent.children[$_siblingIndex]');
@override
ConstraintId _copy() {
return IndexConstraintId(_siblingIndex);
}
}
/// A relative id type that is referenced by index offsets between child elements
class RelativeConstraintId extends ConstraintId {
/// [-childCount+1),childCount-1]
/// cannot be 0 because it cannot refer to itself
final int _siblingIndexOffset;
RelativeConstraintId(this._siblingIndexOffset)
: super('$_siblingIndexOffset');
@override
ConstraintId _copy() {
return RelativeConstraintId(_siblingIndexOffset);
}
}
class ConstraintAlign {
final ConstraintId _id;
final ConstraintAlignType _type;
/// margin can be negative
double? _margin;
double? _goneMargin;
/// [0.0,1.0]
/// The default value is 0.5, which means centering
double? _bias;
ConstraintAlign(this._id, this._type);
ConstraintAlign margin(double margin) {
if (_margin != null || _goneMargin != null || _bias != null) {
_margin = margin;
return this;
} else {
return ConstraintAlign(_id, _type).._margin = margin;
}
}
ConstraintAlign goneMargin(double goneMargin) {
if (_margin != null || _goneMargin != null || _bias != null) {
_goneMargin = goneMargin;
return this;
} else {
return ConstraintAlign(_id, _type).._goneMargin = goneMargin;
}
}
ConstraintAlign bias(double bias) {
if (_margin != null || _goneMargin != null || _bias != null) {
_bias = bias;
return this;
} else {
return ConstraintAlign(_id, _type).._bias = bias;
}
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ConstraintAlign &&
runtimeType == other.runtimeType &&
_id == other._id &&
_type == other._type &&
_bias == other._bias;
@override
int get hashCode => _id.hashCode ^ _type.hashCode ^ _bias.hashCode;
}
typedef OnLayoutCallback = void Function(RenderBox renderBox, Rect rect);
typedef OnPaintCallback = void Function(RenderBox renderBox, Offset offset,
Size size, Offset? anchorPoint, double? angle);
typedef CalcSizeCallback = BoxConstraints Function(
RenderBox parent, List<ConstrainedNode> anchors);
typedef CalcOffsetCallback = Offset Function(
RenderBox parent, ConstrainedNode self, List<ConstrainedNode> anchors);
class ConstraintDefine {
final ConstraintId? _id;
ConstraintDefine(this._id)
/// You cannot define a relative id for yourself
: assert(_id is! IndexConstraintId),
assert(_id is! RelativeConstraintId);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ConstraintDefine &&
runtimeType == other.runtimeType &&
_id == other._id;
@override
int get hashCode => _id.hashCode;
}
/// For pinned position and translate
enum AnchorType {
absolute,
percent,
}
class Anchor {
final double _xOffset;
final AnchorType _xType;
final double _yOffset;
final AnchorType _yType;
Anchor(this._xOffset, this._xType, this._yOffset, this._yType);
Offset _resolve(Size size) {
assert(() {
debugCheckAnchorBounds(_xOffset, _xType, size.width);
debugCheckAnchorBounds(_yOffset, _yType, size.height);
return true;
}());
double x;
double y;
if (_xType == AnchorType.absolute) {
x = _xOffset;
} else {
x = _xOffset * size.width;
}
if (_yType == AnchorType.absolute) {
y = _yOffset;
} else {
y = _yOffset * size.height;
}
return Offset(x, y);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Anchor &&
runtimeType == other.runtimeType &&
_xOffset == other._xOffset &&
_xType == other._xType &&
_yOffset == other._yOffset &&
_yType == other._yType;
@override
int get hashCode =>
_xOffset.hashCode ^ _xType.hashCode ^ _yOffset.hashCode ^ _yType.hashCode;
}
/// Has no effect in pinned position layout mode.
/// You can use it to do the rotation of child elements.
class PinnedTranslate extends Offset {
final PinnedInfo _pinnedInfo;
PinnedTranslate(this._pinnedInfo) : super(0, 0);
PinnedTranslate._shift(this._pinnedInfo, double x, double y) : super(x, y);
@override
bool operator ==(Object other) =>
identical(this, other) ||
super == other &&
other is PinnedTranslate &&
runtimeType == other.runtimeType &&
_pinnedInfo == other._pinnedInfo;
@override
PinnedTranslate operator +(Offset other) =>
PinnedTranslate._shift(_pinnedInfo, other.dx, other.dy);
@override
int get hashCode => super.hashCode ^ _pinnedInfo.hashCode;
}
class PinnedInfo {
/// [0.0,360.0]
/// Exceeding the range will be automatically converted
double angle;
/// Nullable when used in pinned translate, representing a rotation
/// relative to itself
final ConstraintId? targetId;
final Anchor selfAnchor;
/// Nullable when used in pinned translate, provided targetId is empty
final Anchor? targetAnchor;
PinnedInfo(
this.targetId,
this.selfAnchor,
this.targetAnchor, {
this.angle = 0.0,
});
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PinnedInfo &&
runtimeType == other.runtimeType &&
angle == other.angle &&
targetId == other.targetId &&
selfAnchor == other.selfAnchor &&
targetAnchor == other.targetAnchor;
@override
int get hashCode =>
angle.hashCode ^
targetId.hashCode ^
selfAnchor.hashCode ^
targetAnchor.hashCode;
}
class ConstraintLayoutController {
int _constraintsVersion = 1;
int _layoutVersion = 1;
int _paintVersion = 1;
int _paintingOrderVersion = 1;
int _eventOrderVersion = 1;
ConstraintLayoutController markNeedsRecalculateConstraints() {
_constraintsVersion++;
_layoutVersion++;
_paintVersion++;
_paintingOrderVersion++;
_eventOrderVersion++;
return this;
}
ConstraintLayoutController markNeedsLayout() {
_layoutVersion++;
_paintVersion++;
return this;
}
ConstraintLayoutController markNeedsPaint() {
_paintVersion++;
return this;
}
ConstraintLayoutController markNeedsReorderPaintingOrder() {
_paintingOrderVersion++;
_eventOrderVersion++;
return this;
}
ConstraintLayoutController markNeedsReorderEventOrder() {
_eventOrderVersion++;
return this;
}
ConstraintLayoutController _copy() {
return ConstraintLayoutController()
.._constraintsVersion = _constraintsVersion
.._layoutVersion = _layoutVersion
.._paintVersion = _paintVersion
.._paintingOrderVersion = _paintingOrderVersion
.._eventOrderVersion = _eventOrderVersion;
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ConstraintLayoutController &&
runtimeType == other.runtimeType &&
_constraintsVersion == other._constraintsVersion &&
_layoutVersion == other._layoutVersion &&
_paintVersion == other._paintVersion &&
_paintingOrderVersion == other._paintingOrderVersion &&
_eventOrderVersion == other._eventOrderVersion;
@override
int get hashCode =>
_constraintsVersion.hashCode ^
_layoutVersion.hashCode ^
_paintVersion.hashCode ^
_paintingOrderVersion.hashCode ^
_eventOrderVersion.hashCode;
}
class Constraint extends ConstraintDefine {
/// 'wrap_content'、'match_parent'、'match_constraint'、'48, etc'
/// 'match_parent' will be converted to the base constraints
final double width;
final double height;
/// When size is non-null, both width and height are set to size
final double? size;
/// Expand the click area without changing the actual size
final EdgeInsets clickPadding;
final CLVisibility visibility;
/// Both margin and goneMargin can be negative
final bool percentageMargin;
final EdgeInsets margin;
final EdgeInsets goneMargin;
/// These are the base constraints constraint on sibling id or parent
/// The essence of constraints is alignment
@_baseConstraint
final ConstraintAlign? left;
@_baseConstraint
final ConstraintAlign? top;
@_baseConstraint
final ConstraintAlign? right;
@_baseConstraint
final ConstraintAlign? bottom;
@_baseConstraint
final ConstraintAlign? baseline;
/// When setting baseline alignment, height must be wrap_content or fixed size, other vertical constraints will be illegal.
/// Warning: Due to a bug in the flutter framework, baseline alignment may not take effect in debug mode
/// See https:///github.com/flutter/flutter/issues/101179
final TextBaseline textBaseline;
final int? zIndex;
final Offset translate;
/// When translate, whether to translate elements that depend on itself
final bool translateConstraint;
/// Only takes effect when width is matchConstraint
final double widthPercent;
/// Only takes effect when height is matchConstraint
final double heightPercent;
final PercentageAnchor widthPercentageAnchor;
final PercentageAnchor heightPercentageAnchor;
/// Only takes effect if both left and right constraints exist
final double horizontalBias;
/// Only takes effect if both top and bottom constraints exist
final double verticalBias;
/// These are wrapper constraints for simplicity of use, which will eventually convert to base constraints.
@_wrapperConstraint
final ConstraintId? topLeftTo;
@_wrapperConstraint
final ConstraintId? topCenterTo;
@_wrapperConstraint
final ConstraintId? topRightTo;
@_wrapperConstraint
final ConstraintId? centerLeftTo;
@_wrapperConstraint
final ConstraintId? centerTo;
@_wrapperConstraint
final ConstraintId? centerRightTo;
@_wrapperConstraint
final ConstraintId? bottomLeftTo;
@_wrapperConstraint
final ConstraintId? bottomCenterTo;
@_wrapperConstraint
final ConstraintId? bottomRightTo;
@_wrapperConstraint
final ConstraintId? centerHorizontalTo;
@_wrapperConstraint
final ConstraintId? centerVerticalTo;
@_wrapperConstraint
final ConstraintId? outTopLeftTo;
@_wrapperConstraint
final ConstraintId? outTopCenterTo;
@_wrapperConstraint
final ConstraintId? outTopRightTo;
@_wrapperConstraint
final ConstraintId? outCenterLeftTo;
@_wrapperConstraint
final ConstraintId? outCenterRightTo;
@_wrapperConstraint
final ConstraintId? outBottomLeftTo;
@_wrapperConstraint
final ConstraintId? outBottomCenterTo;
@_wrapperConstraint
final ConstraintId? outBottomRightTo;
@_wrapperConstraint
final ConstraintId? centerTopLeftTo;
@_wrapperConstraint
final ConstraintId? centerTopCenterTo;
@_wrapperConstraint
final ConstraintId? centerTopRightTo;
@_wrapperConstraint
final ConstraintId? centerCenterLeftTo;
@_wrapperConstraint
final ConstraintId? centerCenterRightTo;
@_wrapperConstraint
final ConstraintId? centerBottomLeftTo;
@_wrapperConstraint
final ConstraintId? centerBottomCenterTo;
@_wrapperConstraint
final ConstraintId? centerBottomRightTo;
final OnLayoutCallback? layoutCallback;
final OnPaintCallback? paintCallback;
/// To offset relative to its own size
final bool percentageTranslate;
/// Only takes effect when width is wrapContent
final double minWidth;
final double maxWidth;
/// Only takes effect when height is wrapContent
final double minHeight;
final double maxHeight;
/// Only takes effect if the size of one side is matchConstraint and the size of the other side can be
/// inferred (fixed size, matchParent, matchConstraint with two constraints)
final double? widthHeightRatio;
/// By default, ConstraintLayout will automatically decide which side to base on and
/// calculate the size of the other side based on widthHeightRatio. But if both sides
/// are matchConstraint, it cannot be determined automatically. At this point, you need
/// to specify the ratioBaseOnWidth parameter. The default value of null means automatically decide
final bool? ratioBaseOnWidth;
/// When the click areas of child elements overlap, the larger the eIndex, the
/// priority to respond to the event
final int? eIndex;
/// pinned position and traditional layout are mutually exclusive
/// pinned translate doesn't work when using pinned position
final PinnedInfo? pinnedInfo;
/// For arbitrary position
final List<ConstraintId>? anchors;
final CalcSizeCallback? calcSizeCallback;
final CalcOffsetCallback? calcOffsetCallback;
Constraint({
ConstraintId? id,
this.width = wrapContent,
this.height = wrapContent,
this.size,
@_baseConstraint this.left,
@_baseConstraint this.top,
@_baseConstraint this.right,
@_baseConstraint this.bottom,
@_baseConstraint this.baseline,
this.clickPadding = EdgeInsets.zero,
this.visibility = visible,
this.percentageMargin = false,
this.margin = EdgeInsets.zero,
this.goneMargin = EdgeInsets.zero,
this.textBaseline = TextBaseline.alphabetic,
this.zIndex, // default is child index
this.translate = Offset.zero,
this.translateConstraint = false,
this.widthPercent = 1,
this.heightPercent = 1,
this.widthPercentageAnchor = PercentageAnchor.constraint,
this.heightPercentageAnchor = PercentageAnchor.constraint,
this.horizontalBias = 0.5,
this.verticalBias = 0.5,
@_wrapperConstraint this.topLeftTo,
@_wrapperConstraint this.topCenterTo,
@_wrapperConstraint this.topRightTo,
@_wrapperConstraint this.centerLeftTo,
@_wrapperConstraint this.centerTo,
@_wrapperConstraint this.centerRightTo,
@_wrapperConstraint this.bottomLeftTo,
@_wrapperConstraint this.bottomCenterTo,
@_wrapperConstraint this.bottomRightTo,
@_wrapperConstraint this.centerHorizontalTo,
@_wrapperConstraint this.centerVerticalTo,
@_wrapperConstraint this.outTopLeftTo,
@_wrapperConstraint this.outTopCenterTo,
@_wrapperConstraint this.outTopRightTo,
@_wrapperConstraint this.outCenterLeftTo,
@_wrapperConstraint this.outCenterRightTo,
@_wrapperConstraint this.outBottomLeftTo,
@_wrapperConstraint this.outBottomCenterTo,
@_wrapperConstraint this.outBottomRightTo,
@_wrapperConstraint this.centerTopLeftTo,
@_wrapperConstraint this.centerTopCenterTo,
@_wrapperConstraint this.centerTopRightTo,
@_wrapperConstraint this.centerCenterLeftTo,
@_wrapperConstraint this.centerCenterRightTo,
@_wrapperConstraint this.centerBottomLeftTo,
@_wrapperConstraint this.centerBottomCenterTo,
@_wrapperConstraint this.centerBottomRightTo,
this.layoutCallback,
this.paintCallback,
this.percentageTranslate = false,
this.minWidth = 0,
this.maxWidth = matchParent,
this.minHeight = 0,
this.maxHeight = matchParent,
this.widthHeightRatio,
this.ratioBaseOnWidth,
this.eIndex,
this.pinnedInfo,
this.anchors,
this.calcSizeCallback,
this.calcOffsetCallback,
}) : super(id);
@override
bool operator ==(Object other) =>
identical(this, other) ||
super == other &&
other is Constraint &&
runtimeType == other.runtimeType &&
width == other.width &&
height == other.height &&
size == other.size &&
clickPadding == other.clickPadding &&
visibility == other.visibility &&
percentageMargin == other.percentageMargin &&
margin == other.margin &&
goneMargin == other.goneMargin &&
left == other.left &&
top == other.top &&
right == other.right &&
bottom == other.bottom &&
baseline == other.baseline &&
textBaseline == other.textBaseline &&
zIndex == other.zIndex &&
translate == other.translate &&
translateConstraint == other.translateConstraint &&
widthPercent == other.widthPercent &&
heightPercent == other.heightPercent &&
widthPercentageAnchor == other.widthPercentageAnchor &&
heightPercentageAnchor == other.heightPercentageAnchor &&
horizontalBias == other.horizontalBias &&
verticalBias == other.verticalBias &&
topLeftTo == other.topLeftTo &&
topCenterTo == other.topCenterTo &&
topRightTo == other.topRightTo &&
centerLeftTo == other.centerLeftTo &&
centerTo == other.centerTo &&
centerRightTo == other.centerRightTo &&
bottomLeftTo == other.bottomLeftTo &&
bottomCenterTo == other.bottomCenterTo &&
bottomRightTo == other.bottomRightTo &&
centerHorizontalTo == other.centerHorizontalTo &&
centerVerticalTo == other.centerVerticalTo &&
outTopLeftTo == other.outTopLeftTo &&
outTopCenterTo == other.outTopCenterTo &&
outTopRightTo == other.outTopRightTo &&
outCenterLeftTo == other.outCenterLeftTo &&
outCenterRightTo == other.outCenterRightTo &&
outBottomLeftTo == other.outBottomLeftTo &&
outBottomCenterTo == other.outBottomCenterTo &&
outBottomRightTo == other.outBottomRightTo &&
centerTopLeftTo == other.centerTopLeftTo &&
centerTopCenterTo == other.centerTopCenterTo &&
centerTopRightTo == other.centerTopRightTo &&
centerCenterLeftTo == other.centerCenterLeftTo &&
centerCenterRightTo == other.centerCenterRightTo &&
centerBottomLeftTo == other.centerBottomLeftTo &&
centerBottomCenterTo == other.centerBottomCenterTo &&
centerBottomRightTo == other.centerBottomRightTo &&
layoutCallback == other.layoutCallback &&
paintCallback == other.paintCallback &&
percentageTranslate == other.percentageTranslate &&
minWidth == other.minWidth &&
maxWidth == other.maxWidth &&
minHeight == other.minHeight &&
maxHeight == other.maxHeight &&
widthHeightRatio == other.widthHeightRatio &&
ratioBaseOnWidth == other.ratioBaseOnWidth &&
eIndex == other.eIndex &&
pinnedInfo == other.pinnedInfo &&
listEquals(anchors, other.anchors) &&
calcSizeCallback == other.calcSizeCallback &&
calcOffsetCallback == other.calcOffsetCallback;
@override
int get hashCode =>
super.hashCode ^
width.hashCode ^
height.hashCode ^
size.hashCode ^
clickPadding.hashCode ^
visibility.hashCode ^
percentageMargin.hashCode ^
margin.hashCode ^
goneMargin.hashCode ^
left.hashCode ^
top.hashCode ^
right.hashCode ^
bottom.hashCode ^
baseline.hashCode ^
textBaseline.hashCode ^
zIndex.hashCode ^
translate.hashCode ^
translateConstraint.hashCode ^