Skip to content

Commit a33394a

Browse files
committed
Expand the default mode
1 parent d39a70e commit a33394a

File tree

5 files changed

+102
-23
lines changed

5 files changed

+102
-23
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Omnibar()
3737
protected override void OnApplyTemplate()
3838
{
3939
_modesHostGrid = GetTemplateChild(ModesHostGrid) as Grid
40-
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in {nameof(Omnibar)}'s style.");
40+
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in the given {nameof(Omnibar)}'s style.");
4141

4242
if (Modes is null)
4343
return;
@@ -65,6 +65,7 @@ protected override void OnApplyTemplate()
6565
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
6666
Grid.SetColumn(mode, _modesHostGrid.Children.Count);
6767
_modesHostGrid.Children.Add(mode);
68+
mode.Host = _modesHostGrid;
6869
}
6970

7071
GotFocus += Omnibar_GotFocus;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ public partial class OmnibarMode
2727
public partial FrameworkElement? IconOnInactive { get; set; }
2828

2929
[GeneratedDependencyProperty]
30-
private partial FrameworkElement? Icon { get; set; }
30+
public partial DataTemplate? SuggestionItemTemplate { get; set; }
3131

3232
[GeneratedDependencyProperty]
33-
public partial DataTemplate? SuggestionItemTemplate { get; set; }
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+
}
3442
}
3543
}

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

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,83 @@
77
using Microsoft.UI.Xaml.Media;
88
using Microsoft.UI.Xaml.Markup;
99
using Microsoft.UI.Xaml.Shapes;
10-
using System.Linq;
11-
using System.Collections.Generic;
1210

1311
namespace Files.App.Controls
1412
{
1513
public partial class OmnibarMode : Control
1614
{
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+
1724
public OmnibarMode()
1825
{
1926
DefaultStyleKey = typeof(OmnibarMode);
2027
}
2128

2229
protected override void OnApplyTemplate()
2330
{
24-
PointerEntered += OmnibarMode_PointerEntered;
25-
PointerPressed += OmnibarMode_PointerPressed;
26-
PointerReleased += OmnibarMode_PointerReleased;
27-
PointerExited += OmnibarMode_PointerExited;
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;
2842

2943
base.OnApplyTemplate();
3044
}
3145

32-
private void OmnibarMode_PointerExited(object sender, PointerRoutedEventArgs e)
46+
private void UpdateVisualStates()
3347
{
34-
VisualStateManager.GoToState(this, "Normal", true);
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+
}
3558
}
3659

37-
private void OmnibarMode_PointerReleased(object sender, PointerRoutedEventArgs e)
60+
// Events
61+
62+
private void OmnibarMode_PointerEntered(object sender, PointerRoutedEventArgs e)
3863
{
39-
VisualStateManager.GoToState(this, "PointerOver", true);
64+
_isHoveredOver = true;
65+
_isPressed = false;
66+
UpdateVisualStates();
4067
}
4168

4269
private void OmnibarMode_PointerPressed(object sender, PointerRoutedEventArgs e)
4370
{
44-
VisualStateManager.GoToState(this, "Pressed", true);
71+
_isHoveredOver = false;
72+
_isPressed = true;
73+
UpdateVisualStates();
4574
}
4675

47-
private void OmnibarMode_PointerEntered(object sender, PointerRoutedEventArgs e)
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)
4884
{
49-
VisualStateManager.GoToState(this, "PointerOver", true);
85+
_isHoveredOver = _isPressed = false;
86+
UpdateVisualStates();
5087
}
5188
}
5289
}

src/Files.App.Controls/Omnibar/OmnibarMode.xaml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<Setter Property="Template">
2323
<Setter.Value>
2424
<ControlTemplate TargetType="local:OmnibarMode">
25-
<Grid x:Name="RootGrid" Height="{TemplateBinding Height}">
25+
<Grid x:Name="PART_RootGrid" Height="{TemplateBinding Height}">
2626
<Grid.ColumnDefinitions>
2727
<ColumnDefinition Width="Auto" />
2828
<ColumnDefinition Width="*" />
2929
</Grid.ColumnDefinitions>
3030

