Skip to content

Commit 184c58a

Browse files
authored
[MacOS] Add pointerover behaviours for main MenuItems with Icon & Label side-by-side (#112)
1 parent 64a7f21 commit 184c58a

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

samples/SampleApp/DemoPages/MenuDemo.axaml

+18-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</Style>
1515

1616
<Style Selector="Menu.Icons25 > MenuItem">
17-
<Style Selector="^ ContentPresenter#PART_HeaderPresenter">
17+
<Style Selector="^ ContentPresenter#PART_HeaderPresenter.TopLevelMenuItem">
1818
<Setter Property="MinWidth" Value="56" />
19-
<Setter Property="MaxWidth" Value="56" />
19+
<Setter Property="MaxWidth" Value="66" />
2020
</Style>
21-
<Style Selector="^.LongTitle ContentPresenter#PART_HeaderPresenter">
21+
<Style Selector="^.LongTitle ContentPresenter#PART_HeaderPresenter.TopLevelMenuItem">
2222
<Setter Property="MaxWidth" Value="75" />
2323
</Style>
2424
<Style Selector="^ Svg">
@@ -28,7 +28,7 @@
2828
</Style>
2929

3030
<Style Selector="Menu.Icons15 > MenuItem">
31-
<Style Selector="^ ContentPresenter#PART_HeaderPresenter">
31+
<Style Selector="^ ContentPresenter#PART_HeaderPresenter.TopLevelMenuItem">
3232
<Setter Property="MinWidth" Value="44" />
3333
<Setter Property="MaxWidth" Value="66" />
3434
</Style>
@@ -106,13 +106,15 @@
106106
<MenuItem.Icon>
107107
<Svg Path="/Assets/Details.svg" />
108108
</MenuItem.Icon>
109+
<MenuItem Header="Menu Item 1" />
110+
<MenuItem Header="Menu Item" />
109111
</MenuItem>
110112
<MenuItem Header="-" />
111113
<MenuItem Header="Copy name">
112114
<MenuItem.Icon>
113115
<Svg Path="/Assets/CopyName.svg" />
114116
</MenuItem.Icon>
115-
<MenuItem Header="Menu Item" />
117+
<MenuItem Header="Longer Menu Item" />
116118
<MenuItem Header="Menu Item" />
117119
</MenuItem>
118120

@@ -129,13 +131,20 @@
129131
</Menu>
130132
<Menu Name="SmallToolbar" DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Right"
131133
Classes="MacOS_Theme_MenuLabelBelowIcon Icons15">
132-
<MenuItem Header="Group" IsEnabled="False">
134+
<MenuItem Header="Testing" IsEnabled="False">
133135
<MenuItem.Icon>
134136
<Svg Path="/Assets/EnableUser.svg" />
135137
</MenuItem.Icon>
136138
<MenuItem Header="Menu Item" />
137139
<MenuItem Header="Menu Item" />
138140
</MenuItem>
141+
<MenuItem Header="Group">
142+
<MenuItem.Icon>
143+
<Svg Path="/Assets/EnableUser.svg" />
144+
</MenuItem.Icon>
145+
<MenuItem Header="Longer Menu Item" />
146+
<MenuItem Header="Menu Item" />
147+
</MenuItem>
139148
<MenuItem Header="Share">
140149
<MenuItem.Icon>
141150
<Svg Path="/Assets/DisableUser.svg" />
@@ -211,7 +220,9 @@
211220
• <TextBlock Classes="code" Text="MacOS_Theme_MenuItemIconOnly" /> for a toolbar-style menu without labels (Header content appears in a ToolTip instead)
212221
<LineBreak /><LineBreak />
213222
• <TextBlock Classes="code" Text="MacOS_Theme_MenuOpensAbove" /> for bottom-placed menus, opening upwards
214-
<LineBreak />
223+
<LineBreak /><LineBreak />
224+
• <TextBlock Classes="code" Text="ContentPresenter#PART_HeaderPresenter" /> of the top-level menu items has a class
225+
<TextBlock Classes="code" Text="TopLevelMenuItem" /> attached that allows easier styling without affecting sub-menu items. E.g. setting MaxWidth to force long names to wrap
215226
</TextBlock>
216227
</Border>
217228
</DockPanel>

src/Devolutions.AvaloniaTheme.MacOS/Accents/ThemeResources.axaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@
372372
<x:Double x:Key="MenuFlyoutSubItemPopupHorizontalOffset">-14</x:Double>
373373
<x:Double x:Key="MenuFlyoutSubItemPopupVerticalOffset">-7</x:Double>
374374
<x:Double x:Key="MenuPopupHorizontalOffset">-12</x:Double>
375-
<x:Double x:Key="MenuPopupBelowVerticalOffset">-10</x:Double>
375+
<x:Double x:Key="MenuPopupVerticalOffset">6</x:Double>
376+
<x:Double x:Key="MenuToolBarPopupVerticalOffset">-10</x:Double>
376377
<x:Double x:Key="MenuPopupAboveVerticalOffset">-5</x:Double>
377378
<Thickness x:Key="MenuPopupAboveMargin">12 1 12 2</Thickness>
378379
<Thickness x:Key="MenuBarPadding">6</Thickness>
@@ -384,6 +385,7 @@
384385
<Thickness x:Key="MenuToolBarItemPadding">4 0 4 4</Thickness>
385386
<Thickness x:Key="MenuToolBarItemIconPadding">10 5 8 5</Thickness>
386387
<Thickness x:Key="MenuToolBarItemActiveBackgroundMargin">-10 -3 -8 -3</Thickness>
388+
<Thickness x:Key="MenuItemActiveBackgroundMargin">-6,-2,-7,-2</Thickness>
387389
<Thickness x:Key="MenuItemIconPadding">0</Thickness>
388390
<SolidColorBrush x:Key="SeparatorBrush" Color="{DynamicResource ForegroundColor}" Opacity="0.2" />
389391
<SolidColorBrush x:Key="SvgIconDisabledColorBrush" Color="{DynamicResource SvgIconDisabledColor}" />

src/Devolutions.AvaloniaTheme.MacOS/Controls/Menu.axaml

+41-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
</DockPanel>
6161
</Design.PreviewWith>
6262

63+
<!-- TODO: Consider refactoring with separate ControlThemes for the different Menu types
64+
(instead of multiple individual variations on the property level) -->
6365
<ControlTheme x:Key="FluentTopLevelMenuItem" TargetType="MenuItem">
6466
<Setter Property="FontSize">
6567
<Setter.Value>
@@ -92,6 +94,19 @@
9294
BorderThickness="{TemplateBinding BorderThickness}"
9395
VerticalAlignment="Top">
9496
<Panel>
97+
<Border Name="MenuItemActiveBackground"
98+
Background="Transparent"
99+
CornerRadius="{StaticResource SelectionCornerRadius}"
100+
Margin="{DynamicResource MenuItemActiveBackgroundMargin}">
101+
<Border.IsVisible>
102+
<MultiBinding Converter="{StaticResource ClassToChoiceConverter}"
103+
ConverterParameter="MacOS_Theme_MenuLabelBelowIcon">
104+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Menu}" Path="Classes" />
105+
<Binding Source="{x:False}" />
106+
<Binding Source="{x:True}" />
107+
</MultiBinding>
108+
</Border.IsVisible>
109+
</Border>
95110
<StackPanel>
96111
<StackPanel.Orientation>
97112
<MultiBinding Converter="{StaticResource ClassToChoiceConverter}"
@@ -113,7 +128,7 @@
113128
</MultiBinding>
114129
</Border.Padding>
115130
<Panel>
116-
<Border Name="ItemActiveBackground"
131+
<Border Name="ToolBarItemActiveBackground"
117132
Background="Transparent"
118133
CornerRadius="{StaticResource SelectionCornerRadius}"
119134
Margin="{DynamicResource MenuToolBarItemActiveBackgroundMargin}">
@@ -180,7 +195,8 @@
180195
TextWrapping="Wrap"
181196
HorizontalContentAlignment="Center"
182197
TextAlignment="Center"
183-
RecognizesAccessKey="True">
198+
RecognizesAccessKey="True"
199+
Classes="TopLevelMenuItem">
184200
<ContentPresenter.IsVisible>
185201
<MultiBinding Converter="{StaticResource ClassToChoiceConverter}"
186202
ConverterParameter="MacOS_Theme_MenuItemIconOnly">
@@ -199,8 +215,15 @@
199215
IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"
200216
Placement="BottomEdgeAlignedLeft"
201217
HorizontalOffset="{DynamicResource MenuPopupHorizontalOffset}"
202-
VerticalOffset="{DynamicResource MenuPopupBelowVerticalOffset}"
203218
OverlayInputPassThroughElement="{Binding $parent[Menu]}">
219+
<Popup.VerticalOffset>
220+
<MultiBinding Converter="{StaticResource ClassToChoiceConverter}"
221+
ConverterParameter="MacOS_Theme_MenuLabelBelowIcon">
222+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Menu}" Path="Classes" />
223+
<Binding Source="{StaticResource MenuToolBarPopupVerticalOffset}" />
224+
<Binding Source="{StaticResource MenuPopupVerticalOffset}" />
225+
</MultiBinding>
226+
</Popup.VerticalOffset>
204227
<Border Margin="{StaticResource PopupMargin} "
205228
Background="{DynamicResource PopupBackgroundBrush}"
206229
BorderBrush="{DynamicResource MenuFlyoutPresenterBorderBrush}"
@@ -248,18 +271,30 @@
248271
</Style>
249272

