Made a base class for the menus

Made more shared code for them
This commit is contained in:
Lars Brubaker 2015-05-20 17:34:55 -07:00
parent 036c82e241
commit 703021620d
8 changed files with 112 additions and 251 deletions

View file

@ -0,0 +1,63 @@
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ContactForm;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MatterControl
{
public abstract class MenuBase : GuiWidget
{
public DropDownMenu MenuDropList;
private TupleList<string, Func<bool>> menuItems = null;
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.DrawDirectionalArrow = false;
MenuDropList.MenuAsWideAsItems = false;
menuItems = GetMenuItems();
BorderDouble padding = MenuDropList.MenuItemsPadding;
//Add the menu items to the menu itself
foreach (Tuple<string, Func<bool>> item in menuItems)
{
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
MenuDropList.AddItem(item.Item1, pointSize: 10);
}
MenuDropList.Padding = padding;
AddChild(MenuDropList);
this.Width = GetChildrenBoundsIncludingMargins().Width;
this.Height = 22 * TextWidget.GlobalPointSizeScaleRatio;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
this.MenuDropList.OpenOffset = new Vector2(0, 0);
}
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
{
string menuSelection = ((DropDownMenu)sender).SelectedValue;
foreach (Tuple<string, Func<bool>> item in menuItems)
{
if (item.Item1 == menuSelection)
{
if (item.Item2 != null)
{
item.Item2();
}
}
}
}
abstract protected TupleList<string, Func<bool>> GetMenuItems();
}
}

View file

