diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index c682f9fac..e0fffb27d 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -74,10 +74,6 @@ const int kDesktopDefaultDisplayHeight = 720; const int kMobileMaxDisplaySize = 1280; const int kDesktopMaxDisplaySize = 3840; -const double kDesktopFileTransferNameColWidth = 200; -const double kDesktopFileTransferModifiedColWidth = 120; -const double kDesktopFileTransferMinimumWidth = 100; -const double kDesktopFileTransferMaximumWidth = 300; const double kDesktopFileTransferRowHeight = 30.0; const double kDesktopFileTransferHeaderHeight = 25.0; @@ -142,6 +138,7 @@ const kRemoteScrollStyleBar = 'scrollbar'; /// [kScrollModeDefault] Mouse or touchpad, the default scroll mode. const kScrollModeDefault = 'default'; + /// [kScrollModeReverse] Mouse or touchpad, the reverse scroll mode. const kScrollModeReverse = 'reverse'; diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart index d684d1535..1ac7987d7 100644 --- a/flutter/lib/desktop/pages/file_manager_page.dart +++ b/flutter/lib/desktop/pages/file_manager_page.dart @@ -364,15 +364,20 @@ class _FileManagerViewState extends State { final _breadCrumbScroller = ScrollController(); final _keyboardNode = FocusNode(); final _listSearchBuffer = TimeoutStringBuffer(); - final _nameColWidth = kDesktopFileTransferNameColWidth.obs; - final _modifiedColWidth = kDesktopFileTransferModifiedColWidth.obs; + final _nameColWidth = 0.0.obs; + final _modifiedColWidth = 0.0.obs; + final _sizeColWidth = 0.0.obs; final _fileListScrollController = ScrollController(); + final _globalHeaderKey = GlobalKey(); /// [_lastClickTime], [_lastClickEntry] help to handle double click var _lastClickTime = DateTime.now().millisecondsSinceEpoch - bind.getDoubleClickTime() - 1000; Entry? _lastClickEntry; + double? _windowWidthPrev; + double _fileTransferMinimumWidth = 0.0; + FileController get controller => widget.controller; bool get isLocal => widget.controller.isLocal; FFI get _ffi => widget._ffi; @@ -398,6 +403,7 @@ class _FileManagerViewState extends State { @override Widget build(BuildContext context) { + _handleColumnPorportions(); return Container( margin: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(8.0), @@ -429,6 +435,27 @@ class _FileManagerViewState extends State { ); } + void _handleColumnPorportions() { + final windowWidthNow = MediaQuery.of(context).size.width; + if (_windowWidthPrev == null) { + _windowWidthPrev = windowWidthNow; + final defaultColumnWidth = windowWidthNow * 0.115; + _fileTransferMinimumWidth = defaultColumnWidth / 3; + _nameColWidth.value = defaultColumnWidth; + _modifiedColWidth.value = defaultColumnWidth; + _sizeColWidth.value = defaultColumnWidth; + } + + if (_windowWidthPrev != windowWidthNow) { + final difference = windowWidthNow / _windowWidthPrev!; + _windowWidthPrev = windowWidthNow; + _fileTransferMinimumWidth *= difference; + _nameColWidth.value *= difference; + _modifiedColWidth.value *= difference; + _sizeColWidth.value *= difference; + } + } + void onLocationFocusChanged() { debugPrint("focus changed on local"); if (_locationNode.hasFocus) { @@ -1143,9 +1170,21 @@ class _FileManagerViewState extends State { return false; } + void _onDrag(double dx, RxDouble column1, RxDouble column2) { + if (column1.value + dx <= _fileTransferMinimumWidth || + column2.value - dx <= _fileTransferMinimumWidth) { + return; + } + column1.value += dx; + column2.value -= dx; + column1.value = max(_fileTransferMinimumWidth, column1.value); + column2.value = max(_fileTransferMinimumWidth, column2.value); + } + Widget _buildFileBrowserHeader(BuildContext context) { final padding = EdgeInsets.all(1.0); return SizedBox( + key: _globalHeaderKey, height: kDesktopFileTransferHeaderHeight, child: Row( children: [ @@ -1155,11 +1194,8 @@ class _FileManagerViewState extends State { ), DraggableDivider( axis: Axis.vertical, - onPointerMove: (dx) { - _nameColWidth.value += dx; - _nameColWidth.value = min(kDesktopFileTransferMaximumWidth, - max(kDesktopFileTransferMinimumWidth, _nameColWidth.value)); - }, + onPointerMove: (dx) => + _onDrag(dx, _nameColWidth, _modifiedColWidth), padding: padding, ), Obx( @@ -1168,15 +1204,12 @@ class _FileManagerViewState extends State { ), DraggableDivider( axis: Axis.vertical, - onPointerMove: (dx) { - _modifiedColWidth.value += dx; - _modifiedColWidth.value = min( - kDesktopFileTransferMaximumWidth, - max(kDesktopFileTransferMinimumWidth, - _modifiedColWidth.value)); - }, + onPointerMove: (dx) => + _onDrag(dx, _modifiedColWidth, _sizeColWidth), padding: padding), - Expanded(child: headerItemFunc(null, SortBy.size, translate("Size"))) + Expanded( + child: headerItemFunc( + _sizeColWidth.value, SortBy.size, translate("Size"))) ], ), ); @@ -1201,23 +1234,20 @@ class _FileManagerViewState extends State { height: kDesktopFileTransferHeaderHeight, child: Row( children: [ - Flexible( - flex: 2, + Expanded( child: Text( name, style: headerTextStyle, overflow: TextOverflow.ellipsis, - ).marginSymmetric(horizontal: 4), + ).marginOnly(left: 4), ), - Flexible( - flex: 1, - child: ascending.value != null - ? Icon( - ascending.value! - ? Icons.keyboard_arrow_up_rounded - : Icons.keyboard_arrow_down_rounded, - ) - : const Offstage()) + ascending.value != null + ? Icon( + ascending.value! + ? Icons.keyboard_arrow_up_rounded + : Icons.keyboard_arrow_down_rounded, + ) + : SizedBox() ], ), ),