From bcd1827d8a4db6d2c232815d6dd3462807b01e96 Mon Sep 17 00:00:00 2001 From: NicKoehler Date: Sat, 16 Sep 2023 11:54:17 +0200 Subject: [PATCH 1/2] Changed columns and window behaviour when resized --- flutter/lib/consts.dart | 5 +- .../lib/desktop/pages/file_manager_page.dart | 86 ++++++++++++++----- 2 files changed, 66 insertions(+), 25 deletions(-) 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..3a42d2191 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; @@ -1145,7 +1150,27 @@ class _FileManagerViewState extends State { Widget _buildFileBrowserHeader(BuildContext context) { final padding = EdgeInsets.all(1.0); + final windowWidthNow = MediaQuery.of(context).size.width; + if (_windowWidthPrev == null) { + _windowWidthPrev = windowWidthNow; + final defaultColumnWidth = windowWidthNow * 0.34 / 3; + _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; + } + return SizedBox( + key: _globalHeaderKey, height: kDesktopFileTransferHeaderHeight, child: Row( children: [ @@ -1156,9 +1181,20 @@ class _FileManagerViewState extends State { DraggableDivider( axis: Axis.vertical, onPointerMove: (dx) { + if (_nameColWidth.value + dx <= _fileTransferMinimumWidth) { + return; + } + + if (_modifiedColWidth.value - dx <= _fileTransferMinimumWidth) { + return; + } + _nameColWidth.value += dx; - _nameColWidth.value = min(kDesktopFileTransferMaximumWidth, - max(kDesktopFileTransferMinimumWidth, _nameColWidth.value)); + _nameColWidth.value = + max(_fileTransferMinimumWidth, _nameColWidth.value); + _modifiedColWidth.value -= dx; + _modifiedColWidth.value = + max(_fileTransferMinimumWidth, _modifiedColWidth.value); }, padding: padding, ), @@ -1169,14 +1205,25 @@ class _FileManagerViewState extends State { DraggableDivider( axis: Axis.vertical, onPointerMove: (dx) { + if (_modifiedColWidth.value + dx <= _fileTransferMinimumWidth) { + return; + } + + if (_sizeColWidth.value - dx <= _fileTransferMinimumWidth) { + return; + } + _modifiedColWidth.value += dx; - _modifiedColWidth.value = min( - kDesktopFileTransferMaximumWidth, - max(kDesktopFileTransferMinimumWidth, - _modifiedColWidth.value)); + _modifiedColWidth.value = + max(_fileTransferMinimumWidth, _modifiedColWidth.value); + _sizeColWidth.value -= dx; + _sizeColWidth.value = + max(_fileTransferMinimumWidth, _sizeColWidth.value); }, padding: padding), - Expanded(child: headerItemFunc(null, SortBy.size, translate("Size"))) + Expanded( + child: headerItemFunc( + _sizeColWidth.value, SortBy.size, translate("Size"))) ], ), ); @@ -1201,23 +1248,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() ], ), ), From 780d64a34946fc202e25299cbd72cd0ded76157e Mon Sep 17 00:00:00 2001 From: NicKoehler Date: Sat, 16 Sep 2023 12:28:00 +0200 Subject: [PATCH 2/2] refactor functions --- .../lib/desktop/pages/file_manager_page.dart | 88 ++++++++----------- 1 file changed, 37 insertions(+), 51 deletions(-) diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart index 3a42d2191..1ac7987d7 100644 --- a/flutter/lib/desktop/pages/file_manager_page.dart +++ b/flutter/lib/desktop/pages/file_manager_page.dart @@ -403,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), @@ -434,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) { @@ -1148,27 +1170,19 @@ 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); - final windowWidthNow = MediaQuery.of(context).size.width; - if (_windowWidthPrev == null) { - _windowWidthPrev = windowWidthNow; - final defaultColumnWidth = windowWidthNow * 0.34 / 3; - _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; - } - return SizedBox( key: _globalHeaderKey, height: kDesktopFileTransferHeaderHeight, @@ -1180,22 +1194,8 @@ class _FileManagerViewState extends State { ), DraggableDivider( axis: Axis.vertical, - onPointerMove: (dx) { - if (_nameColWidth.value + dx <= _fileTransferMinimumWidth) { - return; - } - - if (_modifiedColWidth.value - dx <= _fileTransferMinimumWidth) { - return; - } - - _nameColWidth.value += dx; - _nameColWidth.value = - max(_fileTransferMinimumWidth, _nameColWidth.value); - _modifiedColWidth.value -= dx; - _modifiedColWidth.value = - max(_fileTransferMinimumWidth, _modifiedColWidth.value); - }, + onPointerMove: (dx) => + _onDrag(dx, _nameColWidth, _modifiedColWidth), padding: padding, ), Obx( @@ -1204,22 +1204,8 @@ class _FileManagerViewState extends State { ), DraggableDivider( axis: Axis.vertical, - onPointerMove: (dx) { - if (_modifiedColWidth.value + dx <= _fileTransferMinimumWidth) { - return; - } - - if (_sizeColWidth.value - dx <= _fileTransferMinimumWidth) { - return; - } - - _modifiedColWidth.value += dx; - _modifiedColWidth.value = - max(_fileTransferMinimumWidth, _modifiedColWidth.value); - _sizeColWidth.value -= dx; - _sizeColWidth.value = - max(_fileTransferMinimumWidth, _sizeColWidth.value); - }, + onPointerMove: (dx) => + _onDrag(dx, _modifiedColWidth, _sizeColWidth), padding: padding), Expanded( child: headerItemFunc(