Added DynamicDropDownMenu( can add to drop down via .add method) DropDownMenuWidget (made drawDirectionalArrow virtual) Added Factory for DropDownMenu and Split Button Add/used Factories in View3DWidget
73 lines
2 KiB
C#
73 lines
2 KiB
C#
using System;
|
|
using MatterHackers.Agg.UI;
|
|
using MatterHackers.Agg;
|
|
|
|
namespace MatterHackers.MatterControl
|
|
{
|
|
public class SplitButton : FlowLayoutWidget
|
|
{
|
|
Button defaultButton;
|
|
DynamicDropDownMenu altChoices;
|
|
|
|
Button DefaultButton { get{return defaultButton;}}
|
|
|
|
public SplitButton (string buttonText, Direction direction = Direction.Down)
|
|
:base(FlowDirection.LeftToRight, HAnchor.FitToChildren, VAnchor.FitToChildren)
|
|
{
|
|
|
|
defaultButton = CreateDefaultButton (buttonText);
|
|
altChoices = CreateDropDown (direction);
|
|
|
|
defaultButton.VAnchor = VAnchor.ParentCenter;
|
|
|
|
|
|
AddChild (defaultButton);
|
|
AddChild (altChoices);
|
|
}
|
|
|
|
public SplitButton(Button button, DynamicDropDownMenu menu)
|
|
:base(FlowDirection.LeftToRight,HAnchor.FitToChildren,VAnchor.FitToChildren)
|
|
{
|
|
defaultButton = button;
|
|
altChoices = menu;
|
|
|
|
defaultButton.VAnchor = VAnchor.ParentCenter;
|
|
|
|
AddChild (defaultButton);
|
|
AddChild (altChoices);
|
|
}
|
|
|
|
public void addItem(string name, Func<bool> clickFunction)
|
|
{
|
|
altChoices.addItem( name, clickFunction);
|
|
}
|
|
|
|
private DynamicDropDownMenu CreateDropDown(Direction direction)
|
|
{
|
|
DynamicDropDownMenu menu = new DynamicDropDownMenu ("", direction);
|
|
menu.VAnchor = VAnchor.ParentCenter;
|
|
menu.MenuAsWideAsItems = false;
|
|
menu.AlignToRightEdge = true;
|
|
menu.Height = defaultButton.Height;
|
|
|
|
return menu;
|
|
}
|
|
|
|
private Button CreateDefaultButton(string buttonText)
|
|
{
|
|
TextImageButtonFactory buttonFactory = new TextImageButtonFactory ();
|
|
buttonFactory.FixedHeight = 30;
|
|
buttonFactory.normalFillColor = RGBA_Bytes.White;
|
|
buttonFactory.normalTextColor = RGBA_Bytes.Black;
|
|
buttonFactory.hoverTextColor = RGBA_Bytes.Black;
|
|
buttonFactory.hoverFillColor = new RGBA_Bytes(255, 255, 255, 200);
|
|
buttonFactory.borderWidth = 1;
|
|
buttonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
|
|
buttonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
|
|
|
|
|
|
return buttonFactory.Generate (buttonText, centerText: true);
|
|
}
|
|
}
|
|
}
|
|
|