Skip to content

Commit 4331681

Browse files
committed
feat: Add layout rotation support.
1 parent b9d2692 commit 4331681

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/keyboard/Keymap.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export const Keymap = ({
6363
y: k.y / 100.0,
6464
width: k.width / 100,
6565
height: k.height / 100.0,
66+
r: k.r / 100.0,
67+
rx: (k.rx || 0) / 100.0,
68+
ry: (k.ry || 0) / 100.0,
6669
children: <span>{label}</span>,
6770
};
6871
});

src/keyboard/PhysicalLayout.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropsWithChildren } from "react";
1+
import { CSSProperties, PropsWithChildren } from "react";
22
import { Key } from "./Key";
33

44
export type KeyPosition = PropsWithChildren<{
@@ -20,21 +20,32 @@ interface PhysicalLayoutProps {
2020
interface PhysicalLayoutPositionLocation {
2121
x: number;
2222
y: number;
23+
r?: number;
24+
rx?: number;
25+
ry?: number;
2326
}
2427

2528
function scalePosition(
26-
{ x, y }: PhysicalLayoutPositionLocation,
29+
{ x, y, r, rx, ry }: PhysicalLayoutPositionLocation,
2730
oneU: number
28-
): {
29-
top: number;
30-
left: number;
31-
} {
31+
): CSSProperties {
3232
let left = x * oneU;
3333
let top = y * oneU;
34+
let transformOrigin = undefined;
35+
let transform = undefined;
36+
37+
if (r) {
38+
let transformX = ((rx || x) - x) * oneU;
39+
let transformY = ((ry || y) - y) * oneU;
40+
transformOrigin = `${transformX}px ${transformY}px`;
41+
transform = `rotate(${r}deg)`;
42+
}
3443

3544
return {
3645
top,
3746
left,
47+
transformOrigin,
48+
transform,
3849
};
3950
}
4051

@@ -46,7 +57,6 @@ export const PhysicalLayout = ({
4657
onPositionClicked,
4758
...props
4859
}: PhysicalLayoutProps) => {
49-
console.log("Physical Layout", oneU, hoverZoom);
5060
// TODO: Add a bit of padding for rotation when supported
5161
let rightMost = positions
5262
.map((k) => k.x + k.width)

0 commit comments

Comments
 (0)