Skip to content

Commit d8580d6

Browse files
committed
Init
1 parent 5652daa commit d8580d6

17 files changed

+636
-585
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public BreadcrumbBar()
4242
{
4343
DefaultStyleKey = typeof(BreadcrumbBar);
4444

45-
_itemsRepeaterLayout = new(this, 2d);
45+
_itemsRepeaterLayout = new(this);
4646
}
4747

4848
// Methods

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.xaml

+22-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
66
xmlns:local="using:Files.App.Controls">
77

8-
<x:Double x:Key="BreadcrumbBarHeight">32</x:Double>
8+
<x:Double x:Key="BreadcrumbBarHeight">34</x:Double>
99
<x:Double x:Key="BreadcrumbBarMinWidth">120</x:Double>
1010
<x:Double x:Key="BreadcrumbBarEllipsisFontSize">16</x:Double>
1111

1212
<Thickness x:Key="BreadcrumbBarChevronPadding">4,0</Thickness>
1313
<Thickness x:Key="BreadcrumbBarItemPadding">8,0</Thickness>
1414
<Thickness x:Key="BreadcrumbBarRootItemPadding">16,0,8,0</Thickness>
15+
<Thickness x:Key="BreadcrumbBarItemMargin">2,0,0,0</Thickness>
1516

1617
<CornerRadius x:Key="BreadcrumbBarItemCornerRadius">2,2,2,2</CornerRadius>
1718
<CornerRadius x:Key="BreadcrumbBarChevronCornerRaduis">2,2,2,2</CornerRadius>
@@ -21,15 +22,28 @@
2122
<Style BasedOn="{StaticResource DefaultBreadcrumbBarItemStyle}" TargetType="local:BreadcrumbBarItem" />
2223

2324
<Style x:Key="DefaultBreadcrumbBarStyle" TargetType="local:BreadcrumbBar">
25+
26+
<Setter Property="Background" Value="Transparent" />
27+
2428
<Setter Property="MinWidth" Value="{StaticResource BreadcrumbBarMinWidth}" />
29+
30+
<Setter Property="HorizontalAlignment" Value="Stretch" />
31+
<Setter Property="HorizontalContentAlignment" Value="Center" />
32+
<Setter Property="VerticalAlignment" Value="Stretch" />
33+
<Setter Property="VerticalContentAlignment" Value="Center" />
34+
2535
<Setter Property="AutomationProperties.LandmarkType" Value="Navigation" />
36+
2637
<Setter Property="IsTabStop" Value="False" />
38+
2739
<Setter Property="Template">
2840
<Setter.Value>
2941
<ControlTemplate TargetType="local:BreadcrumbBar">
3042
<Grid
3143
MinWidth="{TemplateBinding MinWidth}"
32-
ColumnSpacing="2"
44+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
45+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
46+
Background="{TemplateBinding Background}"
3347
TabFocusNavigation="Once"
3448
XYFocusKeyboardNavigation="Enabled">
3549
<Grid.ColumnDefinitions>
@@ -50,6 +64,7 @@
5064
<local:BreadcrumbBarItem
5165
x:Name="PART_EllipsisBreadcrumbBarItem"
5266
Grid.Column="1"
67+
Margin="{StaticResource BreadcrumbBarItemMargin}"
5368
AutomationProperties.AccessibilityView="Content"
5469
IsEllipsis="True"
5570
Visibility="Collapsed">
@@ -59,6 +74,7 @@
5974
<ItemsRepeater
6075
x:Name="PART_MainItemsRepeater"
6176
Grid.Column="2"
77+
Margin="{StaticResource BreadcrumbBarItemMargin}"
6278
ItemTemplate="{Binding ItemTemplate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
6379
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
6480

@@ -85,7 +101,7 @@
85101
<Setter Property="HorizontalAlignment" Value="Stretch" />
86102
<Setter Property="HorizontalContentAlignment" Value="Center" />
87103
<Setter Property="VerticalAlignment" Value="Stretch" />
88-
<Setter Property="VerticalContentAlignment" Value="Center" />
104+
<Setter Property="VerticalContentAlignment" Value="Stretch" />
89105

