Refoctoring and cleaning menu class
Made changing menu text color propogate to child text widget
This commit is contained in:
parent
3366dd84b4
commit
abf963d729
6 changed files with 36 additions and 66 deletions
|
|
@ -94,11 +94,10 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
// make an object that can hold custom content on the right (like the sign in)
|
||||
rightElement = new FlowLayoutWidget(FlowDirection.LeftToRight);
|
||||
rightElement.Height = 24;
|
||||
rightElement.Margin = new BorderDouble(bottom: 4);
|
||||
rightElement.VAnchor = VAnchor.FitToChildren;
|
||||
this.AddChild(rightElement);
|
||||
|
||||
this.Padding = new BorderDouble(0, 0, 6, 0);
|
||||
this.Padding = new BorderDouble(0);
|
||||
|
||||
AddRightElement?.Invoke(rightElement);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ namespace MatterHackers.MatterControl
|
|||
public MenuBase(string menuName)
|
||||
{
|
||||
MenuDropList = new DropDownMenu(menuName.ToUpper(), Direction.Down, pointSize: 10);
|
||||
MenuDropList.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
|
||||
MenuDropList.Margin = new BorderDouble(0);
|
||||
MenuDropList.Padding = new BorderDouble(4, 4, 0, 4);
|
||||
MenuDropList.MenuItemsPadding = new BorderDouble(8, 4);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
public class MenuOptionFile : MenuBase
|
||||
{
|
||||
private static CreateFolderWindow createFolderWindow = null;
|
||||
|
||||
public static MenuOptionFile CurrentMenuOptionFile = null;
|
||||
|
||||
public EventHandler RedeemDesignCode;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public DynamicDropDownMenu Generate(string label = "", TupleList<string, Func<bool>> optionList = null, Direction direction = Direction.Down)
|
||||
{
|
||||
DynamicDropDownMenu menu = new DynamicDropDownMenu(label, CreateButtonViewStates(label), direction);
|
||||
DynamicDropDownMenu menu = new DynamicDropDownMenu(CreateButtonViewStates(label), direction);
|
||||
menu.VAnchor = VAnchor.ParentCenter;
|
||||
menu.HAnchor = HAnchor.FitToChildren;
|
||||
menu.MenuAsWideAsItems = false;
|
||||
|
|
|
|||
|
|
@ -10,20 +10,26 @@ namespace MatterHackers.Agg.UI
|
|||
{
|
||||
public event EventHandler SelectionChanged;
|
||||
|
||||
private TextWidget mainControlText;
|
||||
private GuiWidget mainControlWidget;
|
||||
|
||||
public BorderDouble MenuItemsPadding { get; set; }
|
||||
|
||||
public DropDownMenu(string topMenuText, Direction direction = Direction.Down, double pointSize = 12)
|
||||
: base(direction)
|
||||
{
|
||||
SetStates(topMenuText, pointSize);
|
||||
TextWidget textWidget = new TextWidget(topMenuText, pointSize: pointSize);
|
||||
textWidget.TextColor = this.TextColor;
|
||||
TextColorChanged += (s, e) => textWidget.TextColor = this.TextColor;
|
||||
textWidget.AutoExpandBoundsToText = true;
|
||||
this.Name = topMenuText + " Menu";
|
||||
|
||||
SetStates(textWidget);
|
||||
}
|
||||
|
||||
public DropDownMenu(string topMenuText, GuiWidget buttonView, Direction direction = Direction.Down, double pointSize = 12)
|
||||
: base(buttonView, direction)
|
||||
public DropDownMenu(GuiWidget topMenuContent, Direction direction = Direction.Down, double pointSize = 12)
|
||||
: base(direction)
|
||||
{
|
||||
SetStates(topMenuText, pointSize);
|
||||
SetStates(topMenuContent);
|
||||
}
|
||||
|
||||
public bool MenuAsWideAsItems { get; set; } = true;
|
||||
|
|
@ -42,7 +48,14 @@ namespace MatterHackers.Agg.UI
|
|||
|
||||
public RGBA_Bytes HoverColor { get; set; }
|
||||
|
||||
public RGBA_Bytes TextColor { get; set; } = RGBA_Bytes.Black;
|
||||
RGBA_Bytes textColor = RGBA_Bytes.Black;
|
||||
public RGBA_Bytes TextColor
|
||||
{
|
||||
get { return textColor; }
|
||||
set { if (value != textColor) { textColor = value; TextColorChanged?.Invoke(this, null); } }
|
||||
}
|
||||
|
||||
public event EventHandler TextColorChanged;
|
||||
|
||||
private int selectedIndex = -1;
|
||||
|
||||
|
|
@ -67,20 +80,17 @@ namespace MatterHackers.Agg.UI
|
|||
return MenuItems[SelectedIndex].Value;
|
||||
}
|
||||
|
||||
private void SetStates(string topMenuText, double pointSize)
|
||||
private void SetStates(GuiWidget topMenuContent)
|
||||
{
|
||||
SetDisplayAttributes();
|
||||
|
||||
MenuItems.CollectionChanged += new NotifyCollectionChangedEventHandler(MenuItems_CollectionChanged);
|
||||
mainControlText = new TextWidget(topMenuText, pointSize: pointSize);
|
||||
mainControlText.TextColor = this.TextColor;
|
||||
mainControlText.AutoExpandBoundsToText = true;
|
||||
mainControlText.VAnchor = UI.VAnchor.ParentCenter;
|
||||
mainControlText.HAnchor = UI.HAnchor.ParentLeft;
|
||||
AddChild(mainControlText);
|
||||
mainControlWidget = topMenuContent;
|
||||
mainControlWidget.VAnchor = UI.VAnchor.ParentCenter;
|
||||
mainControlWidget.HAnchor = UI.HAnchor.ParentLeft;
|
||||
AddChild(mainControlWidget);
|
||||
HAnchor = HAnchor.FitToChildren;
|
||||
VAnchor = VAnchor.FitToChildren;
|
||||
this.Name = topMenuText + " Menu";
|
||||
|
||||
MouseEnter += new EventHandler(DropDownList_MouseEnter);
|
||||
MouseLeave += new EventHandler(DropDownList_MouseLeave);
|
||||
|
|
@ -125,15 +135,15 @@ namespace MatterHackers.Agg.UI
|
|||
minSize.x = Math.Max(minSize.x, item.Width);
|
||||
}
|
||||
|
||||
string startText = mainControlText.Text;
|
||||
string startText = mainControlWidget.Text;
|
||||
foreach (MenuItem item in MenuItems)
|
||||
{
|
||||
mainControlText.Text = item.Text;
|
||||
mainControlWidget.Text = item.Text;
|
||||
|
||||
minSize.x = Math.Max(minSize.x, LocalBounds.Width);
|
||||
minSize.y = Math.Max(minSize.y, LocalBounds.Height);
|
||||
}
|
||||
mainControlText.Text = startText;
|
||||
mainControlWidget.Text = startText;
|
||||
|
||||
if (MenuAsWideAsItems)
|
||||
{
|
||||
|
|
@ -239,9 +249,9 @@ namespace MatterHackers.Agg.UI
|
|||
{
|
||||
value = name;
|
||||
}
|
||||
if (mainControlText.Text != "")
|
||||
if (mainControlWidget.Text != "")
|
||||
{
|
||||
mainControlText.Margin = MenuItemsPadding;
|
||||
mainControlWidget.Margin = MenuItemsPadding;
|
||||
}
|
||||
|
||||
//MenuItem menuItem = new MenuItem(new MenuItemStatesView(normalTextWithMargin, hoverTextWithMargin), value);
|
||||
|
|
|
|||
|
|
@ -36,13 +36,11 @@ namespace MatterHackers.Agg.UI
|
|||
public class DynamicDropDownMenu : DropDownMenu
|
||||
{
|
||||
private TupleList<string, Func<bool>> menuItems;
|
||||
private bool hasText;
|
||||
|
||||
public DynamicDropDownMenu(string topMenuText, GuiWidget buttonView, Direction direction = Direction.Down, double pointSize = 12)
|
||||
: base(topMenuText, buttonView, direction, pointSize)
|
||||
public DynamicDropDownMenu(GuiWidget buttonView, Direction direction = Direction.Down, double pointSize = 12)
|
||||
: base(buttonView, direction, pointSize)
|
||||
{
|
||||
menuItems = new TupleList<string, Func<bool>>();
|
||||
hasText = topMenuText != "";
|
||||
TextColor = RGBA_Bytes.Black;
|
||||
NormalArrowColor = RGBA_Bytes.Black;
|
||||
HoverArrowColor = RGBA_Bytes.Black;
|
||||
|
|
@ -74,43 +72,6 @@ namespace MatterHackers.Agg.UI
|
|||
base.OnDraw(graphics2D);
|
||||
}
|
||||
|
||||
protected override void DoDrawDirectionalArrow(Graphics2D graphics2D)
|
||||
{
|
||||
PathStorage littleArrow = new PathStorage();
|
||||
if (this.MenuDirection == Direction.Down)
|
||||
{
|
||||
littleArrow.MoveTo(-4, 0);
|
||||
littleArrow.LineTo(4, 0);
|
||||
littleArrow.LineTo(0, -5);
|
||||
}
|
||||
else if (this.MenuDirection == Direction.Up)
|
||||
{
|
||||
littleArrow.MoveTo(-4, -5);
|
||||
littleArrow.LineTo(4, -5);
|
||||
littleArrow.LineTo(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("Pulldown direction has not been implemented");
|
||||
}
|
||||
|
||||
if (!hasText)
|
||||
{
|
||||
if (UnderMouseState != UI.UnderMouseState.NotUnderMouse)
|
||||
{
|
||||
graphics2D.Render(littleArrow, LocalBounds.Right / 2, LocalBounds.Bottom + Height / 2 + 4, NormalArrowColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics2D.Render(littleArrow, LocalBounds.Right / 2, LocalBounds.Bottom + Height / 2 + 4, HoverArrowColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.DoDrawDirectionalArrow(graphics2D);
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(string name, Func<bool> clickFunction)
|
||||
{
|
||||
this.AddItem(name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue