Skip to content

Commit b80fa47

Browse files
committed
Feature: Use DPI aware icons in the Details View
1 parent e8ed94d commit b80fa47

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ public uint GetRoundedIconSize()
227227
{
228228
return LayoutMode switch
229229
{
230-
FolderLayoutModes.DetailsView
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
231237
=> Constants.ShellIconSizes.Large,
232238
FolderLayoutModes.ListView
233239
=> Constants.ShellIconSizes.Large,

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
975975
var loadNonCachedThumbnail = false;
976976
var thumbnailSize = folderSettings.GetRoundedIconSize();
977977
var returnIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 48;
978+
var useCurrentScale = folderSettings.LayoutMode == FolderLayoutModes.DetailsView;
978979

979980
byte[]? result = null;
980981

@@ -988,7 +989,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
988989
item.ItemPath,
989990
thumbnailSize,
990991
item.IsFolder,
991-
IconOptions.ReturnThumbnailOnly | IconOptions.ReturnOnlyIfCached);
992+
IconOptions.ReturnThumbnailOnly | IconOptions.ReturnOnlyIfCached | (useCurrentScale ? IconOptions.UseCurrentScale : 0));
992993

993994
cancellationToken.ThrowIfCancellationRequested();
994995
loadNonCachedThumbnail = true;
@@ -1001,7 +1002,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
10011002
item.ItemPath,
10021003
thumbnailSize,
10031004
item.IsFolder,
1004-
IconOptions.ReturnIconOnly);
1005+
IconOptions.ReturnIconOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0));
10051006

10061007
cancellationToken.ThrowIfCancellationRequested();
10071008
}
@@ -1013,7 +1014,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
10131014
item.ItemPath,
10141015
thumbnailSize,
10151016
item.IsFolder,
1016-
returnIconOnly ? IconOptions.ReturnIconOnly : IconOptions.None);
1017+
returnIconOnly ? IconOptions.ReturnIconOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0) : (useCurrentScale ? IconOptions.UseCurrentScale : 0));
10171018

10181019
cancellationToken.ThrowIfCancellationRequested();
10191020
}
@@ -1059,7 +1060,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
10591060
item.ItemPath,
10601061
thumbnailSize,
10611062
item.IsFolder,
1062-
IconOptions.ReturnThumbnailOnly);
1063+
IconOptions.ReturnThumbnailOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0));
10631064
}
10641065
finally
10651066
{

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,16 @@
903903
Loaded="StackPanel_Loaded"
904904
Orientation="Horizontal">
905905
<!-- Item Thumbnail -->
906-
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch">
906+
<Grid
907+
Width="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
908+
HorizontalAlignment="Left"
909+
VerticalAlignment="Stretch">
907910

908911
<!-- Thumbnail -->
909912
<Grid
910913
x:Name="IconBox"
911-
Width="24"
912-
Height="24"
914+
Width="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
915+
Height="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
913916
HorizontalAlignment="Center"
914917
VerticalAlignment="Center"
915918
AutomationProperties.Name="{helpers:ResourceString Name=FileBrowserThumbnailIconColumnGrid/AutomationProperties/Name}"
@@ -918,8 +921,7 @@
918921
Tag="ItemImage">
919922
<ContentPresenter
920923
x:Name="PicturePresenter"
921-
Width="20"
922-
Height="20"
924+
Margin="2"
923925
HorizontalAlignment="Center"
924926
VerticalAlignment="Center"
925927
x:Load="{x:Bind LoadFileIcon, Mode=OneWay}"

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public sealed partial class DetailsLayoutPage : BaseGroupableLayoutPage
2929
// Fields
3030

3131
private ListedItem? _nextItemToSelect;
32+
private uint currentIconSize;
3233

3334
// Properties
3435

@@ -136,6 +137,8 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
136137

137138
base.OnNavigatedTo(eventArgs);
138139

140+
currentIconSize = FolderSettings.GetRoundedIconSize();
141+
139142
if (FolderSettings?.ColumnsViewModel is not null)
140143
{
141144
ColumnsViewModel.DateCreatedColumn = FolderSettings.ColumnsViewModel.DateCreatedColumn;
@@ -191,7 +194,7 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
191194
UserSettingsService.LayoutSettingsService.PropertyChanged -= LayoutSettingsService_PropertyChanged;
192195
}
193196

194-
private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
197+
private async void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
195198
{
196199
if (e.PropertyName == nameof(ILayoutSettingsService.DetailsViewSize))
197200
{
@@ -205,6 +208,14 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang
205208

206209
// Restore correct scroll position
207210
ContentScroller?.ChangeView(null, previousOffset, null);
211+
212+
// Reload icons with correct size but only if the size changed
213+
var requestedIconSize = FolderSettings.GetRoundedIconSize();
214+
if (requestedIconSize != currentIconSize)
215+
{
216+
currentIconSize = requestedIconSize;
217+
_ = ReloadItemIconsAsync();
218+
}
208219
}
209220
else
210221
{
@@ -255,6 +266,19 @@ private void SetItemContainerStyle()
255266
// Set correct style
256267
FileList.ItemContainerStyle = RegularItemContainerStyle;
257268
}
269+
270+
// 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;
258282
}
259283

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

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

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

141141
var parameters = (NavigationArguments)eventArgs.Parameter;
142142
if (parameters.IsLayoutSwitch)
143-
ReloadItemIconsAsync();
143+
_ = ReloadItemIconsAsync();
144144
}
145145

146146
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
@@ -204,7 +204,7 @@ private async void FolderSettings_LayoutModeChangeRequested(object? sender, Layo
204204
if (requestedIconSize != currentIconSize)
205205
{
206206
currentIconSize = requestedIconSize;
207-
await ReloadItemIconsAsync();
207+
_ = ReloadItemIconsAsync();
208208
}
209209
}
210210
}
@@ -497,7 +497,7 @@ private async void FolderSettings_IconHeightChanged()
497497
{
498498
// Update icon size before refreshing
499499
currentIconSize = requestedIconSize;
500-
await ReloadItemIconsAsync();
500+
_ = ReloadItemIconsAsync();
501501
}
502502
}
503503

0 commit comments

Comments
 (0)