diff --git a/ApplicationView/MenuRow/ApplicationMenuRow.cs b/ApplicationView/MenuRow/ApplicationMenuRow.cs index dcd753c96..1e7ca8631 100644 --- a/ApplicationView/MenuRow/ApplicationMenuRow.cs +++ b/ApplicationView/MenuRow/ApplicationMenuRow.cs @@ -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); diff --git a/ApplicationView/MenuRow/MenuBase.cs b/ApplicationView/MenuRow/MenuBase.cs index eb0af39ec..3b77b0f6b 100644 --- a/ApplicationView/MenuRow/MenuBase.cs +++ b/ApplicationView/MenuRow/MenuBase.cs @@ -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); diff --git a/ApplicationView/MenuRow/MenuOptionFile.cs b/ApplicationView/MenuRow/MenuOptionFile.cs index 4b4c66929..45b0874b0 100644 --- a/ApplicationView/MenuRow/MenuOptionFile.cs +++ b/ApplicationView/MenuRow/MenuOptionFile.cs @@ -16,8 +16,6 @@ namespace MatterHackers.MatterControl { public class MenuOptionFile : MenuBase { - private static CreateFolderWindow createFolderWindow = null; - public static MenuOptionFile CurrentMenuOptionFile = null; public EventHandler RedeemDesignCode; diff --git a/ControlElements/DropDownMenuFactory.cs b/ControlElements/DropDownMenuFactory.cs index d02663fdb..dcb4085cd 100644 --- a/ControlElements/DropDownMenuFactory.cs +++ b/ControlElements/DropDownMenuFactory.cs @@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl public DynamicDropDownMenu Generate(string label = "", TupleList> 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; diff --git a/CustomWidgets/DropDownMenuWidget.cs b/CustomWidgets/DropDownMenuWidget.cs index 1501eee3a..e45f4deb0 100644 --- a/CustomWidgets/DropDownMenuWidget.cs +++ b/CustomWidgets/DropDownMenuWidget.cs @@ -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); diff --git a/CustomWidgets/DynamicDropDownMenu.cs b/CustomWidgets/DynamicDropDownMenu.cs index 2e585688c..272735dd4 100644 --- a/CustomWidgets/DynamicDropDownMenu.cs +++ b/CustomWidgets/DynamicDropDownMenu.cs @@ -36,13 +36,11 @@ namespace MatterHackers.Agg.UI public class DynamicDropDownMenu : DropDownMenu { private TupleList> 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>(); - 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 clickFunction) { this.AddItem(name);