Significantly improved the layout consistency when enlarging the device scale. Created a DeviceMargin and DevicePadding on GuiWidget Deleted dead code Made many images have default larger disk sizes and scale in memory. Made the menus have horizontal spacers rather than dashed lines
81 lines
No EOL
2.2 KiB
C#
81 lines
No EOL
2.2 KiB
C#
using MatterHackers.Agg;
|
|
using MatterHackers.Agg.UI;
|
|
using MatterHackers.VectorMath;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MatterHackers.MatterControl
|
|
{
|
|
public abstract class MenuBase : GuiWidget
|
|
{
|
|
public class MenuItemAction
|
|
{
|
|
public MenuItemAction(string title, Action action)
|
|
{
|
|
this.Title = title;
|
|
this.Action = action;
|
|
}
|
|
|
|
public string Title { get; set; }
|
|
public Action Action { get; set; }
|
|
}
|
|
|
|
public DropDownMenu MenuDropList;
|
|
private List<MenuItemAction> menuItems = null;
|
|
|
|
protected abstract IEnumerable<MenuItemAction> GetMenuItems();
|
|
|
|
public MenuBase(string menuName)
|
|
{
|
|
MenuDropList = new DropDownMenu(menuName.ToUpper(), Direction.Down, pointSize: 10);
|
|
MenuDropList.MenuItemsPadding = new BorderDouble(0);
|
|
MenuDropList.Margin = new BorderDouble(0);
|
|
MenuDropList.Padding = new BorderDouble(0);
|
|
MenuDropList.MenuItemsPadding = new BorderDouble(8, 6, 8, 6);
|
|
|
|
MenuDropList.DrawDirectionalArrow = false;
|
|
MenuDropList.MenuAsWideAsItems = false;
|
|
|
|
menuItems = new List<MenuItemAction>(GetMenuItems());
|
|
BorderDouble padding = MenuDropList.MenuItemsPadding;
|
|
//Add the menu items to the menu itself
|
|
foreach (MenuItemAction item in menuItems)
|
|
{
|
|
if (item.Title.StartsWith("-----"))
|
|
{
|
|
MenuDropList.AddHorizontalLine();
|
|
}
|
|
else
|
|
{
|
|
MenuItem newItem = MenuDropList.AddItem(item.Title, pointSize: 11);
|
|
if (item.Action == null)
|
|
{
|
|
newItem.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
MenuDropList.Padding = padding;
|
|
|
|
AddChild(MenuDropList);
|
|
this.Width = GetChildrenBoundsIncludingMargins().Width;
|
|
this.Height = 22 * GuiWidget.DeviceScale;
|
|
this.Margin = new BorderDouble(0);
|
|
this.Padding = new BorderDouble(0);
|
|
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
|
this.MenuDropList.SelectionChanged += MenuDropList_SelectionChanged;
|
|
this.MenuDropList.OpenOffset = new Vector2(0, 0);
|
|
}
|
|
|
|
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
string menuSelection = ((DropDownMenu)sender).SelectedValue;
|
|
foreach (MenuItemAction item in menuItems)
|
|
{
|
|
if (item.Title == menuSelection && item.Action != null)
|
|
{
|
|
UiThread.RunOnIdle(item.Action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |