/// <summary> /// Initialize a new instance of the ViewLayoutMenuItemsPile class. /// </summary> /// <param name="provider">Provider of context menu values.</param> /// <param name="items">Reference to the owning collection.</param> /// <param name="standardStyle">Draw items with standard or alternate style.</param> /// <param name="imageColumn">Draw an image background for the item images.</param> public ViewLayoutMenuItemsPile(IContextMenuProvider provider, KryptonContextMenuItems items, bool standardStyle, bool imageColumn) { // Cache access to the highlight item palette _paletteItemHighlight = provider.ProviderStateCommon.ItemHighlight; // Create and place an image column inside a docker so it appears on the left side _imageColumn = new ViewDrawMenuImageColumn(items, provider.ProviderStateCommon.ItemImageColumn); ViewLayoutDocker imageDocker = new() { { _imageColumn, ViewDockStyle.Left } }; // Only show the image column when in a standard collection of items imageDocker.Visible = imageColumn; // Create a vertical stack that contains each individual menu item ItemStack = new ViewLayoutStack(false) { FillLastChild = false }; // Use a docker with the item stack as the fill ViewLayoutDocker stackDocker = new() { { ItemStack, ViewDockStyle.Fill } }; // Grab the padding for around the item stack Padding itemsPadding = _paletteItemHighlight.GetMetricPadding(PaletteState.Normal, PaletteMetricPadding.ContextMenuItemsCollection); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Left), ViewDockStyle.Left); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Right), ViewDockStyle.Right); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Top), ViewDockStyle.Top); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Bottom), ViewDockStyle.Bottom); // The background of the pile is the image column Add(imageDocker); // The foreground of the pile is the stack of menu items Add(stackDocker); }
private void UpdateImageColumnWidth(IRenderer renderer) { // If there is an image column then we will have a entry for index 0 if (_columnToWidth.ContainsKey(0)) { // Find the border padding that is applied to the content of the menu item Padding borderPadding = renderer.RenderStandardBorder.GetBorderDisplayPadding(_paletteItemHighlight.Border, PaletteState.Normal, VisualOrientation.Top); // Add double the left edge to the right edge of the image background coumn var imageColumnWidth = _columnToWidth[0]; imageColumnWidth += borderPadding.Left * 3; // Add double the metric padding that occurs outside the item highlight Padding itemMetricPadding = _paletteItemHighlight.GetMetricPadding(PaletteState.Normal, PaletteMetricPadding.ContextMenuItemHighlight); imageColumnWidth += itemMetricPadding.Left * 2; _imageColumn.ColumnWidth = imageColumnWidth; } }
/// <summary> /// Gets a padding metric value. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <param name="metric">Requested metric.</param> /// <returns>Padding value.</returns> public virtual Padding GetMetricPadding(PaletteState state, PaletteMetricPadding metric) => // Always pass onto the inheritance _inherit.GetMetricPadding(state, metric);