Implement overflow menus

This commit is contained in:
John Lewin 2018-01-21 21:07:14 -08:00
parent 56d9c083b6
commit 51a2406c0f
14 changed files with 127 additions and 83 deletions

View file

@ -28,17 +28,21 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrintLibrary;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class OverflowBar : Toolbar
{
private static HashSet<Type> ignoredTypes = new HashSet<Type> { typeof(VerticalLine), typeof(HorizontalLine), typeof(SearchInputBox) };
public OverflowBar(ThemeConfig theme)
{
this.Padding = theme.ToolbarPadding.Clone(left: 0);
@ -75,7 +79,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
double maxRight = this.Width - RightAnchorItem.Width;
foreach (var widget in this.ActionArea.Children)
foreach (var widget in this.ActionArea.Children.Where(c => !ignoredTypes.Contains(c.GetType())))
{
// Widget is visible when its right edge is less than maxRight
widget.Visible = widget.Position.X + widget.Width < maxRight;
@ -96,7 +100,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var popupMenu = new PopupMenu(theme);
bool hasOverflowItems = false;
foreach (var widget in overflowBar.ActionArea.Children.Where(c => !c.Visible && c.Enabled && !(c is VerticalLine || c is HorizontalSpacer)))
foreach (var widget in overflowBar.ActionArea.Children.Where(c => c.Enabled && !c.Visible && !ignoredTypes.Contains(c.GetType())))
{
hasOverflowItems = true;
@ -125,6 +129,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
}
private static ImageWidget CreateOverflowIcon()
{
return new ImageWidget(AggContext.StaticData.LoadIcon(Path.Combine("ViewTransformControls", "overflow.png"), 32, 32, IconColor.Theme))

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
@ -39,6 +40,7 @@ using MatterHackers.MatterControl.EeProm;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrintHistory;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
@ -132,7 +134,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
this.OverflowMenu.Name = "Printer Overflow Menu";
this.OverflowMenu.DynamicPopupContent = () => GeneratePrinterOverflowMenu(theme);
this.ExtendOverflowMenu = (popupMenu) =>
{
this.GeneratePrinterOverflowMenu(popupMenu, theme);
};
printer.Connection.ConnectionSucceeded.RegisterEvent((s, e) =>
{
@ -155,9 +161,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnClosed(e);
}
private GuiWidget GeneratePrinterOverflowMenu(ThemeConfig theme)
private void GeneratePrinterOverflowMenu(PopupMenu popupMenu, ThemeConfig theme)
{
var menuActions = new NamedAction[]
var menuActions = new List<NamedAction>()
{
new NamedAction()
{
@ -215,7 +221,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
};
return ApplicationController.Instance.Theme.CreatePopupMenu(menuActions);
theme.CreateMenuItems(popupMenu, menuActions);
}
private void configureEePromButton_Click()