Skip to content

Commit de0ea8c

Browse files
committed
Support for ListView
1 parent ad7a17f commit de0ea8c

File tree

6 files changed

+55
-70
lines changed

6 files changed

+55
-70
lines changed

src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Files.App.Data.Enums;
5-
using System.Text.Json;
6-
using Windows.Storage;
74
using Windows.Win32;
85

96
namespace Files.App.Helpers
@@ -205,49 +202,6 @@ public LayoutPreferencesManager(FolderLayoutModes modeOverride) : this()
205202

206203
// Methods
207204

208-
/// <summary>
209-
/// This will round the current icon size to get the best result from the File Explorer thumbnail system.
210-
///
211-
/// Details View:
212-
/// Always uses the Large icon size (32).
213-
///
214-
/// List View:
215-
/// Always uses the Large icon size (32).
216-
///
217-
/// Columns View:
218-
/// Always uses the Large icon size (32).
219-
///
220-
/// Tiles View:
221-
/// Always uses 96, 128, or 256 depending on the layout size.
222-
///
223-
/// Grid View:
224-
/// Always uses 96, 128, or 256 depending on the layout size.
225-
/// </summary>
226-
public uint GetRoundedIconSize()
227-
{
228-
return LayoutMode switch
229-
{
230-
_ when LayoutMode == FolderLayoutModes.DetailsView && UserSettingsService.LayoutSettingsService.DetailsViewSize <= DetailsViewSizeKind.Small
231-
=> Constants.ShellIconSizes.Small,
232-
_ when LayoutMode == FolderLayoutModes.DetailsView && UserSettingsService.LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Medium
233-
=> 20,
234-
_ when LayoutMode == FolderLayoutModes.DetailsView && UserSettingsService.LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Large
235-
=> 24,
236-
_ when LayoutMode == FolderLayoutModes.DetailsView && UserSettingsService.LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.ExtraLarge
237-
=> Constants.ShellIconSizes.Large,
238-
FolderLayoutModes.ListView
239-
=> Constants.ShellIconSizes.Large,
240-
FolderLayoutModes.ColumnView
241-
=> Constants.ShellIconSizes.Large,
242-
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small ||
243-
LayoutMode == FolderLayoutModes.TilesView
244-
=> 96,
245-
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Large
246-
=> 128,
247-
_ => 256,
248-
};
249-
}
250-
251205
public Type GetLayoutType(string path, bool changeLayoutMode = true)
252206
{
253207
var preferencesItem = GetLayoutPreferencesForPath(path);

src/Files.App/Helpers/Layout/LayoutSizeKindHelper.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,41 @@ public static int GetListViewRowHeight(ListViewSizeKind listViewSizeKind)
9393
}
9494
}
9595

96+
/// <summary>
97+
/// Gets the desired icon size for specified layout
98+
/// </summary>
99+
/// <param name="listViewSizeKind"></param>
100+
/// <returns></returns>
101+
public static uint GetIconSize(FolderLayoutModes folderLayoutMode)
102+
{
103+
return folderLayoutMode switch
104+
{
105+
// Details
106+
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Compact => Constants.ShellIconSizes.Small,
107+
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Small => Constants.ShellIconSizes.Small,
108+
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Medium => 20,
109+
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Large => 24,
110+
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,
111+
112+
// List
113+
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Compact => Constants.ShellIconSizes.Small,
114+
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Small => Constants.ShellIconSizes.Small,
115+
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Medium => 20,
116+
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Large => 24,
117+
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,
118+
119+
// Columns
120+
FolderLayoutModes.ColumnView => Constants.ShellIconSizes.Large,
121+
122+
// Grid and Tiles
123+
FolderLayoutModes.GridView when LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small => 96,
124+
FolderLayoutModes.TilesView => 96,
125+
FolderLayoutModes.GridView when LayoutSettingsService.GridViewSize <= GridViewSizeKind.Large => 128,
126+
127+
_ => 256,
128+
};
129+
}
130+
96131
/// <summary>
97132
/// Gets the desired height for items in the Columns View
98133
/// </summary>

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ private async Task<BitmapImage> GetShieldIcon()
973973
private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancellationToken)
974974
{
975975
var loadNonCachedThumbnail = false;
976-
var thumbnailSize = folderSettings.GetRoundedIconSize();
976+
var thumbnailSize = LayoutSizeKindHelper.GetIconSize(folderSettings.LayoutMode);
977977
var returnIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 48;
978-
var useCurrentScale = folderSettings.LayoutMode == FolderLayoutModes.DetailsView;
978+
var useCurrentScale = folderSettings.LayoutMode == FolderLayoutModes.DetailsView || folderSettings.LayoutMode == FolderLayoutModes.ListView;
979979

980980
byte[]? result = null;
981981

src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
137137

138138
base.OnNavigatedTo(eventArgs);
139139

140-
currentIconSize = FolderSettings.GetRoundedIconSize();
140+
currentIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView);
141141