250273
<Style Selector="^:open, ^:pointerover">
251-
<Style Selector="^ /template/ Border#ItemActiveBackground">
274+
<Style Selector="^ /template/ Border#MenuItemActiveBackground">
275+
<Setter Property="Background" Value="{DynamicResource LayoutBackgroundMidBrush}" />
276+
</Style>
277+
</Style>
278+
279+
<Style Selector="^:pressed">
280+
<Style Selector="^ /template/ Border#MenuItemActiveBackground">
281+
<Setter Property="Background" Value="{DynamicResource LayoutBackgroundHighBrush}" />
282+
</Style>
283+
</Style>
284+
285+
<Style Selector="^:open, ^:pointerover">
286+
<Style Selector="^ /template/ Border#ToolBarItemActiveBackground">
252287
<Setter Property="Background" Value="{DynamicResource LayoutBackgroundMidBrush}" />
253288
</Style>
254289
</Style>
255290

256291
<Style Selector="^:pressed">
257-
<Style Selector="^ /template/ Border#ItemActiveBackground">
292+
<Style Selector="^ /template/ Border#ToolBarItemActiveBackground">
258293
<Setter Property="Background" Value="{DynamicResource LayoutBackgroundHighBrush}" />
259294
</Style>
260295
</Style>
261296

262-
<Style Selector="^:empty /template/ Border#ItemActiveBackground">
297+
<Style Selector="^:empty /template/ Border#ToolBarItemActiveBackground">
263298
<Setter Property="Margin" Value="-13 -4" />
264299
</Style>
265300

0 commit comments

Comments
 (0)