浏览代码

Make resize handels properly stay handle parent layout bounds (fixes #183)

/main
Jens Holm 7 年前
当前提交
42cd9d1b
共有 1 个文件被更改,包括 12 次插入7 次删除
  1. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs

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


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;

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

正在加载...
取消
保存