diff --git a/lib/widgets/draggable_containers/draggable_widget_container.dart b/lib/widgets/draggable_containers/draggable_widget_container.dart index cbfb5446..740747af 100644 --- a/lib/widgets/draggable_containers/draggable_widget_container.dart +++ b/lib/widgets/draggable_containers/draggable_widget_container.dart @@ -26,8 +26,8 @@ class DraggableWidgetContainer extends StatelessWidget { this.updateFunctions, }); - static double snapToGrid(double value, [double? gridSize]) { - gridSize ??= Defaults.gridSize.toDouble(); + static double snapToGrid(double value, [int? gridSize]) { + gridSize ??= Defaults.gridSize; return (value / gridSize).roundToDouble() * gridSize; } diff --git a/lib/widgets/draggable_containers/models/list_layout_model.dart b/lib/widgets/draggable_containers/models/list_layout_model.dart index 9ee32ae6..90556888 100644 --- a/lib/widgets/draggable_containers/models/list_layout_model.dart +++ b/lib/widgets/draggable_containers/models/list_layout_model.dart @@ -499,9 +499,13 @@ class ListLayoutModel extends LayoutContainerModel { } Future(() => setDraggable(true)); + int? gridSize = preferences.getInt(PrefKeys.gridSize); + Rect previewLocation = Rect.fromLTWH( - DraggableWidgetContainer.snapToGrid(widget.draggingRect.left), - DraggableWidgetContainer.snapToGrid(widget.draggingRect.top), + DraggableWidgetContainer.snapToGrid( + widget.draggingRect.left, gridSize), + DraggableWidgetContainer.snapToGrid( + widget.draggingRect.top, gridSize), widget.displayRect.width, widget.displayRect.height, ); diff --git a/lib/widgets/draggable_containers/models/widget_container_model.dart b/lib/widgets/draggable_containers/models/widget_container_model.dart index 4fa34bf0..51847716 100644 --- a/lib/widgets/draggable_containers/models/widget_container_model.dart +++ b/lib/widgets/draggable_containers/models/widget_container_model.dart @@ -141,17 +141,17 @@ abstract class WidgetContainerModel extends ChangeNotifier { @mustCallSuper void updateGridSize(int oldGridSize, int newGridSize) { - double newX = DraggableWidgetContainer.snapToGrid( - displayRect.left, newGridSize.toDouble()); - double newY = DraggableWidgetContainer.snapToGrid( - displayRect.top, newGridSize.toDouble()); - - double newWidth = DraggableWidgetContainer.snapToGrid( - displayRect.width, newGridSize.toDouble()) - .clamp(minWidth, double.infinity); - double newHeight = DraggableWidgetContainer.snapToGrid( - displayRect.height, newGridSize.toDouble()) - .clamp(minHeight, double.infinity); + double newX = + DraggableWidgetContainer.snapToGrid(displayRect.left, newGridSize); + double newY = + DraggableWidgetContainer.snapToGrid(displayRect.top, newGridSize); + + double newWidth = + DraggableWidgetContainer.snapToGrid(displayRect.width, newGridSize) + .clamp(minWidth, double.infinity); + double newHeight = + DraggableWidgetContainer.snapToGrid(displayRect.height, newGridSize) + .clamp(minHeight, double.infinity); displayRect = Rect.fromLTWH(newX, newY, newWidth, newHeight); draggingRect = displayRect; diff --git a/lib/widgets/tab_grid.dart b/lib/widgets/tab_grid.dart index 5ebb7be2..0613040c 100644 --- a/lib/widgets/tab_grid.dart +++ b/lib/widgets/tab_grid.dart @@ -302,24 +302,31 @@ class TabGridModel extends ChangeNotifier { ); } - double previewX = DraggableWidgetContainer.snapToGrid(constrainedRect.left); - double previewY = DraggableWidgetContainer.snapToGrid(constrainedRect.top); + int? gridSize = preferences.getInt(PrefKeys.gridSize); + + double previewX = + DraggableWidgetContainer.snapToGrid(constrainedRect.left, gridSize); + double previewY = + DraggableWidgetContainer.snapToGrid(constrainedRect.top, gridSize); double previewWidth = DraggableWidgetContainer.snapToGrid( - constrainedRect.width.clamp(model.minWidth, double.infinity)); + constrainedRect.width.clamp(model.minWidth, double.infinity), gridSize); double previewHeight = DraggableWidgetContainer.snapToGrid( - constrainedRect.height.clamp(model.minHeight, double.infinity)); + constrainedRect.height.clamp(model.minHeight, double.infinity), + gridSize); if (previewWidth < model.minWidth) { previewWidth = DraggableWidgetContainer.snapToGrid( constrainedRect.width.clamp(model.minWidth, double.infinity) + - (preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize)); + (gridSize ?? Defaults.gridSize), + gridSize); } if (previewHeight < model.minHeight) { previewHeight = DraggableWidgetContainer.snapToGrid( constrainedRect.height.clamp(model.minHeight, double.infinity) + - (preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize)); + (preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize), + gridSize); } Rect preview = @@ -486,8 +493,12 @@ class TabGridModel extends ChangeNotifier { Offset localPosition = getLocalPosition(globalPosition); - double previewX = DraggableWidgetContainer.snapToGrid(localPosition.dx); - double previewY = DraggableWidgetContainer.snapToGrid(localPosition.dy); + int? gridSize = preferences.getInt(PrefKeys.gridSize); + + double previewX = + DraggableWidgetContainer.snapToGrid(localPosition.dx, gridSize); + double previewY = + DraggableWidgetContainer.snapToGrid(localPosition.dy, gridSize); double width = widget.displayRect.width; double height = widget.displayRect.height; @@ -895,10 +906,12 @@ class TabGrid extends StatelessWidget { ), ); - double previewX = - DraggableWidgetContainer.snapToGrid(container.draggingRect.left); - double previewY = - DraggableWidgetContainer.snapToGrid(container.draggingRect.top); + int? gridSize = model.preferences.getInt(PrefKeys.gridSize); + + double previewX = DraggableWidgetContainer.snapToGrid( + container.draggingRect.left, gridSize); + double previewY = DraggableWidgetContainer.snapToGrid( + container.draggingRect.top, gridSize); Rect previewLocation = Rect.fromLTWH(previewX, previewY, container.displayRect.width, container.displayRect.height);