浏览代码

Add function in WinowDockingLayout to apply layout position or size

/main
Jens Holm 7 年前
当前提交
6a079706
共有 3 个文件被更改,包括 53 次插入59 次删除
  1. 33
      com.unity.shadergraph/Editor/Drawing/Inspector/WindowDockingLayout.cs
  2. 56
      com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  3. 23
      com.unity.shadergraph/Editor/Drawing/Manipulators/WindowDraggable.cs

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


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleSheets;
namespace UnityEditor.ShaderGraph.Drawing
{

}
m_Size = layout.size;
}
public void ApplyPosition(VisualElement target)
{
if (dockingLeft)
{
target.style.positionRight = StyleValue<float>.Create(float.NaN);
target.style.positionLeft = StyleValue<float>.Create(horizontalOffset);
}
else
{
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(horizontalOffset);
}
if (dockingTop)
{
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
target.style.positionTop = StyleValue<float>.Create(verticalOffset);
}
else
{
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(verticalOffset);
}
}
public void ApplySize(VisualElement target)
{
target.style.width = StyleValue<float>.Create(size.x);
target.style.height = StyleValue<float>.Create(size.y);
}
public Rect GetLayout(Rect parentLayout)

56
com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs


bool m_Dragging;
float m_InitialAspectRatio;
Rect m_ResizeBeginLayout;
Vector2 m_ResizeBeginMousePosition;

void InitialLayoutSetup(GeometryChangedEvent evt)
{
m_ResizeTarget.UnregisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
m_InitialAspectRatio = m_ResizeTarget.layout.width / m_ResizeTarget.layout.height;
m_InitialAspectRatio = 1f;
}
Vector2 BoundedMousePosition(Vector2 mousePosition)
{
mousePosition = m_Container.parent.WorldToLocal(mousePosition);
if (!stayWithinParentBounds)
return mousePosition;
mousePosition.x = Mathf.Clamp(mousePosition.x, 5f, m_Container.parent.layout.width);
mousePosition.y = Mathf.Clamp(mousePosition.y, 5f, m_Container.parent.layout.height);
return mousePosition;
}
void HandleResizeFromTop(MouseMoveEvent mouseMoveEvent)

mouseMoveEvent.StopPropagation();
}
void Applydocking()
{
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
if (m_WindowDockingLayout.dockingLeft)
{
m_Container.style.positionLeft = StyleValue<float>.Create(m_WindowDockingLayout.horizontalOffset);
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN);
}
else
{
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN);
m_Container.style.positionRight = StyleValue<float>.Create(m_WindowDockingLayout.horizontalOffset);
}
if (m_WindowDockingLayout.dockingTop)
{
m_Container.style.positionTop = StyleValue<float>.Create(m_WindowDockingLayout.verticalOffset);
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN);
}
else
{
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN);
m_Container.style.positionBottom = StyleValue<float>.Create(m_WindowDockingLayout.verticalOffset);
}
}
Applydocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
m_WindowDockingLayout.ApplyPosition(m_Container);
m_ResizeBeginLayout = m_ResizeTarget.layout;
m_ResizeBeginMousePosition = mouseDownEvent.mousePosition;

m_Dragging = false;
if (this.HasMouseCapture())
{
}
{
}
Applydocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
m_WindowDockingLayout.ApplyPosition(m_Container);
}
}
}

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


m_Handle.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
target.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
}
protected override void UnregisterCallbacksFromTarget()

positionOffset.y = Mathf.Max(positionOffset.y, 0f);
// Use the docking results to figure which of left/right and top/bottom needs to be set.
if (m_WindowDockingLayout.dockingLeft)
{
target.style.positionRight = StyleValue<float>.Create(float.NaN);
target.style.positionLeft = StyleValue<float>.Create(positionOffset.x);
}
else
{
target.style.positionLeft = StyleValue<float>.Create(float.NaN);
target.style.positionRight = StyleValue<float>.Create(positionOffset.x);
}
if (m_WindowDockingLayout.dockingTop)
{
target.style.positionBottom = StyleValue<float>.Create(float.NaN);
target.style.positionTop = StyleValue<float>.Create(positionOffset.y);
}
else
{
target.style.positionTop = StyleValue<float>.Create(float.NaN);
target.style.positionBottom = StyleValue<float>.Create(positionOffset.y);
}
m_WindowDockingLayout.ApplyPosition(target);
// Signal that the dragging has finished.
if (emitDragFinishedEvent && OnDragFinished != null)

正在加载...
取消
保存