feat(garage): rotate vehicle thumbnails with their cards
Vehicle orientation is meaningful in a bay, so a parked-then-turned vehicle now shows its silhouette turned too. The rotated image is sized from the card's pixel dimensions (long edge against the card height) and anchored to the card centre so the 90deg turn happens around the middle instead of clipping against the top edge. Name labels stay upright.
This commit is contained in:
parent
7c135cd282
commit
45bb0bd029
1 changed files with 27 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { type CSSProperties, useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
DndContext,
|
||||
type DragEndEvent,
|
||||
|
|
@ -106,6 +106,29 @@ export function VehicleFace({
|
|||
dragging?: boolean;
|
||||
}) {
|
||||
const fp = footprint(item);
|
||||
const cardW = fp.width * cellSize - 2;
|
||||
const cardH = fp.height * cellSize - 2;
|
||||
// Thumbnail caps are applied PRE-rotation, so for rotated cards the long
|
||||
// edge must be capped by the card's HEIGHT (it becomes vertical after the
|
||||
// 90deg turn) and vice versa. Pixel math, since % would resolve against
|
||||
// the wrong axis of the already-rotated card. The rotated image is taken
|
||||
// out of flow and anchored to the card centre so the 90deg turn happens
|
||||
// around the card's middle (an in-flow image would rotate around its own
|
||||
// top-biased box and clip against the card edge).
|
||||
const thumbStyle: CSSProperties = item.rotated
|
||||
? {
|
||||
position: "absolute",
|
||||
left: "50%",
|
||||
top: "50%",
|
||||
width: Math.floor(cardH * 0.85),
|
||||
height: Math.floor(cardW * 0.85),
|
||||
objectFit: "contain",
|
||||
transform: "translate(-50%, -50%) rotate(90deg)",
|
||||
}
|
||||
: {
|
||||
maxWidth: Math.floor(cardW * 0.85),
|
||||
maxHeight: Math.floor(cardH * 0.55),
|
||||
};
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
|
|
@ -116,7 +139,7 @@ export function VehicleFace({
|
|||
item.reservedFor && "ring-1 ring-sky-400/60",
|
||||
dragging && "shadow-lg",
|
||||
)}
|
||||
style={{ width: fp.width * cellSize - 2, height: fp.height * cellSize - 2 }}
|
||||
style={{ width: cardW, height: cardH }}
|
||||
title={
|
||||
item.reservedFor ? `${item.name} (reserved for ${item.reservedFor})` : item.name
|
||||
}
|
||||
|
|
@ -126,7 +149,8 @@ export function VehicleFace({
|
|||
<img
|
||||
src={item.thumbnailUrl}
|
||||
alt=""
|
||||
className="pointer-events-none max-h-[55%] max-w-[85%] object-contain opacity-85"
|
||||
className="pointer-events-none object-contain opacity-85"
|
||||
style={thumbStyle}
|
||||
/>
|
||||
) : (
|
||||
<TruckIcon className="size-5 opacity-70" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue