mattercontrol/ControlElements/SplitButtonFactory.cs
Lars Brubaker 47fed001ec Made the save button be on the edit bar.
Made the up arrow cause save to show.
2014-12-12 12:57:44 -08:00

108 lines
3.7 KiB
C#

using System;
using MatterHackers.Agg.UI;
using MatterHackers.Agg;
namespace MatterHackers.MatterControl
{
public class SplitButtonFactory
{
public BorderDouble Margin = new BorderDouble(0, 0);
public RGBA_Bytes normalFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes hoverFillColor = new RGBA_Bytes(0, 0, 0, 50);
public RGBA_Bytes pressedFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledFillColor = new RGBA_Bytes(255, 255, 255, 50);
public RGBA_Bytes normalBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes hoverBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes pressedBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes checkedBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
public int fontSize = 12;
public double borderWidth = 1;
public bool invertImageLocation = false;
public bool AllowThemeToAdjustImage = true;
public double FixedHeight = 30;
public SplitButtonFactory ()
{
}
public SplitButton Generate (TupleList<string, Func<bool>> buttonList, Direction direction = Direction.Down )
{
DynamicDropDownMenu menu = CreateMenu(direction);
menu.Margin = new BorderDouble();
Button button = CreateButton (buttonList [0]);
for(int index =1; index < buttonList.Count; index++)
{
menu.addItem (buttonList[index].Item1,buttonList[index].Item2);
}
SplitButton splitButton = new SplitButton (button, menu);
return splitButton;
}
private Button CreateButton(Tuple<string,Func<bool>> buttonInfo)
{
TextImageButtonFactory buttonFactory = new TextImageButtonFactory ();
buttonFactory.FixedHeight = this.FixedHeight;
buttonFactory.normalFillColor = this.normalFillColor;
buttonFactory.normalTextColor = this.normalTextColor;
buttonFactory.hoverTextColor = this.hoverTextColor;
buttonFactory.hoverFillColor = this.hoverFillColor;
buttonFactory.borderWidth = 1;
buttonFactory.normalBorderColor = this.normalBorderColor;
buttonFactory.hoverBorderColor = this.hoverBorderColor;
Button button = buttonFactory.Generate (buttonInfo.Item1, centerText: true);
button.Click += (object sender, EventArgs e) =>
{
buttonInfo.Item2();
};
return button;
}
private DynamicDropDownMenu CreateMenu(Direction direction = Direction.Down)
{
DropDownMenuFactory menuFactory = new DropDownMenuFactory ();
menuFactory.normalFillColor = this.normalFillColor;
menuFactory.hoverFillColor = this.hoverFillColor;
menuFactory.pressedFillColor = this.pressedFillColor;
menuFactory.pressedFillColor = this.pressedFillColor;
menuFactory.normalBorderColor = this.normalBorderColor;
menuFactory.hoverBorderColor = this.hoverBorderColor;
menuFactory.pressedBorderColor = this.pressedBorderColor;
menuFactory.disabledBorderColor = this.disabledBorderColor;
menuFactory.normalTextColor = this.normalTextColor;
menuFactory.hoverTextColor = this.hoverTextColor;
menuFactory.pressedTextColor = this.pressedTextColor;
menuFactory.disabledTextColor = this.disabledTextColor;
DynamicDropDownMenu menu = menuFactory.Generate(direction:direction);
menu.Height = FixedHeight;
menu.BorderColor = normalBorderColor;
menu.HoverArrowColor = this.hoverTextColor;
menu.NormalArrowColor = this.normalTextColor;
menu.BackgroundColor = normalFillColor;
return menu;
}
}
}