@@ -130,14 +130,20 @@ void OnTitleMouseDown(MouseDownEvent e)
130
130
131
131
void OnTitleRelayout ( GeometryChangedEvent e )
132
132
{
133
+ Rect oldRoundedRect = new Rect ( Mathf . Floor ( e . oldRect . x ) , Mathf . Floor ( e . oldRect . y ) , Mathf . Floor ( e . oldRect . width ) , Mathf . Floor ( e . oldRect . height ) ) ;
134
+ Rect newRoundedRect = new Rect ( Mathf . Floor ( e . newRect . x ) , Mathf . Floor ( e . newRect . y ) , Mathf . Floor ( e . newRect . width ) , Mathf . Floor ( e . newRect . height ) ) ;
135
+ if ( oldRoundedRect == newRoundedRect )
136
+ {
137
+ return ;
138
+ }
139
+
133
140
UpdateTitleFieldRect ( ) ;
134
141
RecomputeBounds ( ) ;
135
142
}
136
143
137
144
void UpdateTitleFieldRect ( )
138
145
{
139
146
Rect rect = m_Title . layout ;
140
-
141
147
m_Title . parent . ChangeCoordinatesTo ( m_TitleField . parent , rect ) ;
142
148
143
149
@@ -186,16 +192,18 @@ public override string title
186
192
}
187
193
188
194
public bool m_WaitingRecompute ;
195
+ private Rect m_previousBounds ;
189
196
190
197
public void RecomputeBounds ( )
191
198
{
192
199
if ( m_WaitingRecompute )
193
200
return ;
201
+
194
202
visible = true ;
195
203
//title width should be at least as wide as a context to be valid.
196
204
float titleWidth = m_Title . layout . width ;
197
- bool invalidTitleWidth = float . IsNaN ( titleWidth ) || titleWidth < 50 ;
198
- bool titleEmpty = string . IsNullOrEmpty ( m_Title . text ) || invalidTitleWidth ;
205
+ bool shouldDeferRecompute = float . IsNaN ( titleWidth ) || titleWidth < 50 ;
206
+ bool titleEmpty = string . IsNullOrEmpty ( m_Title . text ) || shouldDeferRecompute ;
199
207
if ( titleEmpty )
200
208
{
201
209
m_Title . AddToClassList ( "empty" ) ;
@@ -226,22 +234,24 @@ public void RecomputeBounds()
226
234
}
227
235
228
236
if ( float . IsNaN ( rect . xMin ) || float . IsNaN ( rect . yMin ) || float . IsNaN ( rect . width ) || float . IsNaN ( rect . height ) )
237
+ {
229
238
rect = Rect . zero ;
239
+ shouldDeferRecompute = true ;
240
+ }
230
241
242
+
231
243
rect = RectUtils . Inflate ( rect , 20 , titleEmpty ? 20 : m_Title . layout . height , 20 , 20 ) ;
232
-
233
- if ( invalidTitleWidth )
244
+ rect = new Rect ( Mathf . Floor ( rect . x ) , Mathf . Floor ( rect . y ) , Mathf . Floor ( rect . width ) , Mathf . Floor ( rect . height ) ) ;
245
+ if ( rect != m_previousBounds )
234
246
{
235
247
SetPosition ( rect ) ;
236
- if ( ! m_WaitingRecompute )
237
- {
238
- m_WaitingRecompute = true ;
239
- schedule . Execute ( ( ) => { m_WaitingRecompute = false ; RecomputeBounds ( ) ; } ) . ExecuteLater ( 0 ) ; // title height might have changed if width have changed
240
- }
248
+ m_previousBounds = rect ;
241
249
}
242
- else
250
+
251
+ if ( shouldDeferRecompute && ! m_WaitingRecompute )
243
252
{
244
- SetPosition ( rect ) ;
253
+ m_WaitingRecompute = true ;
254
+ schedule . Execute ( ( ) => { m_WaitingRecompute = false ; RecomputeBounds ( ) ; } ) . ExecuteLater ( 0 ) ; // title height might have changed if width have changed
245
255
}
246
256
}
247
257
0 commit comments