90106
<Setter Property="FocusVisualMargin" Value="1" />
91107
<Setter Property="IsTabStop" Value="False" />
@@ -95,7 +111,6 @@
95111
<ControlTemplate TargetType="local:BreadcrumbBarItem">
96112
<Grid
97113
x:Name="PART_LayoutRoot"
98-
ColumnSpacing="2"
99114
TabFocusNavigation="Once"
100115
XYFocusKeyboardNavigation="Enabled">
101116
<Grid.ColumnDefinitions>
@@ -107,7 +122,7 @@
107122
<Button
108123
x:Name="PART_ItemContentButton"
109124
Padding="{TemplateBinding Padding}"
110-
VerticalAlignment="Stretch"
125+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
111126
AutomationProperties.AccessibilityView="Raw"
112127
Background="{TemplateBinding Background}"
113128
BorderBrush="{TemplateBinding BorderBrush}"
@@ -151,8 +166,9 @@
151166
<Button
152167
x:Name="PART_ItemChevronButton"
153168
Grid.Column="1"
169+
Margin="{StaticResource BreadcrumbBarItemMargin}"
154170
Padding="{StaticResource BreadcrumbBarChevronPadding}"
155-
VerticalAlignment="Stretch"
171+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
156172
AutomationProperties.AccessibilityView="Content"
157173
Background="{TemplateBinding Background}"
158174
BorderBrush="{TemplateBinding BorderBrush}"

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public partial class BreadcrumbBarLayout : NonVirtualizingLayout
1313
// Fields
1414

1515
private readonly WeakReference<BreadcrumbBar>? _ownerRef;
16-
private readonly double _spacing = 0d;
1716

1817
private Size _availableSize;
1918
private BreadcrumbBarItem? _ellipsisButton = null;
@@ -24,10 +23,9 @@ public partial class BreadcrumbBarLayout : NonVirtualizingLayout
2423
public int IndexAfterEllipsis { get; private set; }
2524
public int VisibleItemsCount { get; private set; }
2625

27-
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb, double spacing)
26+
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb)
2827
{
2928
_ownerRef = new(breadcrumb);
30-
_spacing = spacing;
3129
}
3230

3331
protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
@@ -79,7 +77,6 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
7977
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
8078

8179
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
82-
accumulatedWidths += _spacing;
8380

