1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using Unity . UIWidgets . foundation ;
4
+ using Unity . UIWidgets . ui ;
5
+
6
+ namespace Unity . UIWidgets . painting {
7
+ public class StrutStyle : Diagnosticable {
8
+ public StrutStyle (
9
+ string fontFamily = null ,
10
+ List < string > fontFamilyFallback = null ,
11
+ float ? fontSize = null ,
12
+ float ? height = null ,
13
+ float ? leading = null ,
14
+ FontWeight fontWeight = null ,
15
+ FontStyle ? fontStyle = null ,
16
+ bool forceStrutHeight = false ,
17
+ string debugLabel = null
18
+ ) {
19
+ D . assert ( fontSize == null || fontSize > 0 ) ;
20
+ D . assert ( leading == null || leading >= 0 ) ;
21
+ this . fontFamily = fontFamily ;
22
+ this . _fontFamilyFallback = fontFamilyFallback ;
23
+ this . fontSize = fontSize ;
24
+ this . height = height ;
25
+ this . fontWeight = fontWeight ;
26
+ this . fontStyle = fontStyle ;
27
+ this . leading = leading ;
28
+ this . forceStrutHeight = forceStrutHeight ;
29
+ this . debugLabel = debugLabel ;
30
+ }
31
+
32
+ public static StrutStyle fromTextStyle (
33
+ TextStyle textStyle ,
34
+ string fontFamily = null ,
35
+ List < string > fontFamilyFallback = null ,
36
+ float ? fontSize = null ,
37
+ float ? height = null ,
38
+ float ? leading = null ,
39
+ FontWeight fontWeight = null ,
40
+ FontStyle ? fontStyle = null ,
41
+ bool forceStrutHeight = false ,
42
+ string debugLabel = null
43
+ ) {
44
+ D . assert ( textStyle != null ) ;
45
+ D . assert ( fontSize == null || fontSize > 0 ) ;
46
+ D . assert ( leading == null || leading >= 0 ) ;
47
+ return new StrutStyle (
48
+ fontFamily : fontFamily ?? textStyle . fontFamily ,
49
+ fontFamilyFallback : fontFamilyFallback ?? textStyle . fontFamilyFallback ,
50
+ height : height ?? textStyle . height ,
51
+ fontSize : fontSize ?? textStyle . fontSize ,
52
+ fontWeight : fontWeight ?? textStyle . fontWeight ,
53
+ fontStyle : fontStyle ?? textStyle . fontStyle ,
54
+ debugLabel : debugLabel ?? textStyle . debugLabel
55
+ ) ;
56
+ }
57
+
58
+ public static readonly StrutStyle disabled = new StrutStyle (
59
+ height : 0.0f ,
60
+ leading : 0.0f
61
+ ) ;
62
+
63
+ public readonly string fontFamily ;
64
+
65
+ public List < string > fontFamilyFallback {
66
+ get { return this . _fontFamilyFallback ; }
67
+ }
68
+
69
+ readonly List < string > _fontFamilyFallback ;
70
+
71
+ public readonly float ? fontSize ;
72
+ public readonly float ? height ;
73
+ public readonly FontWeight fontWeight ;
74
+ public readonly FontStyle ? fontStyle ;
75
+ public readonly float ? leading ;
76
+ public readonly bool forceStrutHeight ;
77
+ public readonly string debugLabel ;
78
+
79
+ public RenderComparison compareTo ( StrutStyle other ) {
80
+ if ( ReferenceEquals ( this , other ) ) {
81
+ return RenderComparison . identical ;
82
+ }
83
+
84
+ if ( other == null ) {
85
+ return RenderComparison . layout ;
86
+ }
87
+
88
+ if ( this . fontFamily != other . fontFamily ||
89
+ this . fontSize != other . fontSize ||
90
+ this . fontWeight != other . fontWeight ||
91
+ this . fontStyle != other . fontStyle ||
92
+ this . height != other . height ||
93
+ this . leading != other . leading ||
94
+ this . forceStrutHeight != other . forceStrutHeight ||
95
+ ! CollectionUtils . equalsList ( this . fontFamilyFallback , other . fontFamilyFallback ) ) {
96
+ return RenderComparison . layout ;
97
+ }
98
+
99
+ return RenderComparison . identical ;
100
+ }
101
+
102
+ public StrutStyle inheritFromTextStyle ( TextStyle other ) {
103
+ if ( other == null ) {
104
+ return this ;
105
+ }
106
+
107
+ return new StrutStyle (
108
+ fontFamily : this . fontFamily ?? other . fontFamily ,
109
+ fontFamilyFallback : this . fontFamilyFallback ?? other . fontFamilyFallback ,
110
+ height : this . height ?? other . height ,
111
+ leading : this . leading ,
112
+ fontSize : this . fontSize ?? other . fontSize ,
113
+ fontWeight : this . fontWeight ?? other . fontWeight ,
114
+ fontStyle : this . fontStyle ?? other . fontStyle ,
115
+ forceStrutHeight : this . forceStrutHeight ,
116
+ debugLabel : this . debugLabel ?? other . debugLabel
117
+ ) ;
118
+ }
119
+
120
+ public bool Equals ( StrutStyle other ) {
121
+ if ( ReferenceEquals ( null , other ) ) {
122
+ return false ;
123
+ }
124
+
125
+ if ( ReferenceEquals ( this , other ) ) {
126
+ return true ;
127
+ }
128
+
129
+ return this . fontFamily == other . fontFamily &&
130
+ this . fontSize == other . fontSize &&
131
+ this . fontWeight == other . fontWeight &&
132
+ this . fontStyle == other . fontStyle &&
133
+ this . height == other . height &&
134
+ this . leading == other . leading &&
135
+ this . forceStrutHeight == other . forceStrutHeight ;
136
+ }
137
+
138
+ public override bool Equals ( object obj ) {
139
+ if ( ReferenceEquals ( null , obj ) ) {
140
+ return false ;
141
+ }
142
+
143
+ if ( ReferenceEquals ( this , obj ) ) {
144
+ return true ;
145
+ }
146
+
147
+ if ( obj . GetType ( ) != this . GetType ( ) ) {
148
+ return false ;
149
+ }
150
+
151
+ return this . Equals ( ( StrutStyle ) obj ) ;
152
+ }
153
+
154
+ public static bool operator == ( StrutStyle left , StrutStyle right ) {
155
+ return Equals ( left , right ) ;
156
+ }
157
+
158
+ public static bool operator != ( StrutStyle left , StrutStyle right ) {
159
+ return ! Equals ( left , right ) ;
160
+ }
161
+
162
+ public override int GetHashCode ( ) {
163
+ unchecked {
164
+ var hashCode = this . fontFamily ? . GetHashCode ( ) ?? 0 ;
165
+ hashCode = ( hashCode * 397 ) ^ ( this . fontSize ? . GetHashCode ( ) ?? 0 ) ;
166
+ hashCode = ( hashCode * 397 ) ^ ( this . fontWeight ? . GetHashCode ( ) ?? 0 ) ;
167
+ hashCode = ( hashCode * 397 ) ^ ( this . fontStyle ? . GetHashCode ( ) ?? 0 ) ;
168
+ hashCode = ( hashCode * 397 ) ^ ( this . height ? . GetHashCode ( ) ?? 0 ) ;
169
+ hashCode = ( hashCode * 397 ) ^ ( this . leading ? . GetHashCode ( ) ?? 0 ) ;
170
+ hashCode = ( hashCode * 397 ) ^ this . forceStrutHeight . GetHashCode ( ) ;
171
+ return hashCode ;
172
+ }
173
+ }
174
+
175
+ public override string toStringShort ( ) {
176
+ return $ "{ this . GetType ( ) } ";
177
+ }
178
+
179
+ public override void debugFillProperties ( DiagnosticPropertiesBuilder properties ) {
180
+ base . debugFillProperties ( properties ) ;
181
+ if ( this . debugLabel != null ) {
182
+ properties . add ( new MessageProperty ( "debugLabel" , this . debugLabel ) ) ;
183
+ }
184
+
185
+ List < DiagnosticsNode > styles = new List < DiagnosticsNode > ( ) ;
186
+ styles . Add ( new StringProperty ( "family" , this . fontFamily , defaultValue : Diagnostics . kNullDefaultValue ,
187
+ quoted : false ) ) ;
188
+ styles . Add ( new EnumerableProperty < string > ( "familyFallback" , this . fontFamilyFallback ) ) ;
189
+ styles . Add ( new DiagnosticsProperty < float ? > ( "size" , this . fontSize ,
190
+ defaultValue : Diagnostics . kNullDefaultValue ) ) ;
191
+ string weightDescription = "" ;
192
+ if ( this . fontWeight != null ) {
193
+ weightDescription = this . fontWeight . weightValue . ToString ( ) ;
194
+ }
195
+
196
+ styles . Add ( new DiagnosticsProperty < FontWeight > (
197
+ "weight" , this . fontWeight ,
198
+ description : weightDescription ,
199
+ defaultValue : Diagnostics . kNullDefaultValue
200
+ ) ) ;
201
+ styles . Add ( new EnumProperty < FontStyle ? > ( "style" , this . fontStyle ,
202
+ defaultValue : Diagnostics . kNullDefaultValue ) ) ;
203
+ styles . Add ( new DiagnosticsProperty < float ? > ( "height" , this . height ,
204
+ defaultValue : Diagnostics . kNullDefaultValue ) ) ;
205
+ styles . Add ( new FlagProperty ( "forceStrutHeight" , value : this . forceStrutHeight ,
206
+ defaultValue : Diagnostics . kNullDefaultValue ) ) ;
207
+
208
+ bool styleSpecified = styles . Any ( ( DiagnosticsNode n ) => ! n . isFiltered ( DiagnosticLevel . info ) ) ;
209
+ foreach ( var style in styles ) {
210
+ properties . add ( style ) ;
211
+ }
212
+
213
+ if ( ! styleSpecified ) {
214
+ properties . add ( new FlagProperty ( "forceStrutHeight" , value : this . forceStrutHeight ,
215
+ ifTrue : "<strut height forced>" ,
216
+ ifFalse : "<strut height normal>" ) ) ;
217
+ }
218
+ }
219
+ }
220
+ }
0 commit comments