2017-08-17 13:05:30 -07:00
|
|
|
|
using System;
|
2017-05-26 11:23:41 -07:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-31 12:42:44 -07:00
|
|
|
|
using System.Linq;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-08-17 13:05:30 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SplitButtonFactory
|
|
|
|
|
|
{
|
|
|
|
|
|
public int fontSize = 12;
|
|
|
|
|
|
public double borderWidth = 1;
|
|
|
|
|
|
public bool invertImageLocation = false;
|
|
|
|
|
|
public bool AllowThemeToAdjustImage = true;
|
|
|
|
|
|
|
2016-05-06 17:56:27 -07:00
|
|
|
|
public double FixedHeight = 30 * GuiWidget.DeviceScale;
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
2017-08-04 08:49:38 -07:00
|
|
|
|
public ButtonFactoryOptions Options { get; set; } = ApplicationController.Instance.Theme.ButtonFactory.Options;
|
|
|
|
|
|
|
2017-05-31 12:42:44 -07:00
|
|
|
|
public SplitButton Generate(List<NamedAction> actions, Direction direction = Direction.Down, string imageName = null)
|
2014-11-17 15:50:39 -08:00
|
|
|
|
{
|
2017-05-31 12:42:44 -07:00
|
|
|
|
var menuFactory = new DropDownMenuFactory()
|
2015-09-01 16:03:29 -07:00
|
|
|
|
{
|
2017-08-17 13:05:30 -07:00
|
|
|
|
normalFillColor = this.Options.NormalFillColor,
|
|
|
|
|
|
hoverFillColor = this.Options.HoverFillColor,
|
|
|
|
|
|
pressedFillColor = this.Options.PressedFillColor,
|
|
|
|
|
|
normalBorderColor = this.Options.NormalBorderColor,
|
|
|
|
|
|
hoverBorderColor = this.Options.HoverBorderColor,
|
|
|
|
|
|
pressedBorderColor = this.Options.PressedBorderColor,
|
|
|
|
|
|
disabledBorderColor = this.Options.DisabledBorderColor,
|
|
|
|
|
|
normalTextColor = this.Options.NormalTextColor,
|
|
|
|
|
|
hoverTextColor = this.Options.HoverTextColor,
|
|
|
|
|
|
pressedTextColor = this.Options.PressedTextColor,
|
|
|
|
|
|
disabledTextColor = this.Options.DisabledTextColor,
|
2017-05-31 12:42:44 -07:00
|
|
|
|
FixedWidth = 20,
|
|
|
|
|
|
};
|
2015-09-01 16:03:29 -07:00
|
|
|
|
|
2017-05-31 12:42:44 -07:00
|
|
|
|
DropDownMenu menu = menuFactory.Generate(actions: actions.Skip(1).ToList(), direction: direction);
|
|
|
|
|
|
menu.Height = FixedHeight;
|
2017-08-17 13:05:30 -07:00
|
|
|
|
menu.BorderColor = this.Options.NormalBorderColor;
|
|
|
|
|
|
menu.HoverArrowColor = this.Options.HoverTextColor;
|
|
|
|
|
|
menu.NormalArrowColor = this.Options.NormalTextColor;
|
|
|
|
|
|
menu.BackgroundColor = this.Options.NormalFillColor;
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
2017-05-31 12:42:44 -07:00
|
|
|
|
// TODO: Why?
|
|
|
|
|
|
if (actions.Count > 1)
|
2014-11-17 15:50:39 -08:00
|
|
|
|
{
|
2017-05-31 12:42:44 -07:00
|
|
|
|
menu.Name = actions[1].Title + " Menu";
|
2014-11-17 15:50:39 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-31 12:42:44 -07:00
|
|
|
|
var primaryAction = actions[0];
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
2017-08-04 08:49:38 -07:00
|
|
|
|
var buttonFactory = ApplicationController.Instance.Theme.SmallMarginButtonFactory;
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
2017-10-14 23:18:06 -07:00
|
|
|
|
Button button = buttonFactory.Generate(primaryAction.Title, AggContext.StaticData.LoadIcon(imageName, 24, 24, IconColor.Theme));
|
2017-06-03 19:08:14 -07:00
|
|
|
|
button.Name = $"{primaryAction.Title} Button";
|
2017-05-26 11:23:41 -07:00
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-05-31 12:42:44 -07:00
|
|
|
|
primaryAction.Action();
|
2017-05-26 11:23:41 -07:00
|
|
|
|
};
|
2014-11-17 15:50:39 -08:00
|
|
|
|
|
2017-05-31 12:42:44 -07:00
|
|
|
|
return new SplitButton(button, menu);
|
2014-11-17 15:50:39 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|