Skip to content

Commit 34d908c

Browse files
authored
Feature: Use DPI aware icons in the Columns View (#16712)
1 parent 0903bad commit 34d908c

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ public static uint GetIconSize(FolderLayoutModes folderLayoutMode)
117117
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,
118118

119119
// Columns
120-
FolderLayoutModes.ColumnView => Constants.ShellIconSizes.Large,
120+
FolderLayoutModes.ColumnView when LayoutSettingsService.ColumnsViewSize == ColumnsViewSizeKind.Compact => Constants.ShellIconSizes.Small,
121+
FolderLayoutModes.ColumnView when LayoutSettingsService.ColumnsViewSize == ColumnsViewSizeKind.Small => Constants.ShellIconSizes.Small,
122+
FolderLayoutModes.ColumnView when LayoutSettingsService.ColumnsViewSize == ColumnsViewSizeKind.Medium => 20,
123+
FolderLayoutModes.ColumnView when LayoutSettingsService.ColumnsViewSize == ColumnsViewSizeKind.Large => 24,
124+
FolderLayoutModes.ColumnView when LayoutSettingsService.ColumnsViewSize == ColumnsViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,
121125

122126
// Grid and Tiles
123127
FolderLayoutModes.GridView when LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small => 96,

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
977977
var returnIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 48;
978978

979979
// TODO Remove this property when all the layouts can support different icon sizes
980-
var useCurrentScale = folderSettings.LayoutMode == FolderLayoutModes.DetailsView || folderSettings.LayoutMode == FolderLayoutModes.ListView;
980+
var useCurrentScale = folderSettings.LayoutMode == FolderLayoutModes.DetailsView || folderSettings.LayoutMode == FolderLayoutModes.ListView || folderSettings.LayoutMode == FolderLayoutModes.ColumnView;
981981

982982
byte[]? result = null;
983983

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,21 @@
217217
Loaded="Grid_Loaded"
218218
PointerEntered="Grid_PointerEntered">
219219
<Grid.ColumnDefinitions>
220-
<ColumnDefinition Width="24" />
220+
<ColumnDefinition Width="Auto" />
221221
<ColumnDefinition Width="*" />
222222
<ColumnDefinition Width="Auto" />
223223
</Grid.ColumnDefinitions>
224224

225225
<!-- Thumbnail -->
226226
<Grid
227227
Grid.Column="0"
228-
Width="24"
229-
Height="24"
228+
Width="{Binding IconBoxSize, ElementName=PageRoot, Mode=OneWay}"
229+
Height="{Binding IconBoxSize, ElementName=PageRoot, Mode=OneWay}"
230230
Opacity="{x:Bind Opacity, Mode=OneWay}"
231-
Tag="ItemImage">
231+
Tag="IconBox">
232232
<ContentPresenter
233233
x:Name="PicturePresenter"
234-
Width="20"
235-
Height="20"
234+
Margin="2"
236235
HorizontalAlignment="Center"
237236
VerticalAlignment="Center"
238237
x:Load="{x:Bind LoadFileIcon, Mode=OneWay}"

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ public int RowHeight
5050
get => LayoutSizeKindHelper.GetColumnsViewRowHeight(UserSettingsService.LayoutSettingsService.ColumnsViewSize);
5151
}
5252

53+
/// <summary>
54+
/// Icon Box size layout. The value is increased by 4px to account for icon overlays.
55+
/// </summary>
56+
public int IconBoxSize
57+
{
58+
get => (int)(LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.ColumnView) + 4);
59+
}
60+
61+
/// <summary>
62+
/// This reference is used to prevent unnecessary icon reloading by only reloading icons when their
63+
/// size changes, even if the layout size changes (since some layout sizes share the same icon size).
64+
/// </summary>
65+
private uint currentIconSize;
66+
5367
// Constructor
5468

5569
public ColumnLayoutPage() : base()
@@ -149,6 +163,8 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
149163

150164
base.OnNavigatedTo(eventArgs);
151165

166+
currentIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.ColumnView);
167+
152168
UserSettingsService.LayoutSettingsService.PropertyChanged += LayoutSettingsService_PropertyChanged;
153169

154170
SetItemContainerStyle();
@@ -180,12 +196,36 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang
180196
var previousOffset = ContentScroller?.VerticalOffset;
181197

182198
NotifyPropertyChanged(nameof(RowHeight));
199+
NotifyPropertyChanged(nameof(IconBoxSize));
183200

184201
// Update the container style to match the item size
185202
SetItemContainerStyle();
186203

187204
// Restore correct scroll position
188205
ContentScroller?.ChangeView(null, previousOffset, null);
206+
207+
// Check if icons need to be reloaded
208+
var newIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.ColumnView);
209+
if (newIconSize != currentIconSize)
210+
{
211+
currentIconSize = newIconSize;
212+
_ = ReloadItemIconsAsync();
213+
}
214+
}
215+
}
216+
217+
private async Task ReloadItemIconsAsync()
218+
{
219+
if (ParentShellPageInstance is null)
220+
return;
221+
222+
ParentShellPageInstance.ShellViewModel.CancelExtendedPropertiesLoading();
223+
var filesAndFolders = ParentShellPageInstance.ShellViewModel.FilesAndFolders.ToList();
224+
foreach (ListedItem listedItem in filesAndFolders)
225+
{
226+
listedItem.ItemPropertiesInitialized = false;
227+
if (FileList.ContainerFromItem(listedItem) is not null)
228+
await ParentShellPageInstance.ShellViewModel.LoadExtendedItemPropertiesAsync(listedItem);
189229
}
190230
}
191231

0 commit comments

Comments
 (0)