@ -11,62 +11,21 @@ using System.IO;
namespace MatterHackers.MatterControl
{
public class MenuOptionFile : GuiWidget
public class MenuOptionFile : MenuBase
{
public DropDownMenu MenuDropList;
private TupleList<string, Func<bool>> menuItems;
public MenuOptionFile()
: base("File".Localize())
{
MenuDropList = new DropDownMenu("File".Localize().ToUpper(), Direction.Down, pointSize: 10);
MenuDropList.MenuItemsPadding = new BorderDouble(0);
MenuDropList.Margin = new BorderDouble(0);
MenuDropList.Padding = new BorderDouble(0);
SetMenuItems();
AddChild(MenuDropList);
this.Width = 44 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Height = 22 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
this.MenuDropList.OpenOffset = new Vector2(0, 0);
}
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
override protected TupleList<string, Func<bool>> GetMenuItems()
{
string menuSelection = ((DropDownMenu)sender).SelectedValue;
foreach (Tuple<string, Func<bool>> item in menuItems)
{
if (item.Item1 == menuSelection)
{
if (item.Item2 != null)
{
item.Item2();
}
}
}
}
private void SetMenuItems()
{
menuItems = new TupleList<string, Func<bool>>
return new TupleList<string, Func<bool>>
{
{LocalizedString.Get("Add Printer"), addPrinter_Click},
{LocalizedString.Get("Add File"), importFile_Click},
{LocalizedString.Get("Exit"), exit_Click},
};
BorderDouble padding = MenuDropList.MenuItemsPadding;
//Add the menu items to the menu itself
foreach (Tuple<string, Func<bool>> item in menuItems)
{
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
MenuDropList.AddItem(item.Item1, pointSize: 10);
}
MenuDropList.Padding = padding;
}
private bool addPrinter_Click()

View file

@ -7,48 +7,16 @@ using System;
namespace MatterHackers.MatterControl
{
public class MenuOptionHelp : GuiWidget
public class MenuOptionHelp : MenuBase
{
public DropDownMenu MenuDropList;
private TupleList<string, Func<bool>> menuItems;
public MenuOptionHelp()
: base("Help".Localize())
{
MenuDropList = new DropDownMenu("Help".Localize().ToUpper(), Direction.Down, pointSize: 10);
MenuDropList.MenuItemsPadding = new BorderDouble(0);
MenuDropList.Margin = new BorderDouble(0);
MenuDropList.Padding = new BorderDouble(0);
SetMenuItems();
AddChild(MenuDropList);
this.Width = 48 * TextWidget.GlobalPointSizeScaleRatio;
this.Height = 22 * TextWidget.GlobalPointSizeScaleRatio;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
this.MenuDropList.OpenOffset = new Vector2(0, 0);
}
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
override protected TupleList<string, Func<bool>> GetMenuItems()
{
string menuSelection = ((DropDownMenu)sender).SelectedValue;
foreach (Tuple<string, Func<bool>> item in menuItems)
{
if (item.Item1 == menuSelection)
{
if (item.Item2 != null)
{
item.Item2();
}
}
}
}
private void SetMenuItems()
{
menuItems = new TupleList<string, Func<bool>>
return new TupleList<string, Func<bool>>
{
{LocalizedString.Get("Getting Started"), gettingStarted_Click},
{LocalizedString.Get("View Help"), help_Click},
@ -56,15 +24,6 @@ namespace MatterHackers.MatterControl
{LocalizedString.Get("Release Notes"), notes_Click},
{LocalizedString.Get("About MatterControl"), about_Click},
};
BorderDouble padding = MenuDropList.MenuItemsPadding;
//Add the menu items to the menu itself
foreach (Tuple<string, Func<bool>> item in menuItems)
{
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
MenuDropList.AddItem(item.Item1, pointSize: 10);
}
MenuDropList.Padding = padding;
}
private bool bug_Click()

View file

@ -11,65 +11,24 @@ using System.IO;
namespace MatterHackers.MatterControl
{
public class MenuOptionSettings : GuiWidget
public class MenuOptionSettings : MenuBase
{
public DropDownMenu MenuDropList;
private TupleList<string, Func<bool>> menuItems;
static public PopOutTextTabWidget sliceSettingsPopOut = null;
static public PopOutTextTabWidget controlsPopOut = null;
public MenuOptionSettings()
: base("Settings".Localize())
{
MenuDropList = new DropDownMenu("Settings".Localize().ToUpper(), Direction.Down, pointSize: 10);
MenuDropList.MenuItemsPadding = new BorderDouble(0);
MenuDropList.Margin = new BorderDouble(0);
MenuDropList.Padding = new BorderDouble(0);
SetMenuItems();
AddChild(MenuDropList);
this.Width = 84 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Height = 22 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
this.MenuDropList.OpenOffset = new Vector2(0, 0);
}
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
override protected TupleList<string, Func<bool>> GetMenuItems()
{
string menuSelection = ((DropDownMenu)sender).SelectedValue;
foreach (Tuple<string, Func<bool>> item in menuItems)
{
if (item.Item1 == menuSelection)
{
if (item.Item2 != null)
{
item.Item2();
}
}
}
}
private void SetMenuItems()
{
menuItems = new TupleList<string, Func<bool>>
return new TupleList<string, Func<bool>>
{
{LocalizedString.Get("Printing"), openPrintingPannel_Click},
{LocalizedString.Get("Controls"), openControlsPannel_Click},
{LocalizedString.Get("Show Terminal"), openTermanialPannel_Click},
};
BorderDouble padding = MenuDropList.MenuItemsPadding;
//Add the menu items to the menu itself
foreach (Tuple<string, Func<bool>> item in menuItems)
{
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
MenuDropList.AddItem(item.Item1, pointSize: 10);
}
MenuDropList.Padding = padding;
}
private bool openPrintingPannel_Click()

View file

@ -1,107 +0,0 @@
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MatterControl
{
public class MenuOptionView : GuiWidget
{
public DropDownMenu MenuDropList;
private TupleList<string, Func<bool>> menuItems;
public MenuOptionView()
{
MenuDropList = new DropDownMenu("View".Localize().ToUpper(), Direction.Down, pointSize: 10);
MenuDropList.MenuItemsPadding = new BorderDouble(0);
MenuDropList.Margin = new BorderDouble(0);
MenuDropList.Padding = new BorderDouble(0);
SetMenuItems();
AddChild(MenuDropList);
this.Width = 44 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Height = 22 * TextWidget.GlobalPointSizeScaleRatio; ;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
this.VAnchor = Agg.UI.VAnchor.ParentCenter;
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
this.MenuDropList.OpenOffset = new Vector2(0, 0);
}
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
{
string menuSelection = ((DropDownMenu)sender).SelectedValue;
foreach (Tuple<string, Func<bool>> item in menuItems)
{
if (item.Item1 == menuSelection)
{
if (item.Item2 != null)
{
item.Item2();
}
}
}
}
private void SetMenuItems()
{
menuItems = new TupleList<string, Func<bool>>
{
{LocalizedString.Get("Layout 1"), layout1_Click},
{LocalizedString.Get("Layout 2"), layout2_Click},
//{LocalizedString.Get("Layout 3"), layout3_Click},
};
BorderDouble padding = MenuDropList.MenuItemsPadding;
//Add the menu items to the menu itself
foreach (Tuple<string, Func<bool>> item in menuItems)
{
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4, 8, 4) * TextWidget.GlobalPointSizeScaleRatio;
MenuDropList.AddItem(item.Item1, pointSize: 10);
}
MenuDropList.Padding = padding;
}
private int widthAdjust = -14;
private int heightAdjust = -35;
private bool layout1_Click()
{
// UiThread.RunOnIdle((state) =>
// {
// double width = System.Windows.SystemParameters.FullPrimaryScreenWidth;
// double height = System.Windows.SystemParameters.FullPrimaryScreenHeight;
//
// MatterControlApplication.Instance.DesktopPosition = new Point2D(0, 0);
// MatterControlApplication.Instance.Width = width / 3;
// MatterControlApplication.Instance.Height = height;
//
// PopOutManager.SetStates(ThirdPanelTabView.SliceSettingsTabName, true, width / 3, height + heightAdjust, width / 3 * 2 + widthAdjust, 0);
// PopOutManager.SetStates(ThirdPanelTabView.ControlsTabName, false, width / 3, height / 2 + heightAdjust, width / 3 * 2 + widthAdjust, height / 2);
// ApplicationController.Instance.ReloadAll(null, null);
//
// });
return true;
}
private bool layout2_Click()
{
// UiThread.RunOnIdle((state) =>
// {
// double width = System.Windows.SystemParameters.PrimaryScreenWidth;
// double height = System.Windows.SystemParameters.PrimaryScreenHeight;
//
// MatterControlApplication.Instance.DesktopPosition = new Point2D(0, 0);
// MatterControlApplication.Instance.Width = width / 3;
// MatterControlApplication.Instance.Height = height;
//
// PopOutManager.SetStates(ThirdPanelTabView.SliceSettingsTabName, true, width / 3, height / 2 + heightAdjust, width / 3 * 2 + widthAdjust, 0);
// PopOutManager.SetStates(ThirdPanelTabView.ControlsTabName, true, width / 3, height / 2 + heightAdjust * 2, width / 3 * 2 + widthAdjust, height / 2);
// ApplicationController.Instance.ReloadAll(null, null);
// });
return true;
}
}
}