Skip to content

Commit 957cc89

Browse files
committed
Initialize Omnibar templates
1 parent 635700f commit 957cc89

File tree

10 files changed

+402
-0
lines changed

10 files changed

+402
-0
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<PackageVersion Include="ByteSize" Version="2.1.2" />
88
<PackageVersion Include="ColorCode.WinUI" Version="2.0.15" />
99
<PackageVersion Include="CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock" Version="0.1.250206-build.2040" />
10+
<PackageVersion Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
1011
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
1112
<PackageVersion Include="CommunityToolkit.WinUI.Behaviors" Version="8.2.250129-preview2" />
1213
<PackageVersion Include="CommunityToolkit.WinUI.Controls.ColorPicker" Version="8.2.250129-preview2" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="CommunityToolkit.WinUI.Extensions" />
17+
<PackageReference Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" />
1718
<PackageReference Include="Microsoft.WindowsAppSDK" />
1819
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
1920
<PackageReference Include="Microsoft.Windows.CsWinRT" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
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;
12+
13+
namespace Files.App.Controls
14+
{
15+
public partial class Omnibar
16+
{
17+
[GeneratedDependencyProperty]
18+
public partial IList<OmnibarMode>? Modes { get; set; }
19+
}
20+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using Microsoft.UI.Xaml.Media;
7+
using Microsoft.UI.Xaml.Markup;
8+
using Microsoft.UI.Xaml.Shapes;
9+
using System.Linq;
10+
using System.Collections.Generic;
11+
using Microsoft.UI.Xaml.Input;
12+
13+
namespace Files.App.Controls
14+
{
15+
// Content
16+
[ContentProperty(Name = nameof(Modes))]
17+
// Template parts
18+
[TemplatePart(Name = "ModesItemsRepeater", Type = typeof(ItemsRepeater))]
19+
// Visual states
20+
[TemplateVisualState(Name = "Focused", GroupName = "FocusStates")]
21+
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusStates")]
22+
public partial class Omnibar : Control
23+
{
24+
private const string ModesItemsRepeater = "ModesItemsRepeater";
25+
26+
private ItemsRepeater? _modesItemsRepeater;
27+
28+
public Omnibar()
29+
{
30+
DefaultStyleKey = typeof(Omnibar);
31+
32+
Modes ??= [];
33+
}
34+
35+
protected override void OnApplyTemplate()
36+
{
37+
_modesItemsRepeater = GetTemplateChild(ModesItemsRepeater) as ItemsRepeater
38+
?? throw new MissingFieldException($"Could not find {ModesItemsRepeater} in {nameof(Omnibar)}'s style.");
39+
40+
_modesItemsRepeater.ItemsSource = Modes;
41+
42+
GotFocus += Omnibar_GotFocus;
43+
LostFocus += Omnibar_LostFocus;
44+
45+
base.OnApplyTemplate();
46+
}
47+
48+
private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
49+
{
50+
VisualStateManager.GoToState(this, "Focused", true);
51+
}
52+
53+
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
54+
{
55+
var focus = FocusState;
56+
57+
VisualStateManager.GoToState(this, "Unfocused", true);
58+
}
59+
}
60+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
2+
<ResourceDictionary
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Files.App.Controls">
6+
7+
<ResourceDictionary.ThemeDictionaries>
8+
<ResourceDictionary x:Key="Default">
9+
<SolidColorBrush x:Key="SystemControlSplitterPressed" Color="{ThemeResource SystemBaseHighColor}" />
10+
</ResourceDictionary>
11+
<ResourceDictionary x:Key="HighContrast">
12+
<SolidColorBrush x:Key="SystemControlSplitterPressed" Color="{ThemeResource SystemColorHighlightColor}" />
13+
</ResourceDictionary>
14+
</ResourceDictionary.ThemeDictionaries>
15+
16+
<x:Double x:Key="OmnibarDefaultHeight">40</x:Double>
17+
<CornerRadius x:Key="OmnibarDefaultCornerRadius">20</CornerRadius>
18+
<Thickness x:Key="OmnibarFocusedBorderThickness">2</Thickness>
19+
<Thickness x:Key="OmnibarUnfocusedBorderThickness">1</Thickness>
20+
21+
<Style BasedOn="{StaticResource DefaultOmnibarStyle}" TargetType="local:Omnibar" />
22+
23+
<Style x:Key="DefaultOmnibarStyle" TargetType="local:Omnibar">
24+
<Setter Property="IsTabStop" Value="True" />
25+
<Setter Property="Height" Value="{StaticResource OmnibarDefaultHeight}" />
26+
<Setter Property="UseSystemFocusVisuals" Value="True" />
27+
<Setter Property="HorizontalAlignment" Value="Stretch" />
28+
<Setter Property="Background" Value="Transparent" />
29+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
30+
<Setter Property="CornerRadius" Value="{StaticResource OmnibarDefaultCornerRadius}" />
31+
<Setter Property="VerticalAlignment" Value="Center" />
32+
<Setter Property="IsFocusEngagementEnabled" Value="True" />
33+
<Setter Property="Template">
34+
<Setter.Value>
35+
<ControlTemplate TargetType="local:Omnibar">
36+
<Grid
37+
x:Name="PART_RootGrid"
38+
Background="{TemplateBinding Background}"
39+
CornerRadius="{TemplateBinding CornerRadius}">
40+
<ItemsRepeater x:Name="ModesItemsRepeater">
41+
<ItemsRepeater.Layout>
42+
<StackLayout Orientation="Horizontal" Spacing="2" />
43+
</ItemsRepeater.Layout>
44+
</ItemsRepeater>
45+
46+
<VisualStateManager.VisualStateGroups>
47+
48+
<VisualStateGroup x:Name="FocusStates">
49+
<VisualState x:Name="Focused">
50+
<VisualState.Setters>
51+
<Setter Target="PART_RootGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
52+
<Setter Target="PART_RootGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
53+
<Setter Target="PART_RootGrid.Margin" Value="-1" />
54+
</VisualState.Setters>
55+
</VisualState>
56+
<VisualState x:Name="Unfocused">
57+
<VisualState.Setters>
58+
<Setter Target="PART_RootGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
59+
<Setter Target="PART_RootGrid.BorderThickness" Value="{StaticResource OmnibarUnfocusedBorderThickness}" />
60+
</VisualState.Setters>
61+
</VisualState>
62+
</VisualStateGroup>
63+
64+
</VisualStateManager.VisualStateGroups>
65+
</Grid>
66+
</ControlTemplate>
67+
</Setter.Value>
68+
</Setter>
69+
</Style>
70+
71+
</ResourceDictionary>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
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;
12+
13+
namespace Files.App.Controls
14+
{
15+
public partial class OmnibarMode
16+
{
17+
[GeneratedDependencyProperty]
18+
public partial string? Text { get; set; }
19+
20+
[GeneratedDependencyProperty]
21+
public partial bool HideContentOnInactive { get; set; }
22+
23+
[GeneratedDependencyProperty]
24+
public partial FrameworkElement? IconOnActive { get; set; }
25+
26+
[GeneratedDependencyProperty]
27+
public partial FrameworkElement? IconOnInactive { get; set; }
28+
29+
[GeneratedDependencyProperty]
30+
private partial FrameworkElement? Icon { get; set; }
31+
32+
[GeneratedDependencyProperty]
33+
public partial DataTemplate? SuggestionItemTemplate { get; set; }
34+
}
35+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using Microsoft.UI.Xaml.Input;
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;
12+
13+
namespace Files.App.Controls
14+
{
15+
public partial class OmnibarMode : Control
16+
{
17+
public OmnibarMode()
18+
{
19+
DefaultStyleKey = typeof(Omnibar);
20+
}
21+
22+
protected override void OnApplyTemplate()
23+
{
24+
PointerEntered += OmnibarMode_PointerEntered;
25+
PointerPressed += OmnibarMode_PointerPressed;
26+
PointerReleased += OmnibarMode_PointerReleased;
27+
PointerExited += OmnibarMode_PointerExited;
28+
29+
base.OnApplyTemplate();
30+
}
31+
32+
private void OmnibarMode_PointerExited(object sender, PointerRoutedEventArgs e)
33+
{
34+
VisualStateManager.GoToState(this, "Normal", true);
35+
}
36+
37+
private void OmnibarMode_PointerReleased(object sender, PointerRoutedEventArgs e)
38+
{
39+
VisualStateManager.GoToState(this, "PointerOver", true);
40+
}
41+
42+
private void OmnibarMode_PointerPressed(object sender, PointerRoutedEventArgs e)
43+
{
44+
VisualStateManager.GoToState(this, "Pressed", true);
45+
}
46+
47+
private void OmnibarMode_PointerEntered(object sender, PointerRoutedEventArgs e)
48+
{
49+
VisualStateManager.GoToState(this, "PointerOver", true);
50+
}
51+
}
52+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
2+
<ResourceDictionary
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Files.App.Controls">
6+
7+
<x:Double x:Key="OmnibarModeDefaultHeight">36</x:Double>
8+
<x:Double x:Key="OmnibarModeDefaultClickAreaWidth">48</x:Double>
9+
<CornerRadius x:Key="OmnibarDefaultCornerRadius">18</CornerRadius>
10+
11+
<Style BasedOn="{StaticResource DefaultOmnibarModeStyle}" TargetType="local:OmnibarMode" />
12+
13+
<Style x:Key="DefaultOmnibarModeStyle" TargetType="local:OmnibarMode">
14+
<Setter Property="IsTabStop" Value="True" />
15+
<Setter Property="Height" Value="{StaticResource OmnibarModeDefaultHeight}" />
16+
<Setter Property="UseSystemFocusVisuals" Value="True" />
17+
<Setter Property="HorizontalAlignment" Value="Left" />
18+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
19+
<Setter Property="CornerRadius" Value="{StaticResource OmnibarDefaultCornerRadius}" />
20+
<Setter Property="VerticalAlignment" Value="Stretch" />
21+
<Setter Property="IsFocusEngagementEnabled" Value="True" />
22+
<Setter Property="Template">
23+
<Setter.Value>
24+
<ControlTemplate TargetType="local:OmnibarMode">
25+
<Grid x:Name="RootGrid" Height="{TemplateBinding Height}">
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinition Width="Auto" />
28+
<ColumnDefinition Width="*" />
29+
</Grid.ColumnDefinitions>
30+
31+
<Border
32+
x:Name="ModeClickBorder"
33+
Width="{StaticResource OmnibarModeDefaultClickAreaWidth}"
34+
Height="{TemplateBinding Height}"
35+
Background="Transparent"
36+
CornerRadius="{TemplateBinding CornerRadius}">
37+
<Border.BackgroundTransition>
38+
<BrushTransition Duration="0:0:0.083" />
39+
</Border.BackgroundTransition>
40+
41+
<ContentPresenter HorizontalAlignment="Center" Content="{TemplateBinding IconOnInactive}" />
42+
</Border>
43+
44+
<VisualStateManager.VisualStateGroups>
45+
46+
<VisualStateGroup x:Name="CommonStates">
47+
<VisualState x:Name="Normal" />
48+
<VisualState x:Name="PointerOver">
49+
<VisualState.Setters>
50+
<Setter Target="ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorTertiaryBrush}" />
51+
</VisualState.Setters>
52+
</VisualState>
53+
<VisualState x:Name="Pressed">
54+
<VisualState.Setters>
55+
<Setter Target="ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorSecondaryBrush}" />
56+
</VisualState.Setters>
57+
</VisualState>
58+
</VisualStateGroup>
59+
60+
</VisualStateManager.VisualStateGroups>
61+
</Grid>
62+
</ControlTemplate>
63+
</Setter.Value>
64+
</Setter>
65+
</Style>
66+
67+
</ResourceDictionary>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<ResourceDictionary Source="ms-appx:///Files.App.Controls/GridSplitter/GridSplitter.xaml" />
5555
<!--#endregion-->
5656

57+
<!--#region Omnibar-->
58+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Omnibar/Omnibar.xaml" />
59+
<ResourceDictionary Source="ms-appx:///Files.App.Controls/Omnibar/OmnibarMode.xaml" />
60+
<!--#endregion-->
61+
5762
</ResourceDictionary.MergedDictionaries>
5863

5964
</ResourceDictionary>

0 commit comments

Comments
 (0)