-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): support equal line when resize #WIK-14483 #741
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
return result; | ||
} | ||
|
||
handleAlign(direction?: ResizeAlignDirection | null): ResizeAlignRef { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResizeAlignOptions: { resizeDirectionFactors: [number, number], isMaintainAspectRatio: boolean}
for (let alignRectangle of alignRectangles) { | ||
const offsetWidth = this.activeRectangle.width - alignRectangle.width; | ||
const offsetHeight = this.activeRectangle.height - alignRectangle.height; | ||
const absOffsetWidth = Math.abs(offsetWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以去掉这两个变量,在用的地方直接 Math.abs(xxx)
canDrawHorizontal = true; | ||
} | ||
|
||
if (absOffsetWidth === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要绝对值
const absOffsetHeight = Math.abs(offsetHeight); | ||
|
||
let canDrawHorizontal = false; | ||
if (!isCorrectWidth && absOffsetWidth < ALIGN_TOLERANCE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也需要增加判断条件,如果只垂直拖动,canDrawHorizontal 也是 false
const absOffsetWidth = Math.abs(offsetWidth); | ||
const absOffsetHeight = Math.abs(offsetHeight); | ||
|
||
let canDrawHorizontal = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canDrawHorizontal 和 isCorrectWidth 是否重复
y = 'y' | ||
} | ||
|
||
export class ResizeAlignReaction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文件名也改成 resize-align-reaction
alignRectangles: RectangleClient[]; | ||
|
||
constructor(private board: PlaitBoard, private activeElements: PlaitElement[], private activeRectangle: RectangleClient) { | ||
this.alignRectangles = this.getAlignRectangle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该就不用调用了?
export function getResizeAlignRef(board: PlaitBoard, resizeRef: ResizeRef<PlaitDrawElement | PlaitDrawElement[]>,resizeState: ResizeState): ResizeAlignRef { | ||
const isResizeFromCorner = isCornerHandle(board, resizeRef.handle); | ||
const isMaintainAspectRatio = resizeState.isShift || PlaitDrawElement.isImage(resizeRef.element); | ||
let result = getResizeOriginAndZoom(board, resizeRef, resizeState, isResizeFromCorner, isMaintainAspectRatio); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getNormalizedResizeRef
@@ -82,6 +104,15 @@ export function withDrawResize(board: PlaitBoard) { | |||
return board; | |||
} | |||
|
|||
export const getResizeUnitVector = (board: PlaitBoard, resizeRef: ResizeRef<PlaitDrawElement | PlaitDrawElement[]>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getResizeOriginPointAndHandlePoint
return movePointByZoomAndOriginPoint(p, result.originPoint, result.xZoom, result.yZoom); | ||
}) as [Point, Point]; | ||
const newRectangle = RectangleClient.getRectangleByPoints(resizePoints); | ||
const resizeAlignReaction = new ResizeAlignReaction(board, activeElements, newRectangle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像 ResizeAlignReaction 也可以用一个函数解决了,handleResizeAlign -> ResizeAlignRef,放到 draw/src/utils 里面吧
|
||
getAlignRectangle() { | ||
const result: RectangleClient[] = []; | ||
depthFirstRecursion<Ancestor>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 findElements 做
alignG = g; | ||
alignG.classList.add(ACTIVE_MOVING_CLASS_NAME); | ||
PlaitBoard.getElementActiveHost(board).append(alignG); | ||
resizeState.endPoint = [resizeState.endPoint[0] - deltaWidth, resizeState.endPoint[1] - deltaHeight]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我的理解 + 才是正确的,不知道哪里出问题了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了跟 reaction-manager 保持一致, 内部 deltaWidth 用的是 this.activeRectangle.width - alignRectangle.width,反过来外面就是 + 了,后面可以统一改下
No description provided.