Skip to content

Commit a8e8fd9

Browse files
committed
Update brushes and use Grid to host mode controls
1 parent 957cc89 commit a8e8fd9

File tree

4 files changed

+83
-33
lines changed

4 files changed

+83
-33
lines changed

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ namespace Files.App.Controls
1515
// Content
1616
[ContentProperty(Name = nameof(Modes))]
1717
// Template parts
18-
[TemplatePart(Name = "ModesItemsRepeater", Type = typeof(ItemsRepeater))]
18+
[TemplatePart(Name = "PART_ModesHostGrid", Type = typeof(Grid))]
1919
// Visual states
2020
[TemplateVisualState(Name = "Focused", GroupName = "FocusStates")]
2121
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusStates")]
2222
public partial class Omnibar : Control
2323
{
24-
private const string ModesItemsRepeater = "ModesItemsRepeater";
24+
private const string ModesHostGrid = "PART_ModesHostGrid";
2525

26-
private ItemsRepeater? _modesItemsRepeater;
26+
private Grid? _modesHostGrid;
27+
private bool _isFocused;
2728

2829
public Omnibar()
2930
{
@@ -34,27 +35,66 @@ public Omnibar()
3435

3536
protected override void OnApplyTemplate()
3637
{
37-
_modesItemsRepeater = GetTemplateChild(ModesItemsRepeater) as ItemsRepeater
38-
?? throw new MissingFieldException($"Could not find {ModesItemsRepeater} in {nameof(Omnibar)}'s style.");
38+
_modesHostGrid = GetTemplateChild(ModesHostGrid) as Grid
39+
?? throw new MissingFieldException($"Could not find {ModesHostGrid} in {nameof(Omnibar)}'s style.");
3940

40-
_modesItemsRepeater.ItemsSource = Modes;
41+
if (Modes is null)
42+
return;
43+
44+
// Populate the modes1
45+
foreach (var mode in Modes)
46+
{
47+
// Insert a divider
48+
if (_modesHostGrid.Children.Count is not 0)
49+
{
50+
var divider = new Border()
51+
{
52+
Width = 1,
53+
Height = 24,
54+
//Style = (Style)Application.Current.Resources["DefaultModeDividerStyle"]
55+
};
56+
57+
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
58+
_modesHostGrid.Children.Add(divider);
59+
Grid.SetColumn(divider, _modesHostGrid.Children.Count - 1);
60+
}
61+
62+
// Insert the mode
63+
_modesHostGrid.ColumnDefinitions.Add(new() { Width = GridLength.Auto });
64+
_modesHostGrid.Children.Add(mode);
65+
Grid.SetColumn(mode, _modesHostGrid.Children.Count - 1);
66+
}
4167

4268
GotFocus += Omnibar_GotFocus;
4369
LostFocus += Omnibar_LostFocus;
4470

71+
UpdateVisualStates();
72+
4573
base.OnApplyTemplate();
4674
}
4775

76+
// Private methods
77+
78+
private void UpdateVisualStates()
79+
{
80+
VisualStateManager.GoToState(
81+
this,
82+
_isFocused ? "Focused" : "Normal",
83+
true);
84+
}
85+
86+
// Events
87+
4888
private void Omnibar_GotFocus(object sender, RoutedEventArgs e)
4989
{
50-
VisualStateManager.GoToState(this, "Focused", true);
90+
_isFocused = true;
91+
UpdateVisualStates();
5192
}
5293

5394
private void Omnibar_LostFocus(object sender, RoutedEventArgs e)
5495
{
55-
var focus = FocusState;
56-
57-
VisualStateManager.GoToState(this, "Unfocused", true);
96+
_isFocused = false;
97+
UpdateVisualStates();
5898
}
5999
}
60100
}

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:Files.App.Controls">
66

7-
<ResourceDictionary.ThemeDictionaries>
7+
<!--<ResourceDictionary.ThemeDictionaries>
88
<ResourceDictionary x:Key="Default">
9-
<SolidColorBrush x:Key="SystemControlSplitterPressed" Color="{ThemeResource SystemBaseHighColor}" />
9+
<SolidColorBrush x:Key="OmnibarModeDivisiderBrush" Color="{ThemeResource DividerStrokeColorDefaultBrush}" />
1010
</ResourceDictionary>
1111
<ResourceDictionary x:Key="HighContrast">
12-
<SolidColorBrush x:Key="SystemControlSplitterPressed" Color="{ThemeResource SystemColorHighlightColor}" />
12+
<SolidColorBrush x:Key="OmnibarModeDivisiderBrush" Color="{ThemeResource DividerStrokeColorDefaultBrush}" />
1313
</ResourceDictionary>
14-
</ResourceDictionary.ThemeDictionaries>
14+
</ResourceDictionary.ThemeDictionaries>-->
1515

