Skip to content

Commit

Permalink
Reusing the weights when rebuilding the layout. #38
Browse files Browse the repository at this point in the history
  • Loading branch information
caduandrade committed Nov 10, 2023
1 parent baf02b8 commit 7800713
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.14.1

* Bugfix
* Fixing the issue that reset the weight after using the `DockingLayout.addItemOn` method.

## 1.14.0

* The `id` attribute has been moved from the `DockingItem` to the `DockingArea`.
Expand Down
53 changes: 43 additions & 10 deletions lib/src/internal/layout/drop_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,35 @@ class DropItem extends LayoutModifier {
} else if (dockingItem == targetArea) {
final DockingItem newDraggedItem = dropItem;
if (dropIndex == 0) {
return DockingTabs([newDraggedItem, dockingItem]);
return DockingTabs([newDraggedItem, dockingItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else if (dropIndex == 1) {
return DockingTabs([dockingItem, newDraggedItem]);
return DockingTabs([dockingItem, newDraggedItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else if (dropPosition == DropPosition.top) {
return DockingColumn([newDraggedItem, dockingItem]);
return DockingColumn([newDraggedItem, dockingItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else if (dropPosition == DropPosition.bottom) {
return DockingColumn([dockingItem, newDraggedItem]);
return DockingColumn([dockingItem, newDraggedItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else if (dropPosition == DropPosition.left) {
return DockingRow([newDraggedItem, dockingItem]);
return DockingRow([newDraggedItem, dockingItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else if (dropPosition == DropPosition.right) {
return DockingRow([dockingItem, newDraggedItem]);
return DockingRow([dockingItem, newDraggedItem],
weight: dockingItem.weight,
minimalSize: dockingItem.minimalSize,
minimalWeight: dockingItem.minimalWeight);
} else {
throw ArgumentError(
'DropPosition not recognized: ' + dropPosition.toString());
Expand All @@ -81,6 +99,7 @@ class DropItem extends LayoutModifier {
return area;
} else if (area is DockingTabs) {
final DockingTabs dockingTabs = area;
print('${dockingTabs.index}: ${dockingTabs.weight}');
List<DockingItem> children = [];
DockingItem? oldSelection;
int oldIndex = -1;
Expand All @@ -104,7 +123,10 @@ class DropItem extends LayoutModifier {
} else {
newArea = DockingTabs(children,
maximized: dockingTabs.maximized,
maximizable: dockingTabs.maximizable);
maximizable: dockingTabs.maximizable,
weight: dockingTabs.weight,
minimalWeight: dockingTabs.minimalWeight,
minimalSize: dockingTabs.minimalSize);
if (oldSelection != null) {
int newSelectedIndex = children.indexOf(oldSelection);
(newArea as DockingTabs).selectedIndex =
Expand All @@ -123,7 +145,12 @@ class DropItem extends LayoutModifier {
} else {
children.insert(newIndex, newDraggedItem);
}
DockingTabs newDockingTabs = DockingTabs(children);
DockingTabs newDockingTabs = DockingTabs(children,
maximized: dockingTabs.maximized,
maximizable: dockingTabs.maximizable,
weight: dockingTabs.weight,
minimalWeight: dockingTabs.minimalWeight,
minimalSize: dockingTabs.minimalSize);
if (oldSelection != null) {
int newSelectedIndex = children.indexOf(oldSelection);
newDockingTabs.selectedIndex =
Expand Down Expand Up @@ -158,9 +185,15 @@ class DropItem extends LayoutModifier {
return children.first;
}
if (area is DockingRow) {
return DockingRow(children);
return DockingRow(children,
weight: area.weight,
minimalWeight: area.minimalWeight,
minimalSize: area.minimalSize);
} else if (area is DockingColumn) {
return DockingColumn(children);
return DockingColumn(children,
weight: area.weight,
minimalWeight: area.minimalWeight,
minimalSize: area.minimalSize);
}
throw StateError(
'DockingArea class not recognized: ' + area.runtimeType.toString());
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: docking
description: Flutter layout for placing widgets in docking areas and arrange them into split and tabbed views.
version: 1.14.0
version: 1.14.1
homepage: https://caduandrade.github.io/docking_flutter/
repository: https://github.com/caduandrade/docking_flutter

Expand Down

0 comments on commit 7800713

Please sign in to comment.