Skip to content

Commit c61b706

Browse files
committed
Initial commit
1 parent 79b7621 commit c61b706

17 files changed

+1068
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI;
5+
using Microsoft.UI.Xaml;
6+
using Microsoft.UI.Xaml.Controls;
7+
using Microsoft.UI.Xaml.Input;
8+
using Microsoft.UI.Xaml.Markup;
9+
using Microsoft.UI.Xaml.Media;
10+
using Microsoft.UI.Xaml.Shapes;
11+
12+
namespace Files.App.Controls
13+
{
14+
public partial class BreadcrumbBar
15+
{
16+
private void RootItemButton_PointerEntered(object sender, PointerRoutedEventArgs e)
17+
{
18+
VisualStateManager.GoToState(this, "PointerOverItem", true);
19+
}
20+
21+
private void RootItemButton_PointerPressed(object sender, PointerRoutedEventArgs e)
22+
{
23+
VisualStateManager.GoToState(this, "PointerPressedOnItem", true);
24+
}
25+
26+
private void RootItemButton_PointerReleased(object sender, PointerRoutedEventArgs e)
27+
{
28+
RootItemClicked?.Invoke(this, EventArgs.Empty);
29+
30+
VisualStateManager.GoToState(this, "PointerOverItem", true);
31+
}
32+
33+
private void RootItemButton_PointerExited(object sender, PointerRoutedEventArgs e)
34+
{
35+
VisualStateManager.GoToState(this, "PointerNormal", true);
36+
}
37+
38+
private void RootChevronItemButton_PointerEntered(object sender, PointerRoutedEventArgs e)
39+
{
40+
VisualStateManager.GoToState(this, "PointerOverChevron", true);
41+
}
42+
43+
private void RootChevronItemButton_PointerPressed(object sender, PointerRoutedEventArgs e)
44+
{
45+
VisualStateManager.GoToState(this, "PointerPressedOnChevron", true);
46+
}
47+
48+
private void RootChevronItemButton_PointerReleased(object sender, PointerRoutedEventArgs e)
49+
{
50+
VisualStateManager.GoToState(this, "PointerOverChevron", true);
51+
52+
FlyoutBase.ShowAttachedFlyout(_rootItemChevronButton);
53+
}
54+
55+
private void RootChevronItemButton_PointerExited(object sender, PointerRoutedEventArgs e)
56+
{
57+
VisualStateManager.GoToState(this, "PointerNormal", true);
58+
}
59+
60+
private void RootItemChevronDropDownMenuFlyout_Opening(object? sender, object e)
61+
{
62+
if (sender is not MenuFlyout flyout)
63+
return;
64+
65+
RootItemDropDownFlyoutOpening?.Invoke(this, new(flyout));
66+
}
67+
68+
private void RootItemChevronDropDownMenuFlyout_Opened(object? sender, object e)
69+
{
70+
VisualStateManager.GoToState(this, "ChevronNormalOn", true);
71+
}
72+
73+
private void RootItemChevronDropDownMenuFlyout_Closed(object? sender, object e)
74+
{
75+
if (sender is not MenuFlyout flyout)
76+
return;
77+
78+
RootItemDropDownFlyoutClosed?.Invoke(this, new(flyout));
79+
80+
VisualStateManager.GoToState(this, "ChevronNormalOff", true);
81+
VisualStateManager.GoToState(this, "PointerNormal", true);
82+
}
83+
84+
private void ItemsRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args)
85+
{
86+
if (args.Element is not BreadcrumbBarItem item)
87+
return;
88+
89+
item.SetOwner(this);
90+
}
91+
}
92+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using CommunityToolkit.WinUI;
5+
using Microsoft.UI;
6+
using Microsoft.UI.Xaml;
7+
using Microsoft.UI.Xaml.Controls;
8+
using Microsoft.UI.Xaml.Input;
9+
using Microsoft.UI.Xaml.Markup;
10+
using Microsoft.UI.Xaml.Media;
11+
using Microsoft.UI.Xaml.Shapes;
12+
13+
namespace Files.App.Controls
14+
{
15+
public partial class BreadcrumbBar : Control
16+
{
17+
[GeneratedDependencyProperty]
18+
public partial object? ItemsSource { get; set; }
19+
20+
[GeneratedDependencyProperty]
21+
public partial object? ItemTemplate { get; set; }
22+
23+
[GeneratedDependencyProperty]
24+
public partial FrameworkElement? RootElement { get; set; }
25+
26+
partial void OnItemsSourceChanged(object? newValue)
27+
{
28+
}
29+
30+
partial void OnItemTemplateChanged(object? newValue)
31+
{
32+
}
33+
}
34+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using CommunityToolkit.WinUI;
5+
using Microsoft.UI;
6+
using Microsoft.UI.Xaml;
7+
using Microsoft.UI.Xaml.Controls;
8+
using Microsoft.UI.Xaml.Input;
9+
using Microsoft.UI.Xaml.Markup;
10+
using Microsoft.UI.Xaml.Media;
11+
using Microsoft.UI.Xaml.Shapes;
12+
using System;
13+
using Windows.Foundation;
14+
15+
namespace Files.App.Controls
16+
{
17+
// Template parts
18+
[TemplatePart(Name = "PART_ItemsRepeater", Type = typeof(ItemsRepeater))]
19+
public partial class BreadcrumbBar : Control
20+
{
21+
// Constants
22+
23+
private const string TemplatePartName_RootItemButton = "PART_RootItemButton";
24+
private const string TemplatePartName_RootItemChevronButton = "PART_RootItemChevronButton";
25+
private const string TemplatePartName_RootElementChevronDropDownMenuFlyout = "PART_RootElementChevronDropDownMenuFlyout";
26+
private const string TemplatePartName_MainItemsRepeater = "PART_MainItemsRepeater";
27+
28+
// Fields
29+
30+
private BreadcrumbBarLayout _itemsRepeaterLayout = null!;
31+
32+
private Border? _rootItemButton;
33+
private Border? _rootItemChevronButton;
34+
private MenuFlyout? _rootItemChevronDropDownMenuFlyout;
35+
private ItemsRepeater? _itemsRepeater;
36+
37+
// Events
38+
39+
public event TypedEventHandler<BreadcrumbBar, BreadcrumbBarItemClickedEventArgs>? ItemClicked;
40+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? ItemDropDownFlyoutOpening;
41+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? ItemDropDownFlyoutClosed;
42+
43+
public event EventHandler? RootItemClicked;
44+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? RootItemDropDownFlyoutOpening;
45+
public event EventHandler<BreadcrumbBarItemDropDownFlyoutEventArgs>? RootItemDropDownFlyoutClosed;
46+
47+
// Constructor
48+
49+
public BreadcrumbBar()
50+
{
51+
DefaultStyleKey = typeof(BreadcrumbBar);
52+
53+
_itemsRepeaterLayout = new(this, 2d);
54+
}
55+
56+
// Methods
57+
58+
protected override void OnApplyTemplate()
59+
{
60+
_rootItemButton = GetTemplateChild(TemplatePartName_RootItemButton) as Border
61+
?? throw new MissingFieldException($"Could not find {TemplatePartName_RootItemButton} in the given {nameof(BreadcrumbBar)}'s style.");
62+
_rootItemChevronButton = GetTemplateChild(TemplatePartName_RootItemChevronButton) as Border
63+
?? throw new MissingFieldException($"Could not find {TemplatePartName_RootItemChevronButton} in the given {nameof(BreadcrumbBar)}'s style.");
64+
_rootItemChevronDropDownMenuFlyout = GetTemplateChild(TemplatePartName_RootElementChevronDropDownMenuFlyout) as MenuFlyout
65+
?? throw new MissingFieldException($"Could not find {TemplatePartName_RootElementChevronDropDownMenuFlyout} in the given {nameof(BreadcrumbBar)}'s style.");
66+
_itemsRepeater = GetTemplateChild(TemplatePartName_MainItemsRepeater) as ItemsRepeater
67+
?? throw new MissingFieldException($"Could not find {TemplatePartName_MainItemsRepeater} in the given {nameof(BreadcrumbBar)}'s style.");
68+
69+
_itemsRepeater.Layout = _itemsRepeaterLayout;
70+
71+
_rootItemButton.PointerEntered += RootItemButton_PointerEntered;
72+
_rootItemButton.PointerPressed += RootItemButton_PointerPressed;
73+
_rootItemButton.PointerReleased += RootItemButton_PointerReleased;
74+
_rootItemButton.PointerExited += RootItemButton_PointerExited;
75+
76+
_rootItemChevronButton.PointerEntered += RootChevronItemButton_PointerEntered;
77+
_rootItemChevronButton.PointerPressed += RootChevronItemButton_PointerPressed;
78+
_rootItemChevronButton.PointerReleased += RootChevronItemButton_PointerReleased;
79+
_rootItemChevronButton.PointerExited += RootChevronItemButton_PointerExited;
80+
81+
_rootItemChevronDropDownMenuFlyout.Opening += RootItemChevronDropDownMenuFlyout_Opening;
82+
_rootItemChevronDropDownMenuFlyout.Opened += RootItemChevronDropDownMenuFlyout_Opened;
83+
_rootItemChevronDropDownMenuFlyout.Closed += RootItemChevronDropDownMenuFlyout_Closed;
84+
85+
_itemsRepeater.ElementPrepared += ItemsRepeater_ElementPrepared;
86+
87+
base.OnApplyTemplate();
88+
}
89+
90+
internal void RaiseItemClickedEvent(BreadcrumbBarItem item)
91+
{
92+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
93+
var eventArgs = new BreadcrumbBarItemClickedEventArgs(item, index);
94+
ItemClicked?.Invoke(this, eventArgs);
95+
}
96+
97+
internal void RaiseItemDropDownFlyoutOpening(BreadcrumbBarItem item, MenuFlyout flyout)
98+
{
99+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
100+
ItemDropDownFlyoutOpening?.Invoke(this, new(flyout, item, index));
101+
}
102+
103+
internal void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem item, MenuFlyout flyout)
104+
{
105+
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
106+
ItemDropDownFlyoutClosed?.Invoke(this, new(flyout, item, index));
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)