3131
<Border
32-
x:Name="ModeClickBorder"
32+
x:Name="PART_ModeClickBorder"
3333
Width="{StaticResource OmnibarModeDefaultClickAreaWidth}"
3434
Height="{TemplateBinding Height}"
3535
Background="Transparent"
@@ -41,18 +41,48 @@
4141
<ContentPresenter HorizontalAlignment="Center" Content="{TemplateBinding IconOnInactive}" />
4242
</Border>
4343

44+
<TextBox
45+
x:Name="PART_InputTextBox"
46+
Grid.Column="1"
47+
HorizontalAlignment="Stretch"
48+
HorizontalContentAlignment="Stretch"
49+
Visibility="Collapsed">
50+
<TextBox.Resources>
51+
<SolidColorBrush x:Key="TextControlBackground" Color="Transparent" />
52+
<SolidColorBrush x:Key="TextControlBackgroundPointerOver" Color="Transparent" />
53+
<SolidColorBrush x:Key="TextControlBackgroundFocused" Color="Transparent" />
54+
<SolidColorBrush x:Key="TextControlBackgroundDisabled" Color="Transparent" />
55+
56+
<SolidColorBrush x:Key="TextControlBorderBrush" Color="Transparent" />
57+
<SolidColorBrush x:Key="TextControlBorderBrushPointerOver" Color="Transparent" />
58+
<SolidColorBrush x:Key="TextControlBorderBrushFocused" Color="Transparent" />
59+
<SolidColorBrush x:Key="TextControlBorderBrushDisabled" Color="Transparent" />
60+
61+
<Thickness x:Key="TextControlThemePadding">0,5,0,6</Thickness>
62+
</TextBox.Resources>
63+
</TextBox>
64+
4465
<VisualStateManager.VisualStateGroups>
4566

4667
<VisualStateGroup x:Name="CommonStates">
47-
<VisualState x:Name="Normal" />
68+
<VisualState x:Name="PointerNormal" />
4869
<VisualState x:Name="PointerOver">
4970
<VisualState.Setters>
50-
<Setter Target="ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorTertiaryBrush}" />
71+
<Setter Target="PART_ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorTertiaryBrush}" />
72+
</VisualState.Setters>
73+
</VisualState>
74+
<VisualState x:Name="PointerPressed">
75+
<VisualState.Setters>
76+
<Setter Target="PART_ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorSecondaryBrush}" />
5177
</VisualState.Setters>
5278
</VisualState>
53-
<VisualState x:Name="Pressed">
79+
</VisualStateGroup>
80+
81+
<VisualStateGroup x:Name="InputVisibilityStates">
82+
<VisualState x:Name="Hidden" />
83+
<VisualState x:Name="Visible">
5484
<VisualState.Setters>
55-
<Setter Target="ModeClickBorder.Background" Value="{ThemeResource SubtleFillColorSecondaryBrush}" />
85+
<Setter Target="PART_InputTextBox.Visibility" Value="Visible" />
5686
</VisualState.Setters>
5787
</VisualState>
5888
</VisualStateGroup>

tests/Files.App.UITests/Views/OmnibarPage.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
Padding="24"
6565
Style="{StaticResource GridExampleControlStyle}">
6666
<controls:Omnibar HorizontalAlignment="Stretch" VerticalAlignment="Center">
67-
<controls:OmnibarMode HideContentOnInactive="True" Text="A">
67+
<controls:OmnibarMode
68+
HideContentOnInactive="True"
69+
IsDefault="True"
70+
Text="A">
6871
<controls:OmnibarMode.IconOnActive>
6972
<controls:ThemedIcon
7073
Width="16"

0 commit comments

Comments
 (0)