Fix for negative spacing

This commit is contained in:
2025-11-18 21:11:26 +01:00
parent f7a01e6c92
commit 57d62db219
4 changed files with 32 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
import { ref, computed, type Ref, type ComputedRef } from 'vue';
import type { Sprite } from '@/types/sprites';
import { getMaxDimensions } from './useSprites';
import { calculateNegativeSpacing } from './useNegativeSpacing';
export interface CellPosition {
col: number;
@@ -74,17 +75,8 @@ export function useDragSprite(options: DragSpriteOptions) {
lastMaxWidth.value = baseMaxWidth;
lastMaxHeight.value = baseMaxHeight;
// Calculate negative spacing based on sprite size differences
let negativeSpacing = 0;
if (negativeSpacingEnabled && sprites.length > 0) {
// Find the smallest sprite dimensions
const minWidth = Math.min(...sprites.map(s => s.width));
const minHeight = Math.min(...sprites.map(s => s.height));
// Negative spacing is the difference between max and min dimensions
const widthDiff = baseMaxWidth - minWidth;
const heightDiff = baseMaxHeight - minHeight;
negativeSpacing = Math.max(widthDiff, heightDiff);
}
// Calculate negative spacing using shared composable
const negativeSpacing = calculateNegativeSpacing(sprites, negativeSpacingEnabled);
// Add negative spacing to expand each cell
const maxWidth = baseMaxWidth + negativeSpacing;