8481
VisibleItemsCount++;
8582
}
@@ -95,9 +92,9 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
9592
private int GetFirstIndexToRender(NonVirtualizingLayoutContext context)
9693
{
9794
var itemCount = context.Children.Count;
98-
var accumulatedWidth = _spacing;
95+
var accumulatedWidth = 0d;
9996

100-
// Go through all items from the end
97+
// Go through all items from the last item
10198
for (int index = itemCount - 1; index >= 0; index--)
10299
{
103100
var newAccumulatedWidth = accumulatedWidth + context.Children[index].DesiredSize.Width;

src/Files.App.Controls/Omnibar/Omnibar.Properties.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Media;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Shapes;
10-
using System.Linq;
11-
using System.Collections.Generic;
125

136
namespace Files.App.Controls
147
{
@@ -19,5 +12,8 @@ public partial class Omnibar
1912

2013
[GeneratedDependencyProperty]
2114
public partial OmnibarMode? CurrentSelectedMode { get; set; }
15+
16+
[GeneratedDependencyProperty]
17+
public partial Thickness AutoSuggestBoxPadding { get; set; }
2218
}
2319
}
+48-119
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,60 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using CommunityToolkit.WinUI;
5-
using Microsoft.UI.Xaml;
64
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Media;
85
using Microsoft.UI.Xaml.Markup;
6+
using Microsoft.UI.Xaml.Media;
7+
using Microsoft.UI.Xaml.Media.Animation;
98
using Microsoft.UI.Xaml.Shapes;
10-
using Microsoft.UI.Xaml.Input;
11-
using Microsoft.UI;
12-
using Windows.ApplicationModel.Contacts;
139

1410
namespace Files.App.Controls
1511
{
1612
// Content
1713
[ContentProperty(Name = nameof(Modes))]
18-
// Template parts
19-
[TemplatePart(Name = "PART_ModesHostGrid", Type = typeof(Grid))]
20-
// Visual states
21-
[TemplateVisualState(Name = "Focused", GroupName = "FocusStates")]
22-
[TemplateVisualState(Name = "Normal", GroupName = "FocusStates")]
2314
public partial class Omnibar : Control
2415
{
25-
private const string ModesHostGrid = "PART_ModesHostGrid";
26-
private const string AutoSuggestPopup = "PART_AutoSuggestPopup";
27-
private const string AutoSuggestBoxBorder = "PART_AutoSuggestBoxBorder";
16+
// Constants
17+
18+
private const string TemplatePartName_ModesHostGrid = "PART_ModesHostGrid";
19+
20+
// Fields
2821

2922
private Grid? _modesHostGrid;
30-
private Popup? _autoSuggestPopup;
31-
private Border? _autoSuggestBoxBorder;
32-
private bool _isFocused;
33-
private bool _stillHasFocus;
23+
24+
// Constructor
3425

3526
public Omnibar()
3627
{
3728
DefaultStyleKey = typeof(Omnibar);
3829

39-
Modes ??= [];
30+
Modes = [];
31+
AutoSuggestBoxPadding = new(0, 0, 0, 0);
4032
}
4133

34+
// Methods
35+
4236
protected override void OnApplyTemplate()
4337
{
44-
_modesHostGrid = GetTemplateChild(ModesHostGrid) as Grid
45-
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in the given {nameof(Omnibar)}'s style.");
46-
_autoSuggestPopup = GetTemplateChild(AutoSuggestPopup) as Popup
47-
?? throw new MissingFieldException($"Could not find {AutoSuggestPopup} in the given {nameof(Omnibar)}'s style.");
48-
_autoSuggestBoxBorder = GetTemplateChild(AutoSuggestBoxBorder) as Border
49-
?? throw new MissingFieldException($"Could not find {AutoSuggestBoxBorder} in the given {nameof(Omnibar)}'s style.");
50-
51-
if (Modes is null)
52-
return;
38+
base.OnApplyTemplate();
39+
40+
_modesHostGrid = GetTemplateChild(TemplatePartName_ModesHostGrid) as Grid
41+
?? throw new MissingFieldException($"Could not find {TemplatePartName_ModesHostGrid} in the given {nameof(Omnibar)}'s style.");
5342

54-
// Add shadow to the popup and set the proper width
55-
_autoSuggestBoxBorder!.Translation = new(0, 0, 32);
56-
_autoSuggestBoxBorder!.Width = _modesHostGrid!.ActualWidth;
43+
PopulateModes();
44+
}
45+
46+
public void PopulateModes()
47+
{
48+
if (Modes is null || _modesHostGrid is null)
49+
return;
5750

5851
// Populate the modes
5952
foreach (var mode in Modes)
6053
{
6154
// Insert a divider
6255
if (_modesHostGrid.Children.Count is not 0)
6356
{
64-
var divider = new Rectangle()
65-
{
66-
Fill = (SolidColorBrush)Application.Current.Resources["DividerStrokeColorDefaultBrush"],
67-
Height = 20,
68-
Margin = new(2,0,2,0),
69-
Width = 1,
70-
};
57+
var divider = new OmnibarModeSeparator();
7158

7259
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
7360
Grid.SetColumn(divider, _modesHostGrid.Children.Count);
@@ -78,103 +65,45 @@ protected override void OnApplyTemplate()
7865
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
7966
Grid.SetColumn(mode, _modesHostGrid.Children.Count);
8067
_modesHostGrid.Children.Add(mode);
81-
mode.Host = this;
68+
mode.SetOwner(this);
8269
}
83-
84-
_modesHostGrid.SizeChanged += ModesHostGrid_SizeChanged;
85-
86-
GotFocus += Omnibar_GotFocus;
87-
LostFocus += Omnibar_LostFocus;
88-
LosingFocus += Omnibar_LosingFocus;
89-
90-
UpdateVisualStates();
91-
92-
base.OnApplyTemplate();
9370
}
9471

95-
// Methods
96-
9772
internal void ChangeMode(OmnibarMode modeToExpand)
9873
{
9974
if (_modesHostGrid is null || Modes is null)
100-
throw new NullReferenceException();
101-
102-
// Reset
103-
foreach (var column in _modesHostGrid.ColumnDefinitions)
104-
column.Width = GridLength.Auto;
105-
foreach (var mode in Modes)
106-
VisualStateManager.GoToState(mode, "Unfocused", true);
107-
108-
// Expand the given mode
109-
VisualStateManager.GoToState(modeToExpand, "Focused", true);
110-
_modesHostGrid.ColumnDefinitions[_modesHostGrid.Children.IndexOf(modeToExpand)].Width = new(1, GridUnitType.Star);
111-
112-
CurrentSelectedMode = modeToExpand;
113-
114-
UpdateVisualStates();
115-
}
116-
117-
private void UpdateVisualStates()
118-
{
119-
VisualStateManager.GoToState(this, _isFocused ? "Focused" : "Normal", true);
75+
return;
12076

121-
if (CurrentSelectedMode is not null && _autoSuggestPopup is not null)
122-
{
123-
// Close anyway
124-
if (_autoSuggestPopup.IsOpen && CurrentSelectedMode.SuggestionItemsSource is null)
125-
VisualStateManager.GoToState(this, "PopupClosed", true);
77+
var index = _modesHostGrid.Children.IndexOf(modeToExpand);
12678

127-
// Decide open or close
128-
if (_isFocused != _autoSuggestPopup.IsOpen)
129-
VisualStateManager.GoToState(this, _isFocused && CurrentSelectedMode.SuggestionItemsSource is not null ? "PopupOpened" : "PopupClosed", true);
130-
}
79+
// Add the reposition transition to the old item
80+
//foreach (var mode in Modes)
81+
// mode.Transitions = [ new RepositionThemeTransition() ];
13182

13283
if (CurrentSelectedMode is not null)
133-
VisualStateManager.GoToState(
134-
CurrentSelectedMode,
135-
_isFocused
136-
? "Focused"
137-
: CurrentSelectedMode.ContentOnInactive is null
138-
? "CurrentUnfocusedWithoutInactiveMode"
139-
: "CurrentUnfocusedWithInactiveMode",
140-
true);
141-
}
84+
VisualStateManager.GoToState(CurrentSelectedMode, "Unfocused", true);
14285

143-
// Events
86+
// Reset
87+
foreach (var column in _modesHostGrid.ColumnDefinitions)
88+
column.Width = GridLength.Auto;
14489

145-
private void ModesHostGrid_SizeChanged(object sender, SizeChangedEventArgs e)
146-
{
147-
_autoSuggestBoxBorder!.Width = _modesHostGrid!.ActualWidth;
148-
}
90+
// Expand the given mode
91+
_modesHostGrid.ColumnDefinitions[index].Width = new(1, GridUnitType.Star);
14992

150-
private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
151-
{
152-
_isFocused = true;
153-
UpdateVisualStates();
154-
}
93+
VisualStateManager.GoToState(modeToExpand, "Focused", true);
15594

156-
private void Omnibar_LosingFocus(UIElement sender, LosingFocusEventArgs args)
157-
{
158-
// Ignore when user clicks on the TextBox or the button area of an OmnibarMode, Omnibar still has focus anyway
159-
if (args.NewFocusedElement?.GetType() is not { } focusedType ||
160-
focusedType == typeof(TextBox) ||
161-
focusedType == typeof(OmnibarMode) ||
162-
focusedType == typeof(Omnibar))
163-
{
164-
_stillHasFocus = true;
165-
}
166-
}
95+
// Remove it again
96+
//foreach (var mode in Modes)
97+
// mode.Transitions.Clear();
16798

168-
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
169-
{
170-
if (_stillHasFocus)
171-
{
172-
_stillHasFocus = false;
173-
return;
174-
}
99+
// Set the correct AutoSuggestBox cursor position
100+
var itemCount = Modes.Count;
101+
var itemIndex = Modes.IndexOf(modeToExpand);
102+
var leftPadding = (itemIndex + 1) * modeToExpand.ActualWidth + 9 * itemIndex + 4;
103+
var rightPadding = (itemCount - itemIndex - 1) * modeToExpand.ActualWidth + 9 * (itemCount - itemIndex - 1) + 8;
104+
AutoSuggestBoxPadding = new(leftPadding, 5, rightPadding, 6);
175105

176-
_isFocused = false;
177-
UpdateVisualStates();
106+
CurrentSelectedMode = modeToExpand;
178107
}
179108
}
180109
}

0 commit comments

Comments
 (0)