Skip to content

Commit

Permalink
feat(bosskmk#212): support drop to resize when no enable context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcb33 authored and bosskmk committed Jun 26, 2021
1 parent bb76711 commit 667ef71
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/model/pluto_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class PlutoColumn {
/// Displays the right icon of the column title.
bool enableContextMenu;

/// Diaplay the right icon for drop to resize the column
/// Valid only when [enableContextMenu] is noactivated.
bool enableDropToResize;

/// Displays filter-related menus in the column context menu.
/// Valid only when [enableContextMenu] is activated.
bool enableFilterMenuItem;
Expand Down Expand Up @@ -91,6 +95,7 @@ class PlutoColumn {
this.enableRowChecked = false,
this.enableSorting = true,
this.enableContextMenu = true,
this.enableDropToResize = false,
this.enableFilterMenuItem = true,
this.enableHideColumnMenuItem = true,
this.enableSetColumnsMenuItem = true,
Expand Down
30 changes: 30 additions & 0 deletions lib/src/ui/columns/pluto_column_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ class _PlutoColumnTitleState extends _PlutoColumnTitleStateWithChange {
_showContextMenu(context, details.globalPosition);
}

void _handleOnHorizontalResizeDragStart(DragStartDetails details) {
_currentPosition = details.localPosition;
}

void _handleOnHorizontalResizeDragUpdate(DragUpdateDetails details) {
_currentPosition = details.localPosition;
widget.stateManager.resizeColumn(widget.column.key, details.delta.dx);
}

void _handleOnHorizontalResizeDragEnd(DragEndDetails details) {
widget.stateManager
.resizeColumn(widget.column.key, _currentPosition.dx - 20);
}

void _handleOnHorizontalDragUpdateContextMenu(DragUpdateDetails details) {
_currentPosition = details.localPosition;
}
Expand Down Expand Up @@ -136,6 +150,22 @@ class _PlutoColumnTitleState extends _PlutoColumnTitleStateWithChange {
)
: _contextMenuIcon,
),
if (!(widget.column.enableContextMenu || !widget.column.sort.isNone) &&
widget.column.enableDropToResize)
Positioned(
right: -1,
child: GestureDetector(
onHorizontalDragStart: _handleOnHorizontalResizeDragStart,
onHorizontalDragUpdate: _handleOnHorizontalResizeDragUpdate,
child: Container(
height: widget.stateManager.columnHeight,
alignment: Alignment.center,
child: IconButton(
icon: const Icon(Icons.code_sharp),
iconSize: widget.stateManager.configuration!.iconSize,
onPressed: null,
)),
)),
],
);
}
Expand Down

0 comments on commit 667ef71

Please sign in to comment.