Skip to content

Commit 8a69fd7

Browse files
committed
Added initial implementations
1 parent d770b7e commit 8a69fd7

File tree

16 files changed

+623
-118
lines changed

16 files changed

+623
-118
lines changed

src/Files.App.Controls/BladeView/BladeView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
FontSize="14"
126126
Foreground="{TemplateBinding CloseButtonForeground}"
127127
Style="{StaticResource ButtonRevealStyle}"
128-
Visibility="{TemplateBinding CloseButtonVisibility}"
129-
TabIndex="0" />
128+
TabIndex="0"
129+
Visibility="{TemplateBinding CloseButtonVisibility}" />
130130
</Grid>
131131
</ControlTemplate>
132132
</Setter.Value>
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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
using Microsoft.UI;
13+
14+
namespace Files.App.Controls
15+
{
16+
// Content
17+
[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 = "Unfocused", GroupName = "FocusStates")]
23+
public partial class Omnibar : Control
24+
{
25+
private const string ModesHostGrid = "PART_ModesHostGrid";
26+
27+
private Grid? _modesHostGrid;
28+
private bool _isFocused;
29+
30+
public Omnibar()
31+
{
32+
DefaultStyleKey = typeof(Omnibar);
33+
34+
Modes ??= [];
35+
}
36+
37+
protected override void OnApplyTemplate()
38+
{
39+
_modesHostGrid = GetTemplateChild(ModesHostGrid) as Grid
40+
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in the given {nameof(Omnibar)}'s style.");
41+
42+
if (Modes is null)
43+
return;
44+
45+
// Populate the modes1
46+
foreach (var mode in Modes)
47+
{
48+
// Insert a divider
49+
if (_modesHostGrid.Children.Count is not 0)
50+
{
51+
var divider = new Rectangle()
52+
{
53+
Fill = (SolidColorBrush)Application.Current.Resources["DividerStrokeColorDefaultBrush"],
54+
Height = 20,
55+
Margin = new(2,0,2,0),
56+
Width = 1,
57+
};
58+
59+
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
60+
Grid.SetColumn(divider, _modesHostGrid.Children.Count);
61+
_modesHostGrid.Children.Add(divider);
62+
}
63+
64+
// Insert the mode
65+
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
66+
Grid.SetColumn(mode, _modesHostGrid.Children.Count);
67+
_modesHostGrid.Children.Add(mode);
68+
mode.Host = _modesHostGrid;
69+
}
70+
71+
GotFocus += Omnibar_GotFocus;
72+
LostFocus += Omnibar_LostFocus;
73+
74+
UpdateVisualStates();
75+
76+
base.OnApplyTemplate();
77+
}
78+
79+
// Private methods
80+
81+
private void UpdateVisualStates()
82+
{
83+
VisualStateManager.GoToState(
84+
this,
85+
_isFocused ? "Focused" : "Normal",
86+
true);
87+
}
88+
89+
// Events
90+
91+
private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
92+
{
93+
_isFocused = true;
94+
UpdateVisualStates();
95+
}
96+
97+
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
98+
{
99+
_isFocused = false;
100+
UpdateVisualStates();
101+
}
102+
}
103+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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="OmnibarModeDivisiderBrush" Color="{ThemeResource DividerStrokeColorDefaultBrush}" />
10+
</ResourceDictionary>
11+
<ResourceDictionary x:Key="HighContrast">
12+
<SolidColorBrush x:Key="OmnibarModeDivisiderBrush" Color="{ThemeResource DividerStrokeColorDefaultBrush}" />
13+
</ResourceDictionary>
14+
</ResourceDictionary.ThemeDictionaries>-->
15+
16+
<x:Double x:Key="OmnibarDefaultHeight">36</x:Double>
17+
<CornerRadius x:Key="OmnibarDefaultCornerRadius">18</CornerRadius>
18+
<Thickness x:Key="OmnibarFocusedBorderThickness">2</Thickness>
19+
<Thickness x:Key="OmnibarUnfocusedBorderThickness">1</Thickness>
20+
<Thickness x:Key="OmnibarUnfocusedRootPadding">1</Thickness>
21+
22+
<x:Double x:Key="OmnibarModeDividerDefaultHeight">24</x:Double>
23+
<SolidColorBrush x:Key="OmnibarModeDivisiderBrush" Color="{ThemeResource DividerStrokeColorDefaultBrush}" />
24+
25+
<Style BasedOn="{StaticResource DefaultOmnibarStyle}" TargetType="local:Omnibar" />
26+
27+
<Style x:Key="DefaultOmnibarStyle" TargetType="local:Omnibar">
28+
<Setter Property="IsTabStop" Value="True" />
29+
<Setter Property="Height" Value="{StaticResource OmnibarDefaultHeight}" />
30+
<Setter Property="UseSystemFocusVisuals" Value="True" />
31+
<Setter Property="HorizontalAlignment" Value="Stretch" />
32+
<Setter Property="Background" Value="{ThemeResource ControlFillColorDefaultBrush}" />
33+
<Setter Property="Padding" Value="{ThemeResource OmnibarUnfocusedRootPadding}" />
34+
<Setter Property="BorderBrush" Value="{ThemeResource CircleElevationBorderBrush}" />
35+
<Setter Property="BorderThickness" Value="{StaticResource OmnibarUnfocusedBorderThickness}" />
36+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
37+
<Setter Property="CornerRadius" Value="{StaticResource OmnibarDefaultCornerRadius}" />
38+
<Setter Property="VerticalAlignment" Value="Center" />
39+
<Setter Property="IsFocusEngagementEnabled" Value="True" />
40+
<Setter Property="Template">
41+
<Setter.Value>
42+
<ControlTemplate TargetType="local:Omnibar">
43+
<Grid
44+
x:Name="PART_RootGrid"
45+
Padding="{TemplateBinding Padding}"
46+
Background="{TemplateBinding Background}"
47+
BorderBrush="{TemplateBinding BorderBrush}"
48+
BorderThickness="{TemplateBinding BorderThickness}"
49+
CornerRadius="{TemplateBinding CornerRadius}">
50+
<Grid x:Name="PART_ModesHostGrid" />
51+
52+
<VisualStateManager.VisualStateGroups>
53+
54+
<VisualStateGroup x:Name="PointerStates">
55+
<VisualState x:Name="Normal" />
56+
<VisualState x:Name="Focused">
57+
<VisualState.Setters>
58+
<Setter Target="PART_RootGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
59+
<Setter Target="PART_RootGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
60+
<Setter Target="PART_RootGrid.Margin" Value="-1" />
61+
</VisualState.Setters>
62+
</VisualState>
63+
</VisualStateGroup>
64+
65+
</VisualStateManager.VisualStateGroups>
66+
</Grid>
67+
</ControlTemplate>
68+
</Setter.Value>
69+
</Setter>
70+
</Style>
71+
72+
</ResourceDictionary>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
public partial DataTemplate? SuggestionItemTemplate { get; set; }
31+
32+
[GeneratedDependencyProperty]
33+
public partial bool IsDefault { get; set; }
34+
35+
[GeneratedDependencyProperty]
36+
internal partial Grid? Host { get; set; }
37+
38+
partial void OnHostChanged(Grid? newValue)
39+
{
40+
UpdateVisualStates();
41+
}
42+
}
43+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
11+
namespace Files.App.Controls
12+
{
13+
public partial class OmnibarMode : Control
14+
{
15+
private const string ModeClickBorder = "PART_ModeClickBorder";
16+
private const string InputTextBox = "PART_InputTextBox";
17+
18+
private Border? _modeClickArea;
19+
private TextBox? _inputTextBox;
20+
21+
private bool _isHoveredOver;
22+
private bool _isPressed;
23+
24+
public OmnibarMode()
25+
{
26+
DefaultStyleKey = typeof(OmnibarMode);
27+
}
28+
29+
protected override void OnApplyTemplate()
30+
{
31+
_modeClickArea = GetTemplateChild(ModeClickBorder) as Border
32+
?? throw new MissingFieldException($"Could not find {ModeClickBorder} in the given {nameof(OmnibarMode)}'s style.");
33+
_inputTextBox = GetTemplateChild(InputTextBox) as TextBox
34+
?? throw new MissingFieldException($"Could not find {InputTextBox} in the given {nameof(OmnibarMode)}'s style.");
35+
36+
UpdateVisualStates();
37+
38+
_modeClickArea.PointerEntered += OmnibarMode_PointerEntered;
39+
_modeClickArea.PointerPressed += OmnibarMode_PointerPressed;
40+
_modeClickArea.PointerReleased += OmnibarMode_PointerReleased;
41+
_modeClickArea.PointerExited += OmnibarMode_PointerExited;
42+
43+
base.OnApplyTemplate();
44+
}
45+
46+
private void UpdateVisualStates()
47+
{
48+
VisualStateManager.GoToState(
49+
this,
50+
_isPressed ? "PointerPressed" : _isHoveredOver ? "PointerOver" : "PointerNormal",
51+
true);
52+
53+
if (IsDefault && Host is not null)
54+
{
55+
VisualStateManager.GoToState(this, "Visible",true);
56+
Host.ColumnDefinitions[Host.Children.IndexOf(this)].Width = new(1, GridUnitType.Star);
57+
}
58+
}
59+
60+
// Events
61+
62+
private void OmnibarMode_PointerEntered(object sender, PointerRoutedEventArgs e)
63+
{
64+
_isHoveredOver = true;
65+
_isPressed = false;
66+
UpdateVisualStates();
67+
}
68+
69+
private void OmnibarMode_PointerPressed(object sender, PointerRoutedEventArgs e)
70+
{
71+
_isHoveredOver = false;
72+
_isPressed = true;
73+
UpdateVisualStates();
74+
}
75+
76+
private void OmnibarMode_PointerReleased(object sender, PointerRoutedEventArgs e)
77+
{
78+
_isHoveredOver = true;
79+
_isPressed = false;
80+
UpdateVisualStates();
81+
}
82+
83+
private void OmnibarMode_PointerExited(object sender, PointerRoutedEventArgs e)
84+
{
85+
_isHoveredOver = _isPressed = false;
86+
UpdateVisualStates();
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)