Skip to content

Commit

Permalink
Add Menu & ContextMenu (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
apman authored Jan 20, 2025
1 parent 3b296e3 commit 7b81d6d
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 256 deletions.
10 changes: 8 additions & 2 deletions samples/SampleApp/DemoPages/ContextMenuDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
<Border Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" />
<MenuItem Header="Paste" />
<MenuItem Header="Standard _Menu Item" />
<MenuItem Header="Disabled" IsEnabled="False" />
<Separator />
<MenuItem Header="Menu with _Submenu">
<MenuItem Header="Submenu _1" />
<MenuItem Header="Submenu _2" />
</MenuItem>
</ContextMenu>
</Border.ContextMenu>
<TextBlock Margin="10">Right-click anywhere in this space</TextBlock>
</Border>


</UserControl>
274 changes: 79 additions & 195 deletions samples/SampleApp/DemoPages/MenuDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,207 +4,91 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SampleApp.DemoPages.MenuDemo">
<Panel>
<Panel.Styles>
<Style Selector="MenuItem Image">
<Setter Property="Width" Value="15" />
<Setter Property="Height" Value="15" />
</Style>

<Style Selector="MenuItem > StackPanel">
<Setter Property="Spacing" Value="10" />
<Setter Property="Orientation" Value="Horizontal" />
</Style>
</Panel.Styles>


<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="File" />
</StackPanel>
</MenuItem.Header>
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Big Icon">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy">
<MenuItem.Icon>
<PathIcon Data="{StaticResource PasswordRevealPath}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>

<MenuItem IsEnabled="True" Header="Test">
<DockPanel>
<Menu DockPanel.Dock="Top" VerticalAlignment="Top">
<MenuItem Header="File">
<MenuItem Header="Open session" InputGesture="&#x2318;+O" />
<MenuItem Header="Open with parameters">
<MenuItem Header="Open (embedded/tabbed)" />
<MenuItem Header="Open embedded SFTP connection" />
<MenuItem Header="Open embedded SCP connection" InputGesture="&#x2318;+S" IsEnabled="False" />
<MenuItem Header="-" />
<MenuItem Header="Open (select credentials)..." />
</MenuItem>
<MenuItem Header="View password" />
<MenuItem Header="Copy name" />
<MenuItem Header="Copy password" />
<MenuItem Header="-" />
<MenuItem Header="Focus session" />
<MenuItem Header="Edit" IsEnabled="False">
<MenuItem Header="Dummy1" />
<MenuItem Header="Dummy2" />
</MenuItem>
<MenuItem Header="Toggle Options">
<MenuItem Header="Option 1" ToggleType="CheckBox" />
<MenuItem Header="Option 2" ToggleType="CheckBox" IsChecked="True" />
</MenuItem>
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<PathIcon Data="{StaticResource PasswordRevealPath}"
Height="9" Width="12" />
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>

<MenuItem IsEnabled="False">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem>
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</Menu>

<Menu DockPanel.Dock="Bottom">
<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Big Icon">
<MenuItem.Icon>
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy">
<MenuItem.Icon>
<PathIcon Data="{StaticResource PasswordRevealPath}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>

<MenuItem IsEnabled="True" Header="Test">
<MenuItem Header="Menu Item" />
<MenuItem Header="Menu Item" />
<MenuItem Header="-" />
<MenuItem Header="Menu Item" />
</MenuItem>
</Menu>

<Menu DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<MenuItem Header="File">
<MenuItem Header="Open session" InputGesture="&#x2318;+O" />
<MenuItem Header="Open with parameters">
<MenuItem Header="Open (embedded/tabbed)" />
<MenuItem Header="Open embedded SFTP connection" />
<MenuItem Header="Open embedded SCP connection" InputGesture="&#x2318;+S" IsEnabled="False" />
<MenuItem Header="-" />
<MenuItem Header="Open (select credentials)..." />
</MenuItem>
<MenuItem Header="View password" />
<MenuItem Header="Copy name" />
<MenuItem Header="Copy password" />
<MenuItem Header="-" />
<MenuItem Header="Focus session" />
<MenuItem Header="Edit" IsEnabled="False">
<MenuItem Header="Dummy1" />
<MenuItem Header="Dummy2" />
</MenuItem>
<MenuItem Header="Toggle Options">
<MenuItem Header="Option 1" ToggleType="CheckBox" />
<MenuItem Header="Option 2" ToggleType="CheckBox" IsChecked="True" />
</MenuItem>
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Menu Item">
<MenuItem.Icon>
<PathIcon Data="{StaticResource PasswordRevealPath}"
Height="9" Width="12" />
<Image Source="{StaticResource FolderIcon}" />
</MenuItem.Icon>
</MenuItem>

<MenuItem IsEnabled="False">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem IsEnabled="True">
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>

<MenuItem>
<MenuItem.Header>
<StackPanel>
<Image Source="{StaticResource FolderIcon}" />
<TextBlock Text="Menu Item" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</Menu>

<Border Background="Silver" />
</DockPanel>
</Panel>
<MenuItem Header="Menu Item" />
<MenuItem Header="Menu Item" />
<MenuItem Header="-" />
<MenuItem Header="Menu Item" />
<MenuItem Header="Menu Item" />
<MenuItem Header="-" />
<MenuItem Header="Menu Item" />
<MenuItem Header="Menu Item" />
</MenuItem>
<MenuItem Header="Short Menu (not working yet!)">
<MenuItem Header="Menu Item" />
<MenuItem Header="Menu Item" />
</MenuItem>
</Menu>

<Border Background="Gainsboro" />
</DockPanel>

</UserControl>
14 changes: 7 additions & 7 deletions samples/SampleApp/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
<TabItem Header="ComboBox">
<demoPages:ComboBoxDemo />
</TabItem>
<!-- <TabItem Header="ContextMenu"> -->
<!-- <demoPages:ContextMenuDemo /> -->
<!-- </TabItem> -->
<TabItem Header="ContextMenu" IsSelected="True">
<demoPages:ContextMenuDemo />
</TabItem>
<TabItem Header="DataGrid">
<demoPages:DataGridDemo>
<demoPages:DataGridDemo.DataContext>
<vm:DataGridViewModel />
</demoPages:DataGridDemo.DataContext>
</demoPages:DataGridDemo>
</TabItem>
<!-- <TabItem Header="Menu"> -->
<!-- <demoPages:MenuDemo /> -->
<!-- </TabItem> -->
<TabItem Header="MenuFlyout" IsSelected="True">
<TabItem Header="Menu" IsSelected="True">
<demoPages:MenuDemo />
</TabItem>
<TabItem Header="MenuFlyout">
<demoPages:MenuFlyoutDemo />
</TabItem>
<TabItem Header="TabControl">
Expand Down
2 changes: 2 additions & 0 deletions src/MacOS.Avalonia.Theme/Accents/ThemeResources.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,14 @@
<Thickness x:Key="MenuFlyoutPresenterBorderThemeThickness">0</Thickness>
<x:Double x:Key="MenuFlyoutSubItemPopupHorizontalOffset">-14</x:Double>
<x:Double x:Key="MenuFlyoutSubItemPopupVerticalOffset">-7</x:Double>
<x:Double x:Key="MenuPopupHorizontalOffset">-14</x:Double>
<Thickness x:Key="MenuFlyoutPadding">5 2 5 2</Thickness>
<Thickness x:Key="MenuFlyoutSeparatorThemePadding">8,5,8,5</Thickness>
<Thickness x:Key="MenuIconPresenterMargin">0,0,4,0</Thickness>
<Thickness x:Key="MenuInputGestureTextMargin">24,0,0,0</Thickness>
<Thickness x:Key="MenuItemPadding">9 4 7 2</Thickness>
<SolidColorBrush x:Key="SeparatorBrush" Color="{DynamicResource ForegroundColor}" Opacity="0.2" />
<Thickness x:Key="MenuFlyoutScrollerMargin">0,4,0,4</Thickness>


<!-- DEVELOPMENT ONLY -->
Expand Down
Loading

0 comments on commit 7b81d6d

Please sign in to comment.