Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Copy link
Member Author

@yaira2 yaira2 Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the code for getting the icon size to LayoutSizeKindHelper.cs.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Data.Enums;
using System.Text.Json;
using Windows.Storage;
using Windows.Win32;

namespace Files.App.Helpers
Expand Down Expand Up @@ -205,43 +202,6 @@ public LayoutPreferencesManager(FolderLayoutModes modeOverride) : this()

// Methods

/// <summary>
/// This will round the current icon size to get the best result from the File Explorer thumbnail system.
///
/// Details View:
/// Always uses the Large icon size (32).
///
/// List View:
/// Always uses the Large icon size (32).
///
/// Columns View:
/// Always uses the Large icon size (32).
///
/// Tiles View:
/// Always uses 96, 128, or 256 depending on the layout size.
///
/// Grid View:
/// Always uses 96, 128, or 256 depending on the layout size.
/// </summary>
public uint GetRoundedIconSize()
{
return LayoutMode switch
{
FolderLayoutModes.DetailsView
=> Constants.ShellIconSizes.Large,
FolderLayoutModes.ListView
=> Constants.ShellIconSizes.Large,
FolderLayoutModes.ColumnView
=> Constants.ShellIconSizes.Large,
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small ||
LayoutMode == FolderLayoutModes.TilesView
=> 96,
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Large
=> 128,
_ => 256,
};
}

public Type GetLayoutType(string path, bool changeLayoutMode = true)
{
var preferencesItem = GetLayoutPreferencesForPath(path);
Expand Down
35 changes: 35 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutSizeKindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,41 @@ public static int GetListViewRowHeight(ListViewSizeKind listViewSizeKind)
}
}

/// <summary>
/// Gets the desired icon size for the requested layout
/// </summary>
/// <param name="folderLayoutMode"></param>
/// <returns></returns>
public static uint GetIconSize(FolderLayoutModes folderLayoutMode)
{
return folderLayoutMode switch
{
// Details
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Compact => Constants.ShellIconSizes.Small,
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Small => Constants.ShellIconSizes.Small,
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Medium => 20,
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.Large => 24,
FolderLayoutModes.DetailsView when LayoutSettingsService.DetailsViewSize == DetailsViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,

// List
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Compact => Constants.ShellIconSizes.Small,
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Small => Constants.ShellIconSizes.Small,
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Medium => 20,
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.Large => 24,
FolderLayoutModes.ListView when LayoutSettingsService.ListViewSize == ListViewSizeKind.ExtraLarge => Constants.ShellIconSizes.Large,

// Columns
FolderLayoutModes.ColumnView => Constants.ShellIconSizes.Large,

// Grid and Tiles
FolderLayoutModes.GridView when LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small => 96,
FolderLayoutModes.TilesView => 96,
FolderLayoutModes.GridView when LayoutSettingsService.GridViewSize <= GridViewSizeKind.Large => 128,

_ => 256,
};
}

/// <summary>
/// Gets the desired height for items in the Columns View
/// </summary>
Expand Down
13 changes: 8 additions & 5 deletions src/Files.App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,12 @@ private async Task<BitmapImage> GetShieldIcon()
private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancellationToken)
{
var loadNonCachedThumbnail = false;
var thumbnailSize = folderSettings.GetRoundedIconSize();
var thumbnailSize = LayoutSizeKindHelper.GetIconSize(folderSettings.LayoutMode);
var returnIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 48;

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

byte[]? result = null;

// Non-cached thumbnails take longer to generate
Expand All @@ -988,7 +991,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
item.ItemPath,
thumbnailSize,
item.IsFolder,
IconOptions.ReturnThumbnailOnly | IconOptions.ReturnOnlyIfCached);
IconOptions.ReturnThumbnailOnly | IconOptions.ReturnOnlyIfCached | (useCurrentScale ? IconOptions.UseCurrentScale : 0));

cancellationToken.ThrowIfCancellationRequested();
loadNonCachedThumbnail = true;
Expand All @@ -1001,7 +1004,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
item.ItemPath,
thumbnailSize,
item.IsFolder,
IconOptions.ReturnIconOnly);
IconOptions.ReturnIconOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0));

cancellationToken.ThrowIfCancellationRequested();
}
Expand All @@ -1013,7 +1016,7 @@ private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancell
item.ItemPath,
thumbnailSize,
item.IsFolder,
returnIconOnly ? IconOptions.ReturnIconOnly : IconOptions.None);
returnIconOnly ? IconOptions.ReturnIconOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0) : (useCurrentScale ? IconOptions.UseCurrentScale : 0));

cancellationToken.ThrowIfCancellationRequested();
}
Expand Down Expand Up @@ -1059,7 +1062,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
item.ItemPath,
thumbnailSize,
item.IsFolder,
IconOptions.ReturnThumbnailOnly);
IconOptions.ReturnThumbnailOnly | (useCurrentScale ? IconOptions.UseCurrentScale : 0));
}
finally
{
Expand Down
12 changes: 7 additions & 5 deletions src/Files.App/Views/Layouts/DetailsLayoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,16 @@
Loaded="StackPanel_Loaded"
Orientation="Horizontal">
<!-- Item Thumbnail -->
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch">
<Grid
Width="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
HorizontalAlignment="Left"
VerticalAlignment="Stretch">

<!-- Thumbnail -->
<Grid
x:Name="IconBox"
Width="24"
Height="24"
Width="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
Height="{Binding ColumnsViewModel.IconColumn.Length.Value, ElementName=PageRoot, Mode=OneWay}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.Name="{helpers:ResourceString Name=FileBrowserThumbnailIconColumnGrid/AutomationProperties/Name}"
Expand All @@ -918,8 +921,7 @@
Tag="ItemImage">
<ContentPresenter
x:Name="PicturePresenter"
Width="20"
Height="20"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind LoadFileIcon, Mode=OneWay}"
Expand Down
16 changes: 15 additions & 1 deletion src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed partial class DetailsLayoutPage : BaseGroupableLayoutPage
// Fields

