Skip to content

Commit

Permalink
Tabbed view update (#36)
Browse files Browse the repository at this point in the history
* Compiling with tabbed_view 1.18.0

* Adapting code for tabbed_view 1.18.0 changes. #31

* Adding the tab index in the layout change algorithm. #31

* Adjusting DockingItem to use HitTestBehavior.translucent and allow
components to receive mouse events. #31

* Adding and updating tests. #31

* Updating the CHANGELOG

* Formatting
  • Loading branch information
caduandrade committed Sep 13, 2023
1 parent 47eb4fb commit cd480e6
Show file tree
Hide file tree
Showing 21 changed files with 775 additions and 320 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## 1.12.2
## 1.12.0

* `tabbed_view` dependency updated to 1.18.0
* Tab reordering
* `DropPosition`
* The `center` value has been removed.
* `DockingLayout`
* Methods `addItemOnRoot`, `addItemOn` and `moveItem`
* New optional parameter: `dropIndex`
* The `dropPostion` parameter has become optional.

## 1.11.2

* Bugfix
* Error with GlobalKey when expanding a DockingTabs.
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.11.1"
version: "1.12.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -147,10 +147,10 @@ packages:
dependency: transitive
description:
name: tabbed_view
sha256: dfe40dc579f92cb421b51310a6320cf3239492ed5b198f1a290c81726b2a33c8
sha256: "467fff7781d38592f47ce06bd48347b97d26e2823650a736fa6fcaaefe88e894"
url: "https://pub.dev"
source: hosted
version: "1.16.0+1"
version: "1.18.0"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -185,4 +185,4 @@ packages:
version: "0.1.4-beta"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=1.17.0"
flutter: ">=2.17.0"
6 changes: 4 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"

dependencies:
flutter:
sdk: flutter
docking:
docking: #^1.11.0
path: ../
#tabbed_view: ^1.16.0


dev_dependencies:
flutter_test:
Expand Down
6 changes: 6 additions & 0 deletions lib/src/internal/debug.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:meta/meta.dart';

@internal
class DockingDebug {
static const bool dropAreaVisible = false;
}
27 changes: 27 additions & 0 deletions lib/src/internal/docking_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:docking/src/docking_buttons_builder.dart';
import 'package:docking/src/layout/docking_layout.dart';
import 'package:docking/src/on_item_close.dart';
import 'package:docking/src/on_item_selection.dart';

class DockingProvider {
const DockingProvider(
{required this.layout,
required this.onItemSelection,
required this.onItemClose,
required this.itemCloseInterceptor,
required this.dockingButtonsBuilder,
required this.maximizableItem,
required this.maximizableTab,
required this.maximizableTabsArea,
required this.antiAliasingWorkaround});

final DockingLayout? layout;
final OnItemSelection? onItemSelection;
final OnItemClose? onItemClose;
final ItemCloseInterceptor? itemCloseInterceptor;
final DockingButtonsBuilder? dockingButtonsBuilder;
final bool maximizableItem;
final bool maximizableTab;
final bool maximizableTabsArea;
final bool antiAliasingWorkaround;
}
6 changes: 4 additions & 2 deletions lib/src/internal/layout/add_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class AddItem extends DropItem {
AddItem(
{required DockingItem newItem,
required DropArea targetArea,
required DropPosition dropPosition})
DropPosition? dropPosition,
int? dropIndex})
: super(
dropItem: newItem,
targetArea: targetArea,
dropPosition: dropPosition);
dropPosition: dropPosition,
dropIndex: dropIndex);

@override
void validateDropItem(DockingLayout layout, DockingArea area) {
Expand Down
52 changes: 43 additions & 9 deletions lib/src/internal/layout/drop_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ class DropItem extends LayoutModifier {
DropItem(
{required this.dropItem,
required this.targetArea,
required this.dropPosition});
required this.dropPosition,
required this.dropIndex}) {
if ((dropIndex == null && dropPosition == null) ||
(dropIndex != null && dropPosition != null)) {
throw ArgumentError(
'Only one of the dropIndex and dropPosition parameters can be set.');
}
}

final DockingItem dropItem;
final DropArea targetArea;
final DropPosition dropPosition;
final DropPosition? dropPosition;
final int? dropIndex;

@override
DockingArea? newLayout(DockingLayout layout) {
Expand Down Expand Up @@ -52,7 +60,9 @@ class DropItem extends LayoutModifier {
return null;
} else if (dockingItem == targetArea) {
final DockingItem newDraggedItem = dropItem;
if (dropPosition == DropPosition.center) {
if (dropIndex == 0) {
return DockingTabs([newDraggedItem, dockingItem]);
} else if (dropIndex == 1) {
return DockingTabs([dockingItem, newDraggedItem]);
} else if (dropPosition == DropPosition.top) {
return DockingColumn([newDraggedItem, dockingItem]);
Expand All @@ -71,29 +81,53 @@ class DropItem extends LayoutModifier {
} else if (area is DockingTabs) {
final DockingTabs dockingTabs = area;
List<DockingItem> children = [];
dockingTabs.forEach((child) {
DockingItem? oldSelection;
int oldIndex = -1;
for (int index = 0; index < dockingTabs.childrenCount; index++) {
DockingItem child = dockingTabs.childAt(index);
if (child == targetArea) {
throw ArgumentError('Nested tabbed panels are not allowed.');
}
if (child != dropItem) {
children.add(child);
} else {
oldIndex = index;
}
});
if (index == dockingTabs.selectedIndex) {
oldSelection = child;
}
}
final DockingArea? newArea;
if (children.length == 1) {
newArea = children.first;
} else {
newArea = DockingTabs(children,
maximized: dockingTabs.maximized,
maximizable: dockingTabs.maximizable);
(newArea as DockingTabs).selectedIndex = dockingTabs.selectedIndex;
if (oldSelection != null) {
int newSelectedIndex = children.indexOf(oldSelection);
(newArea as DockingTabs).selectedIndex =
newSelectedIndex > -1 ? newSelectedIndex : 0;
}
}
if (dockingTabs == targetArea) {
DockingItem newDraggedItem = dropItem;
if (dropPosition == DropPosition.center) {
children.add(newDraggedItem);
if (dropIndex != null) {
int newIndex = dropIndex!;
if (oldIndex > -1) {
if (newIndex > 0) {
newIndex--;
}
children.insert(newIndex, newDraggedItem);
} else {
children.insert(newIndex, newDraggedItem);
}
DockingTabs newDockingTabs = DockingTabs(children);
newDockingTabs.selectedIndex = dockingTabs.selectedIndex;
if (oldSelection != null) {
int newSelectedIndex = children.indexOf(oldSelection);
newDockingTabs.selectedIndex =
newSelectedIndex > -1 ? newSelectedIndex : 0;
}
return newDockingTabs;
} else if (dropPosition == DropPosition.top) {
return DockingColumn([newDraggedItem, newArea]);
Expand Down
6 changes: 4 additions & 2 deletions lib/src/internal/layout/move_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class MoveItem extends DropItem {
MoveItem(
{required DockingItem draggedItem,
required DropArea targetArea,
required DropPosition dropPosition})
required DropPosition? dropPosition,
required int? dropIndex})
: super(
dropItem: draggedItem,
targetArea: targetArea,
dropPosition: dropPosition);
dropPosition: dropPosition,
dropIndex: dropIndex);

@override
void validate(DockingLayout layout, DockingArea area) {
Expand Down
Loading

0 comments on commit cd480e6

Please sign in to comment.