浏览代码

Merge pull request #185 from Unity-Technologies/inspector-window

Make resize handles remain within bounds of parent element
/main
GitHub 7 年前
当前提交
653eb828
共有 3 个文件被更改,包括 63 次插入27 次删除
  1. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  2. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

56
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


public class ResizeBorderFrame : VisualElement
{
List<ResizeSideHandle> m_ResizeSideHandles;
bool m_StayWithinParentBounds;
public bool stayWithinParentBounds
{
get { return m_StayWithinParentBounds; }
set
{
m_StayWithinParentBounds = value;
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{
resizeHandle.stayWithinPanretBounds = value;
}
}
}
public Action OnResizeFinished;
public ResizeBorderFrame(VisualElement target)

AddToClassList("reszieBorderFrame");
ResizeSideHandle topLeft = new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft);
ResizeSideHandle top = new ResizeSideHandle(target, ResizeHandleAnchor.Top);
ResizeSideHandle topRight = new ResizeSideHandle(target, ResizeHandleAnchor.TopRight);
ResizeSideHandle right = new ResizeSideHandle(target, ResizeHandleAnchor.Right);
ResizeSideHandle bottomRight = new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight);
ResizeSideHandle bottom = new ResizeSideHandle(target, ResizeHandleAnchor.Bottom);
ResizeSideHandle bottomLeft = new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft);
ResizeSideHandle left = new ResizeSideHandle(target, ResizeHandleAnchor.Left);
m_ResizeSideHandles = new List<ResizeSideHandle>();
topLeft.OnResizeFinished += HandleResizefinished;
top.OnResizeFinished += HandleResizefinished;
topRight.OnResizeFinished += HandleResizefinished;
right.OnResizeFinished += HandleResizefinished;
bottomRight.OnResizeFinished += HandleResizefinished;
bottom.OnResizeFinished += HandleResizefinished;
bottomLeft.OnResizeFinished += HandleResizefinished;
left.OnResizeFinished += HandleResizefinished;
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopLeft));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Top));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.TopRight));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Right));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomRight));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Bottom));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.BottomLeft));
m_ResizeSideHandles.Add(new ResizeSideHandle(target, ResizeHandleAnchor.Left));
Add(topLeft);
Add(top);
Add(topRight);
Add(right);
Add(bottomRight);
Add(bottom);
Add(bottomLeft);
Add(left);
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{
resizeHandle.OnResizeFinished += HandleResizefinished;
Add(resizeHandle);
}
}
void HandleResizefinished()

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs


{
VisualElement m_ResizeTarget;
bool m_StayWithinParentBounds;
public bool stayWithinPanretBounds
{
get { return m_StayWithinParentBounds; }
set { m_StayWithinParentBounds = value; }
}
public Action OnResizeFinished;
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor)

RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
}
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizerVertical)
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;

Rect newLayout = m_ResizeTarget.layout;
// Resize form bottom/right
// Resize from bottom/right
if (!moveWhileResizeHorizontal)
{
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, minSize.x);

if (!moveWhileresizerVertical)
if (!moveWhileresizeVertical)
{
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, minSize.y);
normalizedResizeDelta.y = 0f;

newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - minSize.x);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
if (m_StayWithinParentBounds)
{
float horizontalTranscendance = Mathf.Min(newLayout.x, 0f) + Mathf.Max(newLayout.xMax - m_ResizeTarget.parent.layout.width, 0f);
float verticalTranscendance = Mathf.Min(newLayout.y, 0f) + Mathf.Max(newLayout.yMax - m_ResizeTarget.parent.layout.height, 0f);
if (moveWhileResizeHorizontal)
{
newLayout.x -= horizontalTranscendance;
}
newLayout.width -= Mathf.Abs(horizontalTranscendance);
if (moveWhileresizeVertical)
{
newLayout.y -= verticalTranscendance;
}
newLayout.height -= Mathf.Abs(verticalTranscendance);
}
m_ResizeTarget.layout = newLayout;
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


m_GraphView.Add(m_MasterPreviewView);
ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout;

正在加载...
取消
保存