desktopIconLayout
桌面图标网格布局:钳制、吸附、默认排列、框选与坐标换算。
函数签名
typescript
interface DesktopIconPoint { x: number; y: number }
interface DesktopIconSlotSize { width: number; height: number; gap: number }
interface DesktopLayerBounds { width: number; height: number }
function clampDesktopIconPoint(x, y, bounds, slot): DesktopIconPoint
function snapDesktopIconPoint(x, y, slot): DesktopIconPoint
function defaultDesktopIconPoint(index, bounds, slot): DesktopIconPoint
function buildArrangedDesktopIconPositions(itemIds, bounds, slot): Record<string, DesktopIconPoint>
function normalizeDesktopIconPositions(itemIds, bounds, stored, slot): Record<string, DesktopIconPoint>
function resolveDesktopIconPointAtClient(clientX, clientY, layerOffset, bounds, slot): DesktopIconPoint
function desktopMarqueeIntersectsIconBounds(marquee, icon): boolean参数
| 函数 | 主要参数 | 说明 |
|---|---|---|
clampDesktopIconPoint | x, y, bounds, slot | 限制图标原点在图层内 |
snapDesktopIconPoint | x, y, slot | 按槽宽/高 + gap 吸附到网格 |
defaultDesktopIconPoint | index, bounds, slot | 自上而下填满一列再开下一列 |
resolveDesktopIconPointAtClient | 客户端坐标 + 图层偏移 | 点击位置转图标原点并 snap + clamp |
返回值
| 类型 | 说明 |
|---|---|
DesktopIconPoint | 图层内图标左上角坐标 |
Record<string, DesktopIconPoint> | 批量 id → 坐标 |
boolean | 框选矩形是否与图标 bounds 相交 |
工作原理
- 网格步长:列步长
width + gap,行步长height + gap;snap用round对齐。 - 默认布局:macOS 风格按列优先填充;列数由可用高度与行步长决定。
- 持久化归一化:已有保存坐标仅 clamp,不再 snap,避免 resize 时跳动。
- 框选:
normalizeDesktopMarqueeRect规范化矩形后,用 AABB 相交判断选中图标。