Skip to content

Commit 5629c8d

Browse files
authored
Code Quality: Added ToolbarButton controls (#15894)
1 parent be66d7c commit 5629c8d

File tree

53 files changed

+4271
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4271
-41
lines changed

src/Files.App.Controls/Files.App.Controls.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
1+
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>

src/Files.App.Controls/GlobalUsings.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111
global using global::System.Threading.Tasks;
1212
global using global::System.ComponentModel;
1313
global using global::System.Diagnostics;
14+
global using global::System.Text.Json;
15+
global using global::System.Text.Json.Serialization;
1416
global using SystemIO = global::System.IO;
1517

18+
// Microsoft.UI
19+
global using global::Microsoft.UI.Xaml;
20+
global using global::Microsoft.UI.Xaml.Controls;
21+
global using global::Microsoft.UI.Xaml.Controls.Primitives;
22+
23+
// Files.App.Controls
24+
global using global::Files.App.Controls.Primitives;
25+
1626
// Files.Shared
1727
global using global::Files.Shared;
1828
global using global::Files.Shared.Attributes;

src/Files.App.Controls/ThemedIcon/ThemedIcon.ThemeResources.xaml

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:Files.App.Controls">
66

7-
87
<ResourceDictionary.MergedDictionaries>
98
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
109
</ResourceDictionary.MergedDictionaries>
1110

12-
1311
<ResourceDictionary.ThemeDictionaries>
1412

1513
<ResourceDictionary x:Key="Default">
@@ -31,12 +29,34 @@
3129
<StaticResource x:Key="ThemedIconCriticalBackgroundBrush" ResourceKey="SystemFillColorCriticalBackgroundBrush" />
3230
<StaticResource x:Key="ThemedIconCautionBackgroundBrush" ResourceKey="SystemFillColorCautionBackgroundBrush" />
3331
<StaticResource x:Key="ThemedIconSuccessBackgroundBrush" ResourceKey="SystemFillColorSuccessBackgroundBrush" />
34-
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SolidBackgroundFillColorQuarternaryBrush" />
32+
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SystemFillColorNeutralBackgroundBrush" />
3533

3634
<x:Boolean x:Key="ThemedIconHighContrast">False</x:Boolean>
3735
</ResourceDictionary>
3836

37+
<ResourceDictionary x:Key="Light">
38+
<Color x:Key="ThemedIconBaseColor">#DB161616</Color>
39+
<Color x:Key="ThemedIconAltColor">#66F0F0F0</Color>
40+
41+
<StaticResource x:Key="ThemedIconBaseBrush" ResourceKey="ThemedIconBaseColor" />
42+
<StaticResource x:Key="ThemedIconAltBrush" ResourceKey="ThemedIconAltColor" />
43+
<StaticResource x:Key="ThemedIconAccentBrush" ResourceKey="AccentFillColorDefaultBrush" />
44+
<StaticResource x:Key="ThemedIconAccentContrastBrush" ResourceKey="TextOnAccentFillColorPrimaryBrush" />
45+
<StaticResource x:Key="ThemedIconDisabledBrush" ResourceKey="TextFillColorDisabledBrush" />
46+
<StaticResource x:Key="ThemedIconDisabledToggleBrush" ResourceKey="TextOnAccentFillColorDisabledBrush" />
47+
48+
<StaticResource x:Key="ThemedIconCriticalBrush" ResourceKey="SystemFillColorCritical" />
49+
<StaticResource x:Key="ThemedIconCautionBrush" ResourceKey="SystemFillColorCaution" />
50+
<StaticResource x:Key="ThemedIconSuccessBrush" ResourceKey="SystemFillColorSuccess" />
51+
<StaticResource x:Key="ThemedIconNeutralBrush" ResourceKey="SystemFillColorSolidNeutral" />
52+
53+
<StaticResource x:Key="ThemedIconCriticalBackgroundBrush" ResourceKey="SystemFillColorCriticalBackgroundBrush" />
54+
<StaticResource x:Key="ThemedIconCautionBackgroundBrush" ResourceKey="SystemFillColorCautionBackgroundBrush" />
55+
<StaticResource x:Key="ThemedIconSuccessBackgroundBrush" ResourceKey="SystemFillColorSuccessBackgroundBrush" />
56+
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SystemFillColorNeutralBackgroundBrush" />
3957

58+
<x:Boolean x:Key="ThemedIconHighContrast">False</x:Boolean>
59+
</ResourceDictionary>
4060

4161
<ResourceDictionary x:Key="HighContrast">
4262
<Color x:Key="ThemedIconBaseColor">#FF000000</Color>
@@ -57,37 +77,11 @@
5777
<StaticResource x:Key="ThemedIconCriticalBackgroundBrush" ResourceKey="SystemColorWindowColorBrush" />
5878
<StaticResource x:Key="ThemedIconCautionBackgroundBrush" ResourceKey="SystemColorWindowColorBrush" />
5979
<StaticResource x:Key="ThemedIconSuccessBackgroundBrush" ResourceKey="SystemColorWindowColorBrush" />
60-
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SolidBackgroundFillColorBaseBrush" />
80+
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SystemColorWindowColorBrush" />
6181

6282
<x:Boolean x:Key="ThemedIconHighContrast">True</x:Boolean>
6383
</ResourceDictionary>
6484

65-
66-
67-
<ResourceDictionary x:Key="Light">
68-
<Color x:Key="ThemedIconBaseColor">#DB161616</Color>
69-
<Color x:Key="ThemedIconAltColor">#66F0F0F0</Color>
70-
71-
<StaticResource x:Key="ThemedIconBaseBrush" ResourceKey="ThemedIconBaseColor" />
72-
<StaticResource x:Key="ThemedIconAltBrush" ResourceKey="ThemedIconAltColor" />
73-
<StaticResource x:Key="ThemedIconAccentBrush" ResourceKey="AccentFillColorDefaultBrush" />
74-
<StaticResource x:Key="ThemedIconAccentContrastBrush" ResourceKey="TextOnAccentFillColorPrimaryBrush" />
75-
<StaticResource x:Key="ThemedIconDisabledBrush" ResourceKey="TextFillColorDisabledBrush" />
76-
<StaticResource x:Key="ThemedIconDisabledToggleBrush" ResourceKey="TextOnAccentFillColorDisabledBrush" />
77-
78-
<StaticResource x:Key="ThemedIconCriticalBrush" ResourceKey="SystemFillColorCritical" />
79-
<StaticResource x:Key="ThemedIconCautionBrush" ResourceKey="SystemFillColorCaution" />
80-
<StaticResource x:Key="ThemedIconSuccessBrush" ResourceKey="SystemFillColorSuccess" />
81-
<StaticResource x:Key="ThemedIconNeutralBrush" ResourceKey="SystemFillColorSolidNeutral" />
82-
83-
<StaticResource x:Key="ThemedIconCriticalBackgroundBrush" ResourceKey="SystemFillColorCriticalBackgroundBrush" />
84-
<StaticResource x:Key="ThemedIconCautionBackgroundBrush" ResourceKey="SystemFillColorCautionBackgroundBrush" />
85-
<StaticResource x:Key="ThemedIconSuccessBackgroundBrush" ResourceKey="SystemFillColorSuccessBackgroundBrush" />
86-
<StaticResource x:Key="ThemedIconNeutralBackgroundBrush" ResourceKey="SolidBackgroundFillColorQuarternaryBrush" />
87-
88-
<x:Boolean x:Key="ThemedIconHighContrast">False</x:Boolean>
89-
</ResourceDictionary>
90-
9185
</ResourceDictionary.ThemeDictionaries>
9286

9387
</ResourceDictionary>

src/Files.App.Controls/Themes/Generic.xaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:Files.App.Controls">
66

7-
87
<ResourceDictionary.MergedDictionaries>
9-
108
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
119

12-
<!--#region StorageControls-->
13-
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Storage/StorageRing/StorageRing.ThemeResources.xaml" />
14-
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Storage/StorageRing/StorageRing.xaml" />
15-
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Storage/StorageBar/StorageBar.ThemeResources.xaml" />
16-
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Storage/StorageBar/StorageBar.xaml" />
10+
<!--#region Theme Dictionaries-->
11+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/ThemedIcon.ThemeResources.xaml" />
12+
13+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/Toolbar.ThemeResources.xaml" />
14+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarSeparator/ToolbarSeparator.ThemeResources.xaml" />
15+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarButton/ToolbarButton.ThemeResources.xaml" />
16+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarToggleButton/ToolbarToggleButton.ThemeResources.xaml" />
1717
<!--#endregion-->
1818

1919
<!--#region ThemedIcon-->
20-
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/ThemedIcon.ThemeResources.xaml" />
21-
2220
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/ThemedIcon.xaml" />
2321
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.xaml" />
24-
<!-- Icon Style Sets -->
22+
<!--#endregion-->
23+
24+
<!--#region ToolbarButtons-->
25+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/Toolbar.xaml" />
26+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarSeparator/ToolbarSeparator.xaml" />
27+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarButton/ToolbarButton.xaml" />
28+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Toolbar/ToolbarToggleButton/ToolbarToggleButton.xaml" />
29+
<!--#endregion-->
30+
31+
<!--#region ThemedIcon Styles-->
2532
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/Styles/Icons.Common.xaml" />
2633
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/Styles/Icons.New.xaml" />
2734
<ResourceDictionary Source="ms-appx:///Files.App.Controls/ThemedIcon/Styles/Icons.Open.xaml" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Controls
5+
{
6+
/// <summary>
7+
/// Interface to scope allowed items in the Private Item list
8+
/// </summary>
9+
public interface IToolbarItemSet
10+
{
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Controls
5+
{
6+
/// <summary>
7+
/// Interface to scope allowed items in the Private Overflow list
8+
/// </summary>
9+
public interface IToolbarOverflowItemSet
10+
{
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Controls.Primitives
5+
{
6+
public enum OverflowBehaviors
7+
{
8+
/// <summary>
9+
/// Item will move to the overflow menu if space available is too small
10+
/// </summary>
11+
Auto,
12+
13+
/// <summary>
14+
/// Item will always appear in the overflow menu
15+
/// </summary>
16+
Always,
17+
18+
/// <summary>
19+
/// Item will never move to the overflow menu
20+
/// </summary>
21+
Never,
22+
}
23+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using Windows.Foundation;
7+
8+
namespace Files.App.Controls.Primitives
9+
{
10+
public partial class ToolbarLayout : NonVirtualizingLayout
11+
{
12+
private Size m_availableSize;
13+
14+
public ToolbarLayout()
15+
{
16+
17+
}
18+
19+
private int GetItemCount(NonVirtualizingLayoutContext context)
20+
{
21+
return context.Children.Count;
22+
}
23+
24+
private UIElement GetElementAt(NonVirtualizingLayoutContext context , int index)
25+
{
26+
return context.Children[index];
27+
}
28+
29+
// Measuring is performed in a single step, every element is measured, including the overflow button
30+
// item, but the total amount of space needed is only composed of the Toolbar Items
31+
protected override Size MeasureOverride(NonVirtualizingLayoutContext context , Size availableSize)
32+
{
33+
m_availableSize = availableSize;
34+
35+
Size accumulatedItemsSize = new(0, 0);
36+
37+
for (int i = 0; i < GetItemCount(context); ++i)
38+
{
39+
//var toolbarItem = (ToolbarItem)GetElementAt(context, i);
40+
//toolbarItem.Measure( availableSize );
41+
42+
if ( i != 0 )
43+
{
44+
//accumulatedItemsSize.Width += toolbarItem.DesiredSize.Width;
45+
//accumulatedItemsSize.Height = Math.Max( accumulatedItemsSize.Height , toolbarItem.DesiredSize.Height );
46+
}
47+
}
48+
49+
if ( accumulatedItemsSize.Width > availableSize.Width )
50+
{
51+
52+
}
53+
else
54+
{
55+
56+
}
57+
58+
return accumulatedItemsSize;
59+
}
60+
61+
private void ArrangeItem(UIElement breadcrumbItem , ref float accumulatedWidths , float maxElementHeight)
62+
{
63+
}
64+
65+
// Arranging is performed in a single step, as many elements are tried to be drawn going from the last element
66+
// towards the first one, if there's not enough space, then the ellipsis button is drawn
67+
protected override Size ArrangeOverride(NonVirtualizingLayoutContext context , Size finalSize)
68+
{
69+
return finalSize;
70+
}
71+
}
72+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Controls.Primitives
5+
{
6+
public enum ToolbarSizes
7+
{
8+
/// <summary>
9+
/// Buttons set to 32 x 32 size
10+
/// </summary>
11+
Small,
12+
13+
/// <summary>
14+
/// Buttons set to 32 x 32 size
15+
/// </summary>
16+
Medium,
17+
18+
/// <summary>
19+
/// Buttons set to 40 x 40 size
20+
/// </summary>
21+
Large,
22+
}
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Controls
5+
{
6+
// TemplateParts
7+
[TemplatePart( Name = ToolbarItemsRepeaterPartName , Type = typeof( ItemsRepeater ) )]
8+
9+
// VisualStates
10+
[TemplateVisualState( Name = OverflowOnStateName , GroupName = CommonStatesGroupName )]
11+
[TemplateVisualState( Name = OverflowOffStateName , GroupName = CommonStatesGroupName )]
12+
public partial class Toolbar : Control
13+
{
14+
// TemplatePart Names
15+
internal const string ToolbarItemsRepeaterPartName = "PART_ItemsRepeater";
16+
17+
// VisualState Group Names
18+
internal const string CommonStatesGroupName = "OverflowStates";
19+
20+
// VisualState Names
21+
internal const string OverflowOnStateName = "OverflowOn";
22+
internal const string OverflowOffStateName = "OverflowOff";
23+
// ResourceDictionary Keys
24+
internal const string SmallMinWidthResourceKey = "ToolbarButtonSmallMinWidth";
25+
internal const string SmallMinHeightResourceKey = "ToolbarButtonSmallMinHeight";
26+
27+
internal const string MediumMinWidthResourceKey = "ToolbarButtonMediumMinWidth";
28+
internal const string MediumMinHeightResourceKey = "ToolbarButtonMediumMinHeight";
29+
30+
internal const string LargeMinWidthResourceKey = "ToolbarButtonLargeMinWidth";
31+
internal const string LargeMinHeightResourceKey = "ToolbarButtonLargeMinHeight";
32+
}
33+
}

0 commit comments

Comments
 (0)