feat(refboard): distribute H/V now normalizes sizes for uniform rows/columns

- Distribute H: normalizes height + arranges as row (uniform horizontal strip)
- Distribute V: normalizes width + arranges as column (uniform vertical strip)
- Also reduced min selection from 3 to 2 for both operations
This commit is contained in:
Hiren Kangad
2026-03-10 04:26:00 +05:30
parent 380207a4c0
commit a42d674737
+28 -24
View File
@@ -75,36 +75,40 @@ export function alignBottom(objects: SceneItem[]) {
// ─── Distribution ─── // ─── Distribution ───
/** Distribute horizontally: normalize all to same height, then space evenly in a row. */
export function distributeHorizontal(objects: SceneItem[]) { export function distributeHorizontal(objects: SceneItem[]) {
if (objects.length < 3) return; if (objects.length < 2) return;
// Normalize heights first (uniform row)
normalizeHeight(objects);
// Then arrange as row with even spacing
const gap = 20;
const sorted = [...objects].sort((a, b) => a.data.x - b.data.x); const sorted = [...objects].sort((a, b) => a.data.x - b.data.x);
const first = sorted[0]; const startY = sorted[0].data.y;
const last = sorted[sorted.length - 1]; let x = sorted[0].data.x;
const totalSpan = last.data.x + scaledW(last) - first.data.x; sorted.forEach((item) => {
const totalWidth = sorted.reduce((s, item) => s + scaledW(item), 0); item.data.x = x;
const gap = (totalSpan - totalWidth) / (sorted.length - 1); item.data.y = startY;
let x = first.data.x + scaledW(first) + gap; syncPosition(item);
for (let i = 1; i < sorted.length - 1; i++) { x += scaledW(item) + gap;
sorted[i].data.x = x; });
syncPosition(sorted[i]);
x += scaledW(sorted[i]) + gap;
}
} }
/** Distribute vertically: normalize all to same width, then space evenly in a column. */
export function distributeVertical(objects: SceneItem[]) { export function distributeVertical(objects: SceneItem[]) {
if (objects.length < 3) return; if (objects.length < 2) return;
// Normalize widths first (uniform column)
normalizeWidth(objects);
// Then arrange as column with even spacing
const gap = 20;
const sorted = [...objects].sort((a, b) => a.data.y - b.data.y); const sorted = [...objects].sort((a, b) => a.data.y - b.data.y);
const first = sorted[0]; const startX = sorted[0].data.x;
const last = sorted[sorted.length - 1]; let y = sorted[0].data.y;
const totalSpan = last.data.y + scaledH(last) - first.data.y; sorted.forEach((item) => {
const totalHeight = sorted.reduce((s, item) => s + scaledH(item), 0); item.data.x = startX;
const gap = (totalSpan - totalHeight) / (sorted.length - 1); item.data.y = y;
let y = first.data.y + scaledH(first) + gap; syncPosition(item);
for (let i = 1; i < sorted.length - 1; i++) { y += scaledH(item) + gap;
sorted[i].data.y = y; });
syncPosition(sorted[i]);
y += scaledH(sorted[i]) + gap;
}
} }
// ─── Normalize ─── // ─── Normalize ───