handlePointerMove method
Implementation
void handlePointerMove(PointerMoveEvent event) {
if (draggingItemId.value != null) {
// If we have multiple items selected, move all of them
if (selectedItemIds.isNotEmpty) {
for (var itemId in selectedItemIds) {
final index = items.indexWhere((item) => item.id == itemId);
if (index == -1) continue;
final item = items[index];
// Check if the item is a table component
if (_isTableComponent(item.label)) {
// For table components, ensure they stay within table bounds
final newY = (item.positionY ?? 0) + event.delta.dy;
if (!_isWithinTableBounds(newY)) continue;
}
final Offset currentVisualPosition = Offset(
(item.positionX ?? 0) + event.delta.dx,
(item.positionY ?? 0) + event.delta.dy);
final sectionY = sectionYPositions[item.section!]!;
final sectionHeight = _getSectionHeight(item.section!);
// Constrain item within its section and table bounds if it's a table component
final double constrainedX =
currentVisualPosition.dx.clamp(0.0, 595 - (item.width ?? 100));
double constrainedY = currentVisualPosition.dy
.clamp(sectionY, sectionY + sectionHeight - (item.height ?? 25));
if (_isTableComponent(item.label)) {
constrainedY = constrainedY.clamp(
tableStartY.value, tableEndY.value - (item.height ?? 25));
}
items[index] = PrinterDesignerPackageListModel(
id: item.id,
type: item.type,
label: item.label,
prefix: item.prefix,
value: item.value,
imageUrl: item.imageUrl,
positionX: constrainedX,
positionY: constrainedY,
height: item.height,
width: item.width,
section: item.section,
isSelected: item.isSelected,
customText: item.customText,
properties: item.properties,
);
}
} else {
// Single item movement (existing code)
final index =
items.indexWhere((item) => item.id == draggingItemId.value);
if (index == -1) return;
final item = items[index];
// Check if the item is a table component
if (_isTableComponent(item.label)) {
// For table components, ensure they stay within table bounds
final newY = (item.positionY ?? 0) + event.delta.dy;
if (!_isWithinTableBounds(newY)) return;
}
final Offset currentVisualPosition = Offset(
(item.positionX ?? 0) + event.delta.dx,
(item.positionY ?? 0) + event.delta.dy);
final sectionY = sectionYPositions[item.section!]!;
final sectionHeight = _getSectionHeight(item.section!);
// Constrain item within its section and table bounds if it's a table component
final double constrainedX =
currentVisualPosition.dx.clamp(0.0, 595 - (item.width ?? 100));
double constrainedY = currentVisualPosition.dy
.clamp(sectionY, sectionY + sectionHeight - (item.height ?? 25));
if (_isTableComponent(item.label)) {
constrainedY = constrainedY.clamp(
tableStartY.value, tableEndY.value - (item.height ?? 25));
}
items[index] = PrinterDesignerPackageListModel(
id: item.id,
type: item.type,
label: item.label,
prefix: item.prefix,
value: item.value,
imageUrl: item.imageUrl,
positionX: constrainedX,
positionY: constrainedY,
height: item.height,
width: item.width,
section: item.section,
isSelected: item.isSelected,
customText: item.customText,
properties: item.properties,
);
}
}
}