142142
if (FolderSettings?.ColumnsViewModel is not null)
143143
{
@@ -210,7 +210,7 @@ private async void LayoutSettingsService_PropertyChanged(object? sender, Propert
210210
ContentScroller?.ChangeView(null, previousOffset, null);
211211

212212
// Reload icons with correct size but only if the size changed
213-
var requestedIconSize = FolderSettings.GetRoundedIconSize();
213+
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView);
214214
if (requestedIconSize != currentIconSize)
215215
{
216216
currentIconSize = requestedIconSize;
@@ -268,17 +268,7 @@ private void SetItemContainerStyle()
268268
}
269269

270270
// Set icon column width
271-
var iconColumnWidth = UserSettingsService.LayoutSettingsService.DetailsViewSize switch
272-
{
273-
DetailsViewSizeKind.Compact => new GridLength(20),
274-
DetailsViewSizeKind.Small => new GridLength(20),
275-
DetailsViewSizeKind.Medium => new GridLength(24),
276-
DetailsViewSizeKind.Large => new GridLength(28),
277-
DetailsViewSizeKind.ExtraLarge => new GridLength(36),
278-
_ => new GridLength(20)
279-
};
280-
281-
ColumnsViewModel.IconColumn.UserLength = iconColumnWidth;
271+
ColumnsViewModel.IconColumn.UserLength = new GridLength(LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView) + 4);
282272
}
283273

284274
private void FileList_LayoutUpdated(object? sender, object e)

src/Files.App/Views/Layouts/GridLayoutPage.xaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@
302302
<!-- Thumbnail -->
303303
<Grid
304304
x:Name="IconBox"
305-
Width="24"
306-
Height="24"
305+
Width="{Binding IconBoxSizeListView, ElementName=PageRoot, Mode=OneWay}"
306+
Height="{Binding IconBoxSizeListView, ElementName=PageRoot, Mode=OneWay}"
307307
HorizontalAlignment="Center"
308308
VerticalAlignment="Center"
309309
AutomationProperties.Name="{helpers:ResourceString Name=FileBrowserThumbnailIconColumnGrid/AutomationProperties/Name}"
@@ -312,8 +312,7 @@
312312
Tag="ItemImage">
313313
<ContentPresenter
314314
x:Name="PicturePresenter"
315-
Width="20"
316-
Height="20"
315+
Margin="2"
317316
HorizontalAlignment="Center"
318317
VerticalAlignment="Center"
319318
x:Load="{x:Bind LoadFileIcon, Mode=OneWay}"

src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public int RowHeightListView
4141
{
4242
get => LayoutSizeKindHelper.GetListViewRowHeight(UserSettingsService.LayoutSettingsService.ListViewSize);
4343
}
44+
45+
/// <summary>
46+
/// Icon Box size in the List View layout. The value is increased by 4px to account for icon overlays.
47+
/// </summary>
48+
public int IconBoxSizeListView
49+
{
50+
get => (int)(LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.ListView) + 4);
51+
}
4452

4553
/// <summary>
4654
/// Item width in the Tiles View layout
@@ -127,7 +135,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
127135

128136
base.OnNavigatedTo(eventArgs);
129137

130-
currentIconSize = FolderSettings.GetRoundedIconSize();
138+
currentIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);
131139

132140
FolderSettings.LayoutModeChangeRequested -= FolderSettings_LayoutModeChangeRequested;
133141
FolderSettings.LayoutModeChangeRequested += FolderSettings_LayoutModeChangeRequested;
@@ -162,10 +170,10 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang
162170
if (e.PropertyName == nameof(ILayoutSettingsService.ListViewSize))
163171
{
164172
NotifyPropertyChanged(nameof(RowHeightListView));
173+
NotifyPropertyChanged(nameof(IconBoxSizeListView));
165174

166175
// Update the container style to match the item size
167176
SetItemContainerStyle();
168-
169177
FolderSettings_IconHeightChanged();
170178
}
171179
if (e.PropertyName == nameof(ILayoutSettingsService.TilesViewSize))
@@ -182,7 +190,6 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang
182190

183191
// Update the container style to match the item size
184192
SetItemContainerStyle();
185-
186193
FolderSettings_IconHeightChanged();
187194
}
188195

@@ -200,7 +207,7 @@ private async void FolderSettings_LayoutModeChangeRequested(object? sender, Layo
200207
SetItemTemplate();
201208
SetItemContainerStyle();
202209

203-
var requestedIconSize = FolderSettings.GetRoundedIconSize();
210+
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);
204211
if (requestedIconSize != currentIconSize)
205212
{
206213
currentIconSize = requestedIconSize;
@@ -491,7 +498,7 @@ protected override bool CanGetItemFromElement(object element)
491498
private async void FolderSettings_IconHeightChanged()
492499
{
493500
// Get new icon size
494-
var requestedIconSize = FolderSettings.GetRoundedIconSize();
501+
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);
495502

496503
// Prevents reloading icons when the icon size hasn't changed
497504
if (requestedIconSize != currentIconSize)

0 commit comments

Comments
 (0)