Skip to content

Commit

Permalink
Code Quality: Replaced icon height & size constants with enums (#14809)
Browse files Browse the repository at this point in the history
Co-authored-by: Yair <[email protected]>
  • Loading branch information
0x5bfa and yaira2 authored Feb 23, 2024
1 parent 1de517a commit 9743a4a
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 240 deletions.
64 changes: 32 additions & 32 deletions src/Files.App/Actions/Display/LayoutAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public HotKey MediaHotKey

public bool IsExecutable =>
ContentPageContext.PageType is not ContentPageTypes.Home &&
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum));
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.DetailsViewSize > DetailsViewSizeKind.Compact) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ListViewSize > ListViewSizeKind.Compact) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.GridViewSize > GridViewSizeKind.Compact) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ColumnsViewSize > ColumnsViewSizeKind.Compact));

public LayoutDecreaseSizeAction()
{
Expand Down Expand Up @@ -224,10 +224,10 @@ private void UserSettingsService_PropertyChanged(object? sender, PropertyChanged
{
switch (e.PropertyName)
{
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
case nameof(ILayoutSettingsService.ItemSizeListView):
case nameof(ILayoutSettingsService.ItemSizeGridView):
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
case nameof(ILayoutSettingsService.DetailsViewSize):
case nameof(ILayoutSettingsService.ListViewSize):
case nameof(ILayoutSettingsService.GridViewSize):
case nameof(ILayoutSettingsService.ColumnsViewSize):
OnPropertyChanged(nameof(IsExecutable));
break;
}
Expand All @@ -238,22 +238,22 @@ public Task ExecuteAsync()
switch (DisplayPageContext.LayoutType)
{
case LayoutTypes.Details:
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView > Constants.IconHeights.DetailsView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView -= Constants.IconHeights.DetailsView.Increment;
if (UserSettingsService.LayoutSettingsService.DetailsViewSize > DetailsViewSizeKind.Compact)
UserSettingsService.LayoutSettingsService.DetailsViewSize -= 1;
break;
case LayoutTypes.List:
if (UserSettingsService.LayoutSettingsService.ItemSizeListView > Constants.IconHeights.ListView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeListView -= Constants.IconHeights.ListView.Increment;
if (UserSettingsService.LayoutSettingsService.ListViewSize > ListViewSizeKind.Compact)
UserSettingsService.LayoutSettingsService.ListViewSize -= 1;
break;
case LayoutTypes.Tiles:
break;
case LayoutTypes.Grid:
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView > Constants.IconHeights.GridView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeGridView -= Constants.IconHeights.GridView.Increment;
if (UserSettingsService.LayoutSettingsService.GridViewSize > GridViewSizeKind.Compact)
UserSettingsService.LayoutSettingsService.GridViewSize -= 1;
break;
case LayoutTypes.Columns:
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView > Constants.IconHeights.ColumnsView.Minimum)
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView -= Constants.IconHeights.ColumnsView.Increment;
if (UserSettingsService.LayoutSettingsService.ColumnsViewSize > ColumnsViewSizeKind.Compact)
UserSettingsService.LayoutSettingsService.ColumnsViewSize -= 1;
break;
}

Expand Down Expand Up @@ -281,10 +281,10 @@ public HotKey MediaHotKey

public bool IsExecutable =>
ContentPageContext.PageType is not ContentPageTypes.Home &&
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum));
((DisplayPageContext.LayoutType == LayoutTypes.Details && UserSettingsService.LayoutSettingsService.DetailsViewSize < DetailsViewSizeKind.ExtraLarge) ||
(DisplayPageContext.LayoutType == LayoutTypes.List && UserSettingsService.LayoutSettingsService.ListViewSize < ListViewSizeKind.ExtraLarge) ||
(DisplayPageContext.LayoutType == LayoutTypes.Grid && UserSettingsService.LayoutSettingsService.GridViewSize < GridViewSizeKind.Eleven) ||
(DisplayPageContext.LayoutType == LayoutTypes.Columns && UserSettingsService.LayoutSettingsService.ColumnsViewSize < ColumnsViewSizeKind.ExtraLarge));

public LayoutIncreaseSizeAction()
{
Expand Down Expand Up @@ -317,10 +317,10 @@ private void UserSettingsService_PropertyChanged(object? sender, PropertyChanged
{
switch (e.PropertyName)
{
case nameof(ILayoutSettingsService.ItemSizeDetailsView):
case nameof(ILayoutSettingsService.ItemSizeListView):
case nameof(ILayoutSettingsService.ItemSizeGridView):
case nameof(ILayoutSettingsService.ItemSizeColumnsView):
case nameof(ILayoutSettingsService.DetailsViewSize):
case nameof(ILayoutSettingsService.ListViewSize):
case nameof(ILayoutSettingsService.GridViewSize):
case nameof(ILayoutSettingsService.ColumnsViewSize):
OnPropertyChanged(nameof(IsExecutable));
break;
}
Expand All @@ -331,22 +331,22 @@ public Task ExecuteAsync()
switch (DisplayPageContext.LayoutType)
{
case LayoutTypes.Details:
if (UserSettingsService.LayoutSettingsService.ItemSizeDetailsView < Constants.IconHeights.DetailsView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeDetailsView += Constants.IconHeights.DetailsView.Increment;
if (UserSettingsService.LayoutSettingsService.DetailsViewSize < DetailsViewSizeKind.ExtraLarge)
UserSettingsService.LayoutSettingsService.DetailsViewSize += 1;
break;
case LayoutTypes.List:
if (UserSettingsService.LayoutSettingsService.ItemSizeListView < Constants.IconHeights.ListView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeListView += Constants.IconHeights.ListView.Increment;
if (UserSettingsService.LayoutSettingsService.ListViewSize < ListViewSizeKind.ExtraLarge)
UserSettingsService.LayoutSettingsService.ListViewSize += 1;
break;
case LayoutTypes.Tiles:
break;
case LayoutTypes.Grid:
if (UserSettingsService.LayoutSettingsService.ItemSizeGridView < Constants.IconHeights.GridView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeGridView += Constants.IconHeights.GridView.Increment;
if (UserSettingsService.LayoutSettingsService.GridViewSize < GridViewSizeKind.Eleven)
UserSettingsService.LayoutSettingsService.GridViewSize += 1;
break;
case LayoutTypes.Columns:
if (UserSettingsService.LayoutSettingsService.ItemSizeColumnsView < Constants.IconHeights.ColumnsView.Maximum)
UserSettingsService.LayoutSettingsService.ItemSizeColumnsView += Constants.IconHeights.ColumnsView.Increment;
if (UserSettingsService.LayoutSettingsService.ColumnsViewSize < ColumnsViewSizeKind.ExtraLarge)
UserSettingsService.LayoutSettingsService.ColumnsViewSize += 1;
break;
}

Expand Down
64 changes: 0 additions & 64 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,70 +118,6 @@ public static class Appearance
public const string StandardFont = "Segoe UI Variable";
}

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

public const int Minimum = 80;

public const int Small = 100;

public const int Medium = 160;

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 Increment = 4;

public const int Minimum = 24;

public const int Small = 28;

public const int Regular = 32;

public const int Maximum = 36;
}

public static class DetailsView
{
public const int Increment = 4;

public const int Minimum = 28;

public const int Small = 32;

public const int Regular = 36;

public const int Maximum = 40;
}

public static class ColumnsView
{
public const int Increment = 4;

public const int Minimum = 28;

public const int Small = 32;

public const int Regular = 36;

public const int Maximum = 40;
}
}


// Default icon sizes that are available for files and folders
public static class ShellIconSizes
{
Expand Down
7 changes: 3 additions & 4 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,10 @@ public uint GetRoundedIconSize()
=> Constants.ShellIconSizes.Large,
FolderLayoutModes.ColumnView
=> Constants.ShellIconSizes.Large,
_ when LayoutMode == FolderLayoutModes.TilesView && UserSettingsService.LayoutSettingsService.ItemSizeTilesView <= 96 ||
LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.ItemSizeGridView <= 96
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Small ||
LayoutMode == FolderLayoutModes.TilesView
=> 96,
_ when LayoutMode == FolderLayoutModes.TilesView && UserSettingsService.LayoutSettingsService.ItemSizeTilesView <= 128 ||
LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.ItemSizeGridView <= 128
_ when LayoutMode == FolderLayoutModes.GridView && UserSettingsService.LayoutSettingsService.GridViewSize <= GridViewSizeKind.Large
=> 128,
_ => 256,
};
Expand Down
130 changes: 130 additions & 0 deletions src/Files.App/Helpers/Layout/LayoutSizeKindHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Helpers
{
public static class LayoutSizeKindHelper
{
private static ILayoutSettingsService LayoutSettingsService { get; } = Ioc.Default.GetRequiredService<ILayoutSettingsService>();

/// <summary>
/// Gets the desired height for items in the Details View
/// </summary>
/// <param name="detailsViewSizeKind"></param>
/// <returns></returns>
public static int GetDetailsViewRowHeight(DetailsViewSizeKind detailsViewSizeKind)
{
switch (detailsViewSizeKind)
{
case DetailsViewSizeKind.Compact:
return 28;
case DetailsViewSizeKind.Small:
return 36;
case DetailsViewSizeKind.Medium:
return 40;
case DetailsViewSizeKind.Large:
return 44;
case DetailsViewSizeKind.ExtraLarge:
return 48;
default:
return 36;
}
}

/// <summary>
/// Gets the desired width for items in the Grid View
/// </summary>
/// <param name="gridViewSizeKind"></param>
/// <returns></returns>
public static int GetGridViewItemWidth(GridViewSizeKind gridViewSizeKind)
{
switch (gridViewSizeKind)
{
case GridViewSizeKind.Compact:
return 80;
case GridViewSizeKind.Small:
return 100;
case GridViewSizeKind.Medium:
return 120;
case GridViewSizeKind.Large:
return 140;
case GridViewSizeKind.ExtraLarge:
return 160;
case GridViewSizeKind.Five:
return 180;
case GridViewSizeKind.Six:
return 200;
case GridViewSizeKind.Seven:
return 220;
case GridViewSizeKind.Eight:
return 240;
case GridViewSizeKind.Nine:
return 260;
case GridViewSizeKind.Ten:
return 280;
case GridViewSizeKind.Eleven:
return 300;
default:
return 100;
}
}

/// <summary>
/// Gets the desired height for items in the List View
/// </summary>
/// <param name="listViewSizeKind"></param>
/// <returns></returns>
public static int GetListViewRowHeight(ListViewSizeKind listViewSizeKind)
{
switch (listViewSizeKind)
{
case ListViewSizeKind.Compact:
return 24;
case ListViewSizeKind.Small:
return 32;
case ListViewSizeKind.Medium:
return 36;
case ListViewSizeKind.Large:
return 40;
case ListViewSizeKind.ExtraLarge:
return 44;
default:
return 32;
}
}

/// <summary>
/// Gets the desired height for items in the Columns View
/// </summary>
/// <param name="columnsViewSizeKind"></param>
/// <returns></returns>
public static int GetColumnsViewRowHeight(ColumnsViewSizeKind columnsViewSizeKind)
{
switch (columnsViewSizeKind)
{
case ColumnsViewSizeKind.Compact:
return 28;
case ColumnsViewSizeKind.Small:
return 36;
case ColumnsViewSizeKind.Medium:
return 40;
case ColumnsViewSizeKind.Large:
return 44;
case ColumnsViewSizeKind.ExtraLarge:
return 48;
default:
return 36;
}
}

/// <summary>
/// Gets the desired width for items in the Tiles View
/// </summary>
/// <param name="tilesViewSizeKind"></param>
/// <returns></returns>
public static int GetTilesViewItemWidth(TilesViewSizeKind tilesViewSizeKind)
{
return 260;
}
}
}
30 changes: 15 additions & 15 deletions src/Files.App/Services/Settings/LayoutSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ public LayoutSettingsService(ISettingsSharingContext settingsSharingContext)
RegisterSettingsContext(settingsSharingContext);
}

public int ItemSizeDetailsView
public DetailsViewSizeKind DetailsViewSize
{
get => (int)Get((long)Constants.IconHeights.DetailsView.Regular);
set => Set((long)value);
get => Get(DetailsViewSizeKind.Small);
set => Set(value);
}

public int ItemSizeListView
public ListViewSizeKind ListViewSize
{
get => (int)Get((long)Constants.IconHeights.ListView.Regular);
set => Set((long)value);
get => Get(ListViewSizeKind.Small);
set => Set(value);
}

public int ItemSizeTilesView
public TilesViewSizeKind TilesViewSize
{
get => (int)Get((long)Constants.IconHeights.TilesView.Regular);
set => Set((long)value);
get => Get(TilesViewSizeKind.Small);
set => Set(value);
}

public int ItemSizeGridView
public GridViewSizeKind GridViewSize
{
get => (int)Get((long)Constants.IconHeights.GridView.Medium);
set => Set((long)value);
get => Get(GridViewSizeKind.ExtraLarge);
set => Set(value);
}

public int ItemSizeColumnsView
public ColumnsViewSizeKind ColumnsViewSize
{
get => (int)Get((long)Constants.IconHeights.ColumnsView.Regular);
set => Set((long)value);
get => Get(ColumnsViewSizeKind.Small);
set => Set(value);
}
}
}
Loading

0 comments on commit 9743a4a

Please sign in to comment.