11using System ;
22using System . Collections . Generic ;
3- using System . Diagnostics . Eventing . Reader ;
43using System . Linq ;
54using System . Reflection ;
65using UnityEngine ;
76using UnityEditor . Graphing ;
87using UnityEditor . Graphing . Util ;
9- using UnityEditor . ShaderGraph . Internal ;
8+ using UnityEditor . ShaderGraph . Drawing . Interfaces ;
109using Object = UnityEngine . Object ;
1110
1211using UnityEditor . UIElements ;
1312using UnityEngine . UIElements ;
14- using UnityEngine . UIElements . StyleSheets ;
15- using UnityEditor . SearchService ;
1613
1714namespace UnityEditor . ShaderGraph . Drawing . Inspector
1815{
19- class MasterPreviewView : VisualElement
16+ class MasterPreviewView : VisualElement , ISGResizable
2017 {
2118 PreviewManager m_PreviewManager ;
2219 GraphData m_Graph ;
@@ -34,14 +31,7 @@ public Image previewTextureView
3431
3532 Mesh m_PreviousMesh ;
3633
37- bool m_RecalculateLayout ;
38-
39- ResizeBorderFrame m_PreviewResizeBorderFrame ;
40-
41- public ResizeBorderFrame previewResizeBorderFrame
42- {
43- get { return m_PreviewResizeBorderFrame ; }
44- }
34+ ResizableElement m_ResizableElement ;
4535
4636 VisualElement m_Preview ;
4737 Label m_Title ;
@@ -54,13 +44,14 @@ public VisualElement preview
5444 List < string > m_DoNotShowPrimitives = new List < string > ( new string [ ] { PrimitiveType . Plane . ToString ( ) } ) ;
5545 static Type s_ObjectSelector = AppDomain . CurrentDomain . GetAssemblies ( ) . SelectMany ( x => x . GetTypesOrNothing ( ) ) . FirstOrDefault ( t => t . FullName == "UnityEditor.ObjectSelector" ) ;
5646
57-
5847 public string assetName
5948 {
6049 get { return m_Title . text ; }
6150 set { m_Title . text = value ; }
6251 }
6352
53+ public Action onResized ;
54+
6455 public MasterPreviewView ( PreviewManager previewManager , GraphData graph )
6556 {
6657 style . overflow = Overflow . Hidden ;
@@ -75,14 +66,17 @@ public MasterPreviewView(PreviewManager previewManager, GraphData graph)
7566 m_PreviewRenderHandle . onPreviewChanged += OnPreviewChanged ;
7667 }
7768
69+ var mainContainer = new VisualElement ( ) ;
70+ mainContainer . AddToClassList ( "mainContainer" ) ;
71+
7872 var topContainer = new VisualElement ( ) { name = "top" } ;
7973 {
8074 m_Title = new Label ( ) { name = "title" } ;
8175 m_Title . text = "Main Preview" ;
8276
8377 topContainer . Add ( m_Title ) ;
8478 }
85- Add ( topContainer ) ;
79+ mainContainer . Add ( topContainer ) ;
8680
8781 m_Preview = new VisualElement { name = "middle" } ;
8882 {
@@ -91,14 +85,14 @@ public MasterPreviewView(PreviewManager previewManager, GraphData graph)
9185 preview . Add ( m_PreviewTextureView ) ;
9286 preview . AddManipulator ( new Scrollable ( OnScroll ) ) ;
9387 }
94- Add ( preview ) ;
88+ mainContainer . Add ( preview ) ;
89+
90+ Add ( mainContainer ) ;
9591
96- m_PreviewResizeBorderFrame = new ResizeBorderFrame ( this , this ) { name = "resizeBorderFrame" } ;
97- m_PreviewResizeBorderFrame . maintainAspectRatio = true ;
98- Add ( m_PreviewResizeBorderFrame ) ;
92+ m_ResizableElement = new ResizableElement ( ) ;
93+ Add ( m_ResizableElement ) ;
9994
100- m_RecalculateLayout = false ;
101- this . RegisterCallback < GeometryChangedEvent > ( OnGeometryChanged ) ;
95+ RegisterCallback < GeometryChangedEvent > ( OnGeometryChanged ) ;
10296 }
10397
10498 Image CreatePreview ( Texture texture )
@@ -191,15 +185,6 @@ void ChangeMeshCustom()
191185
192186 void OnGeometryChanged ( GeometryChangedEvent evt )
193187 {
194- if ( m_RecalculateLayout )
195- {
196- WindowDockingLayout dockingLayout = new WindowDockingLayout ( ) ;
197- dockingLayout . CalculateDockingCornerAndOffset ( layout , parent . layout ) ;
198- dockingLayout . ClampToParentWindow ( ) ;
199- dockingLayout . ApplyPosition ( this ) ;
200- m_RecalculateLayout = false ;
201- }
202-
203188 var currentWidth = m_PreviewRenderHandle ? . texture != null ? m_PreviewRenderHandle . texture . width : - 1 ;
204189 var currentHeight = m_PreviewRenderHandle ? . texture != null ? m_PreviewRenderHandle . texture . height : - 1 ;
205190
@@ -210,7 +195,10 @@ void OnGeometryChanged(GeometryChangedEvent evt)
210195 return ;
211196
212197 m_PreviewTextureView . style . width = evt . newRect . width ;
213- m_PreviewTextureView . style . height = evt . newRect . height - 40.0f ;
198+
199+ const float offsetFromHeader = 40.0f ;
200+ const float offsetFromMargin = 2 * 6.0f ;
201+ m_PreviewTextureView . style . height = evt . newRect . height - ( offsetFromHeader + offsetFromMargin ) ;
214202 m_PreviewManager . ResizeMasterPreview ( new Vector2 ( evt . newRect . width , evt . newRect . width ) ) ;
215203 }
216204
@@ -235,5 +223,17 @@ void OnMouseDragPreviewMesh(Vector2 deltaMouse)
235223
236224 m_PreviewManager . UpdateMasterPreview ( ModificationScope . Node ) ;
237225 }
226+
227+ public void OnStartResize ( )
228+ {
229+ }
230+
231+ public void OnResized ( )
232+ {
233+ onResized ? . Invoke ( ) ;
234+ }
235+
236+ public bool CanResizePastParentBounds ( ) => false ;
237+ public bool KeepSquareAspect ( ) => true ;
238238 }
239239}
0 commit comments