浏览代码

Make window draggable able to clamp to the parent window

/main
Jens Holm 7 年前
当前提交
daa8f8ad
共有 4 个文件被更改,包括 44 次插入4 次删除
  1. 1
      com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs
  2. 6
      com.unity.shadergraph/Editor/Drawing/Inspector/WindowDockingLayout.cs
  3. 39
      com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs
  4. 2
      com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs

1
com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs


{
WindowDockingLayout dockingLayout = new WindowDockingLayout();
dockingLayout.CalculateDockingCornerAndOffset(layout, parent.layout);
dockingLayout.ClampToParentWindow();
dockingLayout.ApplyPosition(this);
m_RecalculateLayout = false;
}

6
com.unity.shadergraph/Editor/Drawing/Inspector/WindowDockingLayout.cs


m_Size = layout.size;
}
public void ClampToParentWindow()
{
m_HorizontalOffset = Mathf.Max(0f, m_HorizontalOffset);
m_VerticalOffset = Mathf.Max(0f, m_VerticalOffset);
}
public void ApplyPosition(VisualElement target)
{
if (dockingLeft)

39
com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs


public Action OnDragFinished;
public WindowDraggable(VisualElement handle = null)
public WindowDraggable(VisualElement handle = null, VisualElement container = null)
if (container != null)
container.RegisterCallback<GeometryChangedEvent>(OnParentGeometryChanged);
}
protected override void RegisterCallbacksOnTarget()

{
if (m_WindowDockingLayout.dockingLeft)
{
target.style.positionRight = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(float.NaN);
}
else
{

{
if (m_WindowDockingLayout.dockingTop)
{
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
}
else
{

}
}
void OnParentGeometryChanged(GeometryChangedEvent geometryChangedEvent)
{
// Check if the parent window can no longer contain the target window.
// If the window is out of bounds, make one edge clamp to the border of the
// parent window.
if (target.layout.xMin < 0f)
{
target.style.positionLeft = StyleValue<float>.Create(0f);
target.style.positionRight = StyleValue<float>.Create(float.NaN);
}
if (target.layout.xMax > geometryChangedEvent.newRect.width)
{
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(0f);
}
if (target.layout.yMax > geometryChangedEvent.newRect.height)
{
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(0f);
}
if (target.layout.yMin < 0f)
{
target.style.positionTop = StyleValue<float>.Create(0f);
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
}
}
}

2
com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs


m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" };
WindowDraggable masterPreviewViewDraggable = new WindowDraggable();
WindowDraggable masterPreviewViewDraggable = new WindowDraggable(null, this);
m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable);
m_GraphView.Add(m_MasterPreviewView);

正在加载...
取消
保存