private ListedItem? _nextItemToSelect;
private uint currentIconSize;

// Properties

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

base.OnNavigatedTo(eventArgs);

currentIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView);

if (FolderSettings?.ColumnsViewModel is not null)
{
ColumnsViewModel.DateCreatedColumn = FolderSettings.ColumnsViewModel.DateCreatedColumn;
Expand Down Expand Up @@ -191,7 +194,7 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
UserSettingsService.LayoutSettingsService.PropertyChanged -= LayoutSettingsService_PropertyChanged;
}

private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private async void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ILayoutSettingsService.DetailsViewSize))
{
Expand All @@ -205,6 +208,14 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang

// Restore correct scroll position
ContentScroller?.ChangeView(null, previousOffset, null);

// Reload icons with correct size but only if the size changed
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView);
if (requestedIconSize != currentIconSize)
{
currentIconSize = requestedIconSize;
_ = ReloadItemIconsAsync();
}
}
else
{
Expand Down Expand Up @@ -255,6 +266,9 @@ private void SetItemContainerStyle()
// Set correct style
FileList.ItemContainerStyle = RegularItemContainerStyle;
}

// Set icon column width
ColumnsViewModel.IconColumn.UserLength = new GridLength(LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.DetailsView) + 4);
}

private void FileList_LayoutUpdated(object? sender, object e)
Expand Down
7 changes: 3 additions & 4 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@
<!-- Thumbnail -->
<Grid
x:Name="IconBox"
Width="24"
Height="24"
Width="{Binding IconBoxSizeListView, ElementName=PageRoot, Mode=OneWay}"
Height="{Binding IconBoxSizeListView, ElementName=PageRoot, Mode=OneWay}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.Name="{helpers:ResourceString Name=FileBrowserThumbnailIconColumnGrid/AutomationProperties/Name}"
Expand All @@ -312,8 +312,7 @@
Tag="ItemImage">
<ContentPresenter
x:Name="PicturePresenter"
Width="20"
Height="20"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Load="{x:Bind LoadFileIcon, Mode=OneWay}"
Expand Down
22 changes: 15 additions & 7 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public int RowHeightListView
{
get => LayoutSizeKindHelper.GetListViewRowHeight(UserSettingsService.LayoutSettingsService.ListViewSize);
}

/// <summary>
/// Icon Box size in the List View layout. The value is increased by 4px to account for icon overlays.
/// </summary>
public int IconBoxSizeListView
{
get => (int)(LayoutSizeKindHelper.GetIconSize(FolderLayoutModes.ListView) + 4);
}

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

base.OnNavigatedTo(eventArgs);

currentIconSize = FolderSettings.GetRoundedIconSize();
currentIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);

FolderSettings.LayoutModeChangeRequested -= FolderSettings_LayoutModeChangeRequested;
FolderSettings.LayoutModeChangeRequested += FolderSettings_LayoutModeChangeRequested;
Expand All @@ -140,7 +148,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)

var parameters = (NavigationArguments)eventArgs.Parameter;
if (parameters.IsLayoutSwitch)
ReloadItemIconsAsync();
_ = ReloadItemIconsAsync();
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
Expand All @@ -162,10 +170,10 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang
if (e.PropertyName == nameof(ILayoutSettingsService.ListViewSize))
{
NotifyPropertyChanged(nameof(RowHeightListView));
NotifyPropertyChanged(nameof(IconBoxSizeListView));

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

FolderSettings_IconHeightChanged();
}
if (e.PropertyName == nameof(ILayoutSettingsService.TilesViewSize))
Expand All @@ -182,7 +190,6 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang

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

FolderSettings_IconHeightChanged();
}

Expand All @@ -200,10 +207,11 @@ private async void FolderSettings_LayoutModeChangeRequested(object? sender, Layo
SetItemTemplate();
SetItemContainerStyle();

var requestedIconSize = FolderSettings.GetRoundedIconSize();
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);
if (requestedIconSize != currentIconSize)
{
currentIconSize = requestedIconSize;
// Don't change this await https://github.com/files-community/Files/pull/16708#discussion_r1916402106
await ReloadItemIconsAsync();
}
}
Expand Down Expand Up @@ -490,14 +498,14 @@ protected override bool CanGetItemFromElement(object element)
private async void FolderSettings_IconHeightChanged()
{
// Get new icon size
var requestedIconSize = FolderSettings.GetRoundedIconSize();
var requestedIconSize = LayoutSizeKindHelper.GetIconSize(FolderSettings.LayoutMode);

// Prevents reloading icons when the icon size hasn't changed
if (requestedIconSize != currentIconSize)
{
// Update icon size before refreshing
currentIconSize = requestedIconSize;
await ReloadItemIconsAsync();
_ = ReloadItemIconsAsync();
}
}

Expand Down
Loading