浏览代码

Make reisze handels and window draggable manipulator respect minimum dimensions of target

/main
Jens Holm 7 年前
当前提交
4e8c00e0
共有 3 个文件被更改,包括 64 次插入18 次删除
  1. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  2. 55
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
  3. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

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


{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f))
{
minSize.x = m_ResizeTarget.style.minWidth;
}
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f))
{
minSize.y = m_ResizeTarget.style.minHeight.value;
}
if (direction == ResizeDirection.Vertical)
{
normalizedResizeDelta.x = 0f;

// Resize form bottom/right
if (!moveWhileResizeHorizontal)
{
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, 60f);
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, 60f);
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, minSize.y);
normalizedResizeDelta.y = 0f;
}

newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, 60f);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, 60f);
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, minSize.y);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - 60f);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - 60f);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - minSize.x);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
m_ResizeTarget.layout = newLayout;
}

55
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs


{
public class WindowDraggable : MouseManipulator
{
bool m_ResizeWithParentWindow;
bool m_Active;
bool m_DockLeft;

Rect m_PreviousParentRect;
public WindowDraggable()
public WindowDraggable(bool resizeWithParentwindow = false)
m_ResizeWithParentWindow = resizeWithParentwindow;
m_Active = false;
m_PreviousParentRect = new Rect(0f, 0f, 0f, 0f);
}

Vector2 scaling = target.parent.layout.size / m_PreviousParentRect.size;
Vector2 distanceFromEdge = Vector2.zero;
distanceFromEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(target.style.minWidth, 0f))
{
minSize.x = target.style.minWidth;
}
if (!Mathf.Approximately(target.style.minHeight, 0f))
{
minSize.y = target.style.minHeight;
}
Vector2 distanceFromParentEdge = Vector2.zero;
distanceFromParentEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
Vector2 normalizedDistanceFromEdge = distanceFromParentEdge / m_PreviousParentRect.size;
if (m_ResizeWithParentWindow)
{
if (scaling.x > 1f)
{
scaling.x = target.parent.layout.width * .33f < minSize.x ? 1f : scaling.x;
}
Vector2 normalizedDistanceFromEdge = distanceFromEdge / m_PreviousParentRect.size;
if (scaling.y > 1f)
{
scaling.y = target.parent.layout.height * .33f < minSize.y ? 1f : scaling.y;
}
windowRect.size *= scaling;
windowRect.size *= scaling;
}
else
{
normalizedDistanceFromEdge = distanceFromParentEdge / target.parent.layout.size;
}
if (m_DockLeft)
{

windowRect.y = (1f - normalizedDistanceFromEdge.y) * target.parent.layout.height- windowRect.height;
}
float maximumXPosition = target.parent.layout.width - windowRect.width;
float maximumYPosition = target.parent.layout.height - windowRect.height;
windowRect.width = Mathf.Max(Mathf.Min(windowRect.width, target.parent.layout.width), minSize.x);
windowRect.height = Mathf.Max(Mathf.Min(windowRect.height, target.parent.layout.height), minSize.y);
float maximumXPosition = Mathf.Max(target.parent.layout.width - windowRect.width, 0f);
float maximumYPosition = Mathf.Max(target.parent.layout.height - windowRect.height, 0f);
windowRect.width = Mathf.Min(windowRect.width, target.parent.layout.width);
windowRect.height = Mathf.Min(windowRect.height, target.parent.layout.height);
m_PreviousParentRect = target.parent.layout;
target.layout = windowRect;

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


position-right: 0;
position-top: 0;
width: 400;
min-width: 300;
}
GraphInspectorView * {

position-bottom: 0;
background-color: rgb(79, 79, 79);
justify-content: flex-start;
min-width: 200;
min-height: 200;
}
MasterNodeView > #top {

正在加载...
取消
保存