Skip to content

Commit

Permalink
Fix widget grid scaling when dragging in (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 authored Jul 20, 2024
1 parent 49a2da3 commit 0166c29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
22 changes: 18 additions & 4 deletions lib/services/nt_widget_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,13 @@ class NTWidgetBuilder {
static double getDefaultWidth(NTWidgetModel widget) {
ensureInitialized();

double snappedNormal = DraggableWidgetContainer.snapToGrid(_normalSize)
.clamp(128.0, double.infinity);
double snappedNormal = DraggableWidgetContainer.snapToGrid(
_normalSize, widget.preferences.getInt(PrefKeys.gridSize));

if (snappedNormal < _normalSize) {
snappedNormal +=
widget.preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize;
}

if (_defaultWidthMap.containsKey(widget.type)) {
return snappedNormal * _defaultWidthMap[widget.type]!;
Expand All @@ -427,12 +432,21 @@ class NTWidgetBuilder {
static double getDefaultHeight(NTWidgetModel widget) {
ensureInitialized();

double snappedNormal = DraggableWidgetContainer.snapToGrid(_normalSize)
.clamp(128.0, double.infinity);
double snappedNormal = DraggableWidgetContainer.snapToGrid(
_normalSize, widget.preferences.getInt(PrefKeys.gridSize));

if (snappedNormal < _normalSize) {
snappedNormal +=
widget.preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize;
}

if (_defaultHeightMap.containsKey(widget.type)) {
return snappedNormal * _defaultHeightMap[widget.type]!;
}
return snappedNormal;
}

static double getNormalSize([int? gridSize]) {
return DraggableWidgetContainer.snapToGrid(_normalSize, gridSize);
}
}
7 changes: 3 additions & 4 deletions lib/widgets/tab_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:elastic_dashboard/services/nt_connection.dart';
import 'package:elastic_dashboard/services/nt_widget_builder.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_list_layout.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_nt_widget_container.dart';
Expand Down Expand Up @@ -550,11 +551,9 @@ class TabGridModel extends ChangeNotifier {
initialPosition: Rect.fromLTWH(
0.0,
0.0,
(preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize)
.toDouble() *
NTWidgetBuilder.getNormalSize(preferences.getInt(PrefKeys.gridSize)) *
2,
(preferences.getInt(PrefKeys.gridSize) ?? Defaults.gridSize)
.toDouble() *
NTWidgetBuilder.getNormalSize(preferences.getInt(PrefKeys.gridSize)) *
2,
),
children: children,
Expand Down

0 comments on commit 0166c29

Please sign in to comment.