Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Differentiate between icon size & icon height #14713

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 32 additions & 8 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,48 @@ public static class Appearance
public const string StandardFont = "Segoe UI Variable";
}

public static class Browser
// Default icon heights used in the differents layouts
public static class IconHeights
{
public static class GridViewBrowser
public static class GridView
{
public const int GridViewIncrement = 20;
public const int Increment = 20;

public const int GridViewSizeLarge = 220;
public const int Minimum = 80;

public const int GridViewSizeMedium = 160;
public const int Small = 100;

public const int GridViewSizeSmall = 100;
public const int Medium = 160;

public const int TilesView = 100;
public const int Large = 220;

public const int Maximum = 300;
}

public static class TilesView
{
public const int Regular = 100;
}

public static class ListView
{
public const int Regular = 32;
}

public static class DetailsView
{
public const int Regular = 32;
}

public static class ColumnsView
{
public const int Regular = 32;
}
}


// Default icon sizes that are available for files and folders
public static class DefaultIconSizes
public static class ShellIconSizes
{
public const int Small = 16;

Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using static Files.App.Constants.Browser.GridViewBrowser;
using static Files.App.Constants;

namespace Files.App.Data.Contexts
{
Expand Down Expand Up @@ -34,13 +34,13 @@ public LayoutTypes LayoutType
viewModel.ToggleLayoutModeTiles(true);
break;
case LayoutTypes.GridSmall:
viewModel.ToggleLayoutModeGridView(GridViewSizeSmall, true);
viewModel.ToggleLayoutModeGridView(IconHeights.GridView.Small, true);
break;
case LayoutTypes.GridMedium:
viewModel.ToggleLayoutModeGridView(GridViewSizeMedium, true);
viewModel.ToggleLayoutModeGridView(IconHeights.GridView.Medium, true);
break;
case LayoutTypes.GridLarge:
viewModel.ToggleLayoutModeGridView(GridViewSizeLarge, true);
viewModel.ToggleLayoutModeGridView(IconHeights.GridView.Large, true);
break;
case LayoutTypes.Columns:
viewModel.ToggleLayoutModeColumnView(true);
Expand Down Expand Up @@ -174,7 +174,7 @@ private void FolderSettings_PropertyChanged(object? sender, PropertyChangedEvent
switch (e.PropertyName)
{
case nameof(LayoutPreferencesManager.LayoutMode):
case nameof(LayoutPreferencesManager.IconSize):
case nameof(LayoutPreferencesManager.IconHeight):
case nameof(LayoutPreferencesManager.IsAdaptiveLayoutEnabled):
SetProperty(ref _LayoutType, GetLayoutType(), nameof(LayoutType));
break;
Expand Down Expand Up @@ -251,10 +251,10 @@ private LayoutTypes GetLayoutType()
FolderLayoutModes.DetailsView => LayoutTypes.Details,
FolderLayoutModes.ListView => LayoutTypes.List,
FolderLayoutModes.TilesView => LayoutTypes.Tiles,
FolderLayoutModes.GridView => viewModel.IconSize switch
FolderLayoutModes.GridView => viewModel.IconHeight switch
{
< GridViewSizeMedium => LayoutTypes.GridSmall,
< GridViewSizeLarge => LayoutTypes.GridMedium,
< IconHeights.GridView.Medium => LayoutTypes.GridSmall,
< IconHeights.GridView.Large => LayoutTypes.GridMedium,
_ => LayoutTypes.GridLarge,
},
FolderLayoutModes.ColumnView => LayoutTypes.Columns,
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public int CompareTo(INavigationControlItem other)
public async Task LoadThumbnailAsync()
{
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.DefaultIconSizes.Large, false, false, true);
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.ShellIconSizes.Large, false, false, true);

if (Root is not null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/SidebarLibraryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<bool> CheckDefaultSaveFolderAccess()

public async Task LoadLibraryIconAsync()
{
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Large, false, false, true);
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Large, false, false, true);

if (IconData is not null)
Icon = await IconData.ToBitmapAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/WidgetDriveCardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public WidgetDriveCardItem(DriveItem item)

public async Task LoadCardThumbnailAsync()
{
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.DefaultIconSizes.Jumbo, true, false, true);
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.ShellIconSizes.Jumbo, true, false, true);

// Thumbnail data is valid, set the item icon
if (thumbnailData is not null && thumbnailData.Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/WidgetFolderCardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public WidgetFolderCardItem(LocationItem item, string text, bool isPinned)

public async Task LoadCardThumbnailAsync()
{
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Jumbo, true, false, true);
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Jumbo, true, false, true);

if (_thumbnailData is not null && _thumbnailData.Length > 0)
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => _thumbnailData.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
case nameof(UserSettingsService.FoldersSettingsService.SyncFolderPreferencesAcrossDirectories):
case nameof(UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit):
case nameof(UserSettingsService.FoldersSettingsService.DefaultLayoutMode):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconSizeListView):
case nameof(UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView):
case nameof(UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconHeightDetailsView):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconHeightListView):
case nameof(UserSettingsService.LayoutSettingsService.DefaulIconHeightTilesView):
case nameof(UserSettingsService.LayoutSettingsService.DefaulIconHeightGridView):
case nameof(UserSettingsService.LayoutSettingsService.DefaultIconHeightColumnsView):
await dispatcherQueue.EnqueueOrInvokeAsync(() =>
{
folderSettings.OnDefaultPreferencesChanged(WorkingDirectory, e.SettingName);
Expand Down Expand Up @@ -1288,7 +1288,7 @@ await SafetyExtensions.IgnoreExceptions(() =>
ImageSource? groupImage = null;
if (item.PrimaryItemAttribute != StorageItemTypes.Folder || item.IsArchive)
{
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.DefaultIconSizes.ExtraLarge, false, false, true);
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.ShellIconSizes.ExtraLarge, false, false, true);

if (headerIconInfo is not null && !item.IsShortcut)
groupImage = await dispatcherQueue.EnqueueOrInvokeAsync(() => headerIconInfo.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void ApplyAdaptativeLayout(LayoutPreferencesManager folderSettings
folderSettings.ToggleLayoutModeDetailsView(false);
break;
case Layouts.Grid:
folderSettings.ToggleLayoutModeGridView(Constants.Browser.GridViewBrowser.GridViewSizeMedium, false);
folderSettings.ToggleLayoutModeGridView(Constants.IconHeights.GridView.Medium, false);
break;
}
}
Expand Down
42 changes: 21 additions & 21 deletions src/Files.App/Helpers/Layout/LayoutPreferencesItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class LayoutPreferencesItem
public bool SortFilesFirst;
public bool IsAdaptiveLayoutOverridden;

// Icon sizes
public int IconSizeDetailsView;
public int IconSizeListView;
public int IconSizeTilesView;
public int IconSizeGridView;
public int IconSizeColumnsView;
// Icon heights
public int IconHeightDetailsView;
public int IconHeightListView;
public int IconHeightTilesView;
public int IconHeightGridView;
public int IconHeightColumnsView;

public FolderLayoutModes LayoutMode;

Expand All @@ -43,11 +43,11 @@ public LayoutPreferencesItem()
var defaultLayout = UserSettingsService.FoldersSettingsService.DefaultLayoutMode;

LayoutMode = defaultLayout is FolderLayoutModes.Adaptive ? FolderLayoutModes.DetailsView : defaultLayout;
IconSizeDetailsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView;
IconSizeListView = UserSettingsService.LayoutSettingsService.DefaultIconSizeListView;
IconSizeTilesView = UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView;
IconSizeGridView = UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView;
IconSizeColumnsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView;
IconHeightDetailsView = UserSettingsService.LayoutSettingsService.DefaultIconHeightDetailsView;
IconHeightListView = UserSettingsService.LayoutSettingsService.DefaultIconHeightListView;
IconHeightTilesView = UserSettingsService.LayoutSettingsService.DefaulIconHeightTilesView;
IconHeightGridView = UserSettingsService.LayoutSettingsService.DefaulIconHeightGridView;
IconHeightColumnsView = UserSettingsService.LayoutSettingsService.DefaultIconHeightColumnsView;
DirectorySortOption = UserSettingsService.FoldersSettingsService.DefaultSortOption;
DirectoryGroupOption = UserSettingsService.FoldersSettingsService.DefaultGroupOption;
DirectorySortDirection = UserSettingsService.FoldersSettingsService.DefaultDirectorySortDirection;
Expand Down Expand Up @@ -104,11 +104,11 @@ public override bool Equals(object? obj)
{
return (
item.LayoutMode == LayoutMode &&
item.IconSizeDetailsView == IconSizeDetailsView &&
item.IconSizeListView == IconSizeListView &&
item.IconSizeTilesView == IconSizeTilesView &&
item.IconSizeGridView == IconSizeGridView &&
item.IconSizeColumnsView == IconSizeColumnsView &&
item.IconHeightDetailsView == IconHeightDetailsView &&
item.IconHeightListView == IconHeightListView &&
item.IconHeightTilesView == IconHeightTilesView &&
item.IconHeightGridView == IconHeightGridView &&
item.IconHeightColumnsView == IconHeightColumnsView &&
item.DirectoryGroupOption == DirectoryGroupOption &&
item.DirectorySortOption == DirectorySortOption &&
item.DirectorySortDirection == DirectorySortDirection &&
Expand All @@ -127,11 +127,11 @@ public override int GetHashCode()
HashCode hash = new();

hash.Add(LayoutMode);
hash.Add(IconSizeDetailsView);
hash.Add(IconSizeListView);
hash.Add(IconSizeTilesView);
hash.Add(IconSizeGridView);
hash.Add(IconSizeColumnsView);
hash.Add(IconHeightDetailsView);
hash.Add(IconHeightListView);
hash.Add(IconHeightTilesView);
hash.Add(IconHeightGridView);
hash.Add(IconHeightColumnsView);
hash.Add(DirectoryGroupOption);
hash.Add(DirectorySortOption);
hash.Add(DirectorySortDirection);
Expand Down
Loading
Loading