1- using System . Collections ;
2- using System . Collections . Generic ;
31using UnityEngine ;
42using UnityEngine . UIElements ;
53using UnityEditor . Experimental . GraphView ;
4+
65using System ;
76using System . Linq ;
87
@@ -61,6 +60,7 @@ protected override void ImmediateRepaint()
6160 }
6261
6362 Material m_Mat ;
63+ bool m_WaitingRecompute ;
6464
6565 static Mesh s_Mesh ;
6666
@@ -76,16 +76,16 @@ public VFXSystemBorder()
7676 this . style . overflow = Overflow . Visible ;
7777
7878 m_Title = this . Query < Label > ( "title" ) ;
79- m_TitleField = this . Query < TextField > ( "title-field" ) ;
80-
81- m_TitleField . style . display = DisplayStyle . None ;
82-
8379 m_Title . RegisterCallback < MouseDownEvent > ( OnTitleMouseDown ) ;
80+ m_Title . RegisterCallback < GeometryChangedEvent > ( OnTitleRelayout ) ;
8481
85- m_TitleField . Q ( "unity-text-input" ) . RegisterCallback < FocusOutEvent > ( OnTitleBlur , TrickleDown . TrickleDown ) ;
86- m_TitleField . RegisterCallback < ChangeEvent < string > > ( OnTitleChange ) ;
82+ m_TitleField = this . Query < TextField > ( "title-field" ) ;
83+ m_TitleField . style . display = DisplayStyle . None ;
8784 m_TitleField . maxLength = kMaximumSystemNameLength ;
88- m_Title . RegisterCallback < GeometryChangedEvent > ( OnTitleRelayout ) ;
85+ m_TitleField . multiline = false ;
86+ m_TitleField . RegisterCallback < ChangeEvent < string > > ( OnTitleChange ) ;
87+ m_TitleField . RegisterCallback < GeometryChangedEvent > ( OnTitleRelayout ) ;
88+ m_TitleField . Q ( "unity-text-input" ) . RegisterCallback < FocusOutEvent > ( OnTitleBlur , TrickleDown . TrickleDown ) ;
8989
9090 Content content = new Content ( this ) ;
9191 content . style . position = UnityEngine . UIElements . Position . Absolute ;
@@ -95,27 +95,20 @@ public VFXSystemBorder()
9595 pickingMode = PickingMode . Ignore ;
9696 Add ( content ) ;
9797 RegisterCallback < CustomStyleResolvedEvent > ( OnCustomStyleResolved ) ;
98- this . AddManipulator ( new ContextualMenuManipulator ( BuildContextualMenu ) ) ;
9998 visible = false ;
10099 }
101100
102- public void BuildContextualMenu ( ContextualMenuPopulateEvent evt )
103- {
104- }
105-
106101 public void OnRename ( )
107102 {
108- m_TitleField . RemoveFromClassList ( "empty" ) ;
103+ m_Title . style . display = DisplayStyle . None ;
109104 m_TitleField . value = m_Title . text ;
110-
111105 m_TitleField . style . display = DisplayStyle . Flex ;
112- UpdateTitleFieldRect ( ) ;
113106 m_TitleField . Q ( TextField . textInputUssName ) . Focus ( ) ;
114107 m_TitleField . SelectAll ( ) ;
115108 }
116109
117- Label m_Title ;
118- TextField m_TitleField ;
110+ readonly Label m_Title ;
111+ readonly TextField m_TitleField ;
119112
120113
121114 void OnTitleMouseDown ( MouseDownEvent e )
@@ -128,42 +121,16 @@ void OnTitleMouseDown(MouseDownEvent e)
128121 }
129122 }
130123
131- bool IsDifferenceTooSmall ( float x , float y )
132- {
133- return Mathf . Abs ( x - y ) < 1f ;
134- }
135-
136- void OnTitleRelayout ( GeometryChangedEvent e )
124+ void OnTitleRelayout ( GeometryChangedEvent geometryChangedEvent )
137125 {
138- if ( IsDifferenceTooSmall ( e . oldRect . x , e . newRect . x ) &&
139- IsDifferenceTooSmall ( e . oldRect . y , e . newRect . y ) &&
140- IsDifferenceTooSmall ( e . oldRect . width , e . newRect . width ) &&
141- IsDifferenceTooSmall ( e . oldRect . height , e . newRect . height ) )
142- {
143- return ;
144- }
145-
146- UpdateTitleFieldRect ( ) ;
147126 RecomputeBounds ( ) ;
148127 }
149128
150- void UpdateTitleFieldRect ( )
151- {
152- Rect rect = m_Title . layout ;
153- m_Title . parent . ChangeCoordinatesTo ( m_TitleField . parent , rect ) ;
154-
155-
156- m_TitleField . style . top = rect . yMin - 6 ;
157- m_TitleField . style . left = rect . xMin - 5 ;
158- m_TitleField . style . right = m_Title . resolvedStyle . marginRight + m_Title . resolvedStyle . borderRightWidth + 2 ;
159- m_TitleField . style . height = rect . height - m_Title . resolvedStyle . marginTop - m_Title . resolvedStyle . marginBottom ;
160- }
161-
162129 void OnTitleBlur ( FocusOutEvent e )
163130 {
164131 title = m_TitleField . value ;
165132 m_TitleField . style . display = DisplayStyle . None ;
166-
133+ m_Title . style . display = DisplayStyle . Flex ;
167134 controller . SetTitle ( title ) ;
168135 }
169136
@@ -175,48 +142,31 @@ void OnContextChanged(GeometryChangedEvent e)
175142 void OnTitleChange ( ChangeEvent < string > e )
176143 {
177144 title = m_TitleField . value ;
178- if ( string . IsNullOrEmpty ( e . previousValue ) != string . IsNullOrEmpty ( e . newValue ) )
179- {
180- RecomputeBounds ( ) ;
181- }
145+ RecomputeBounds ( ) ;
182146 }
183147
184148 public override string title
185149 {
186- get
187- {
188- return m_Title . text ;
189- }
150+ get => m_Title . text ;
190151 set
191152 {
192153 if ( m_Title . text != value )
193154 {
194155 m_Title . text = value ;
195- RecomputeBounds ( ) ;
196156 }
197157 }
198158 }
199159
200- public bool m_WaitingRecompute ;
201-
202160 public void RecomputeBounds ( )
203161 {
204162 if ( m_WaitingRecompute )
205163 return ;
206164
207165 visible = true ;
208166 //title width should be at least as wide as a context to be valid.
209- float titleWidth = m_Title . layout . width ;
167+ VisualElement textElement = m_Title . resolvedStyle . display == DisplayStyle . Flex ? m_Title : m_TitleField ;
168+ float titleWidth = textElement . layout . width ;
210169 bool shouldDeferRecompute = float . IsNaN ( titleWidth ) || titleWidth < 50 ;
211- bool titleEmpty = string . IsNullOrEmpty ( m_Title . text ) || shouldDeferRecompute ;
212- if ( titleEmpty )
213- {
214- m_Title . AddToClassList ( "empty" ) ;
215- }
216- else
217- {
218- m_Title . RemoveFromClassList ( "empty" ) ;
219- }
220170
221171 Rect rect = Rect . zero ;
222172
@@ -226,14 +176,9 @@ public void RecomputeBounds()
226176 {
227177 if ( context != null )
228178 {
229- if ( rect == Rect . zero )
230- {
231- rect = context . localBound ;
232- }
233- else
234- {
235- rect = RectUtils . Encompass ( rect , context . GetPosition ( ) ) ;
236- }
179+ rect = rect == Rect . zero
180+ ? context . localBound
181+ : RectUtils . Encompass ( rect , context . GetPosition ( ) ) ;
237182 }
238183 }
239184 }
@@ -243,7 +188,7 @@ public void RecomputeBounds()
243188 rect = Rect . zero ;
244189 }
245190
246- rect = RectUtils . Inflate ( rect , 20 , titleEmpty ? 20 : m_Title . layout . height , 20 , 20 ) ;
191+ rect = RectUtils . Inflate ( rect , 20 , Mathf . Max ( 20 , textElement . layout . height ) , 20 , 20 ) ;
247192 if ( shouldDeferRecompute )
248193 {
249194 SetPosition ( rect ) ;
@@ -262,10 +207,7 @@ public void RecomputeBounds()
262207 VFXContextUI [ ] m_Contexts ;
263208 internal VFXContextUI [ ] contexts
264209 {
265- get
266- {
267- return m_Contexts ;
268- }
210+ get => m_Contexts ;
269211 private set
270212 {
271213 if ( m_Contexts != null )
@@ -303,7 +245,7 @@ void RecreateResources()
303245 for ( int iy = 0 ; iy < 4 ; ++ iy )
304246 {
305247 vertices [ ix + iy * 4 ] = new Vector3 ( ix < 2 ? - 1 : 1 , iy < 2 ? - 1 : 1 , 0 ) ;
306- uvsBorder [ ix + iy * 4 ] = new Vector2 ( ix == 0 || ix == 3 ? 1 : 0 , iy == 0 || iy == 3 ? 1 : 0 ) ;
248+ uvsBorder [ ix + iy * 4 ] = new Vector2 ( ix is 0 or 3 ? 1 : 0 , iy is 0 or 3 ? 1 : 0 ) ;
307249 uvsDistance [ ix + iy * 4 ] = new Vector2 ( iy < 2 ? ix / 2 : 2 - ix / 2 , iy < 2 ? 0 : 1 ) ;
308250 }
309251 }
@@ -373,38 +315,22 @@ void IDisposable.Dispose()
373315 Color m_StartColor ;
374316 public Color startColor
375317 {
376- get
377- {
378- return m_StartColor ;
379- }
380- set
381- {
382- m_StartColor = value ;
383- }
318+ get => m_StartColor ;
319+ set => m_StartColor = value ;
384320 }
321+
385322 Color m_EndColor ;
386323 public Color endColor
387324 {
388- get
389- {
390- return m_EndColor ;
391- }
392- set
393- {
394- m_EndColor = value ;
395- }
325+ get => m_EndColor ;
326+ set => m_EndColor = value ;
396327 }
328+
397329 Color m_MiddleColor ;
398330 public Color middleColor
399331 {
400- get
401- {
402- return m_MiddleColor ;
403- }
404- set
405- {
406- m_MiddleColor = value ;
407- }
332+ get => m_MiddleColor ;
333+ set => m_MiddleColor = value ;
408334 }
409335
410336 static readonly CustomStyleProperty < Color > s_StartColorProperty = new CustomStyleProperty < Color > ( "--start-color" ) ;
@@ -419,24 +345,16 @@ private void OnCustomStyleResolved(CustomStyleResolvedEvent e)
419345 }
420346
421347 VFXSystemController m_Controller ;
422- Controller IControlledElement . controller
423- {
424- get { return m_Controller ; }
425- }
348+ Controller IControlledElement . controller => m_Controller ;
349+
426350 public VFXSystemController controller
427351 {
428- get { return m_Controller ; }
352+ get => m_Controller ;
429353 set
430354 {
431- if ( m_Controller != null )
432- {
433- m_Controller . UnregisterHandler ( this ) ;
434- }
355+ m_Controller ? . UnregisterHandler ( this ) ;
435356 m_Controller = value ;
436- if ( m_Controller != null )
437- {
438- m_Controller . RegisterHandler ( this ) ;
439- }
357+ m_Controller ? . RegisterHandler ( this ) ;
440358 }
441359 }
442360
0 commit comments