16-
<x:Double x:Key="OmnibarDefaultHeight">40</x:Double>
17-
<CornerRadius x:Key="OmnibarDefaultCornerRadius">20</CornerRadius>
16+
<x:Double x:Key="OmnibarDefaultHeight">36</x:Double>
17+
<CornerRadius x:Key="OmnibarDefaultCornerRadius">18</CornerRadius>
1818
<Thickness x:Key="OmnibarFocusedBorderThickness">2</Thickness>
1919
<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}" />
2024

2125
<Style BasedOn="{StaticResource DefaultOmnibarStyle}" TargetType="local:Omnibar" />
2226

@@ -25,7 +29,10 @@
2529
<Setter Property="Height" Value="{StaticResource OmnibarDefaultHeight}" />
2630
<Setter Property="UseSystemFocusVisuals" Value="True" />
2731
<Setter Property="HorizontalAlignment" Value="Stretch" />
28-
<Setter Property="Background" Value="Transparent" />
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}" />
2936
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
3037
<Setter Property="CornerRadius" Value="{StaticResource OmnibarDefaultCornerRadius}" />
3138
<Setter Property="VerticalAlignment" Value="Center" />
@@ -35,30 +42,24 @@
3542
<ControlTemplate TargetType="local:Omnibar">
3643
<Grid
3744
x:Name="PART_RootGrid"
45+
Padding="{TemplateBinding Padding}"
3846
Background="{TemplateBinding Background}"
47+
BorderBrush="{TemplateBinding BorderBrush}"
48+
BorderThickness="{TemplateBinding BorderThickness}"
3949
CornerRadius="{TemplateBinding CornerRadius}">
40-
<ItemsRepeater x:Name="ModesItemsRepeater">
41-
<ItemsRepeater.Layout>
42-
<StackLayout Orientation="Horizontal" Spacing="2" />
43-
</ItemsRepeater.Layout>
44-
</ItemsRepeater>
50+
<Grid x:Name="PART_ModesHostGrid" />
4551

4652
<VisualStateManager.VisualStateGroups>
4753

48-
<VisualStateGroup x:Name="FocusStates">
54+
<VisualStateGroup x:Name="PointerStates">
55+
<VisualState x:Name="Normal" />
4956
<VisualState x:Name="Focused">
5057
<VisualState.Setters>
5158
<Setter Target="PART_RootGrid.BorderBrush" Value="{ThemeResource AccentFillColorDefaultBrush}" />
5259
<Setter Target="PART_RootGrid.BorderThickness" Value="{StaticResource OmnibarFocusedBorderThickness}" />
5360
<Setter Target="PART_RootGrid.Margin" Value="-1" />
5461
</VisualState.Setters>
5562
</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>
6263
</VisualStateGroup>
6364

6465
</VisualStateManager.VisualStateGroups>
@@ -68,4 +69,13 @@
6869
</Setter>
6970
</Style>
7071

72+
<Style
73+
x:Key="DefaultModeDividerStyle"
74+
BasedOn="{StaticResource DefaultBorderStyle}"
75+
TargetType="Border">
76+
<Setter Property="Height" Value="{StaticResource OmnibarModeDividerDefaultHeight}" />
77+
<Setter Property="Width" Value="1" />
78+
<Setter Property="Background" Value="{StaticResource OmnibarModeDividerDefaultHeight}" />
79+
</Style>
80+
7181
</ResourceDictionary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class OmnibarMode : Control
1616
{
1717
public OmnibarMode()
1818
{
19-
DefaultStyleKey = typeof(Omnibar);
19+
DefaultStyleKey = typeof(OmnibarMode);
2020
}
2121

2222
protected override void OnApplyTemplate()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:Files.App.Controls">
66

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>
7+
<x:Double x:Key="OmnibarModeDefaultHeight">32</x:Double>
8+
<x:Double x:Key="OmnibarModeDefaultClickAreaWidth">46</x:Double>
9+
<CornerRadius x:Key="OmnibarDefaultCornerRadius">16</CornerRadius>
1010

1111
<Style BasedOn="{StaticResource DefaultOmnibarModeStyle}" TargetType="local:OmnibarMode" />
1212

0 commit comments

Comments
 (0)