Add icon row arrangement and consistent sizing
This commit is contained in:
1 parent
f79e30897b
commit
8d604a5807
9 files changed
+213
-67
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { runInNewContext } from "node:vm";
|
||||
import { alignmentGuide, builtInLayout, deviceMapper, normalizeLayout, validate } from "./src/layout.ts";
|
||||
import { alignmentGuide, arrangeIconRow, builtInLayout, deviceMapper, normalizeLayout, resizedIconBounds, validate } from "./src/layout.ts";
|
||||
|
||||
const fixtures = JSON.parse(readFileSync(new URL("../docs/layout-cases.json", import.meta.url), "utf8"));
|
||||
const offline = readFileSync(new URL("./canvas.html", import.meta.url), "utf8");
|
||||
@@ -67,3 +67,19 @@ assert.equal(alignmentGuide(82, 36, [120, 118], 4), 118);
|
||||
assert.equal(alignmentGuide(82, 36, [122], 3), undefined);
|
||||
assert.equal(alignmentGuide(0, 36, [0], 0), 0);
|
||||
console.log("Drag alignment guides passed");
|
||||
|
||||
const icons = items.filter(item => item.type === "app_icon").slice(0, 4);
|
||||
const misplaced = icons.map((item, index) => ({ ...item, x: item.x + index * 7, y: item.y + index * 8 }));
|
||||
const arranged = arrangeIconRow(misplaced.reverse(), canvas);
|
||||
assert.deepEqual(arranged.map(({ item, x }) => x + item.w / 2), [216, 432, 648, 864]);
|
||||
assert.equal(new Set(arranged.map(({ item, y }) => y + item.h / 2)).size, 1);
|
||||
assert.deepEqual(arranged.map(({ item }) => item.id), icons.map(item => item.id));
|
||||
assert.equal(arrangeIconRow(icons, { ...canvas, designWidth: 320 }), undefined);
|
||||
console.log("Four-column row arrangement passed");
|
||||
|
||||
const icon = icons[0];
|
||||
assert.deepEqual(resizedIconBounds(icon, icon.w + 16, icon.h + 20, canvas),
|
||||
{ x: icon.x - 8, y: icon.y - 10, w: icon.w + 16, h: icon.h + 20 });
|
||||
assert.deepEqual(resizedIconBounds({ ...icon, x: 0, y: 0 }, 200, 220, canvas),
|
||||
{ x: 0, y: 0, w: 200, h: 220 });
|
||||
console.log("Icon resize centering and canvas bounds passed");
|
||||
Reference in new issue
Block a user