浏览代码

Add option in resize handels to make it staty in the bounds of the parent element

/main
Jens Holm 7 年前
当前提交
e3d84f9b
共有 3 个文件被更改,包括 54 次插入24 次删除
  1. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  2. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  3. 1
      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()

21
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)

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)
{
if (newLayout.x < 0f || (newLayout.x + newLayout.width) > m_ResizeTarget.parent.layout.width)
{
newLayout.width = m_ResizeTarget.layout.width;
}
if (newLayout.y < 0f || (newLayout.y + newLayout.height) > m_ResizeTarget.parent.layout.height)
{
newLayout.height = m_ResizeTarget.layout.height;
}
}
m_ResizeTarget.layout = newLayout;
}

1
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);

正在加载...
取消
保存