mirror of
https://gitee.com/dromara/go-view.git
synced 2026-07-15 03:51:07 +08:00
feat: 优化对齐线算法
This commit is contained in:
parent
ca81246b03
commit
2a9dff856d
@ -308,15 +308,23 @@ const _runAlignSnap = (
|
|||||||
|
|
||||||
if (bestX) {
|
if (bestX) {
|
||||||
const { y: ry, h: rh } = bestX.ref.attr
|
const { y: ry, h: rh } = bestX.ref.attr
|
||||||
const spanStart = Math.min(finalY, ry)
|
// 两组件在 Y 方向上最近的两条边(间隙区域)
|
||||||
const spanEnd = Math.max(finalY + sh, ry + rh)
|
const highBottom = Math.min(finalY + sh, ry + rh)
|
||||||
_drawAlignLine(container, false, bestX.coord, spanStart, spanEnd, `${Math.round(bestX.delta)}px`, color)
|
const lowTop = Math.max(finalY, ry)
|
||||||
|
const spanStart = Math.min(highBottom, lowTop)
|
||||||
|
const spanEnd = Math.max(highBottom, lowTop)
|
||||||
|
const gapDist = Math.max(0, lowTop - highBottom)
|
||||||
|
_drawAlignLine(container, false, bestX.coord, spanStart, spanEnd, `${Math.round(gapDist)}px`, color)
|
||||||
}
|
}
|
||||||
if (bestY) {
|
if (bestY) {
|
||||||
const { x: rx, w: rw } = bestY.ref.attr
|
const { x: rx, w: rw } = bestY.ref.attr
|
||||||
const spanStart = Math.min(finalX, rx)
|
// 两组件在 X 方向上最近的两条边(间隙区域)
|
||||||
const spanEnd = Math.max(finalX + sw, rx + rw)
|
const leftRight = Math.min(finalX + sw, rx + rw)
|
||||||
_drawAlignLine(container, true, bestY.coord, spanStart, spanEnd, `${Math.round(bestY.delta)}px`, color)
|
const rightLeft = Math.max(finalX, rx)
|
||||||
|
const spanStart = Math.min(leftRight, rightLeft)
|
||||||
|
const spanEnd = Math.max(leftRight, rightLeft)
|
||||||
|
const gapDist = Math.max(0, rightLeft - leftRight)
|
||||||
|
_drawAlignLine(container, true, bestY.coord, spanStart, spanEnd, `${Math.round(gapDist)}px`, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { x: finalX, y: finalY }
|
return { x: finalX, y: finalY }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user