Use existing button factory

This commit is contained in:
John Lewin 2017-08-03 18:35:50 -07:00
parent 0613f8c8b9
commit 1efe8dec4f

View file

@ -60,25 +60,10 @@ namespace MatterHackers.MatterControl.PrinterControls
public class ActionControlsWidget : FlowLayoutWidget public class ActionControlsWidget : FlowLayoutWidget
{ {
protected string editWindowLabel;
protected string label;
protected FlowLayoutWidget presetButtonsContainer;
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
public ActionControlsWidget() public ActionControlsWidget()
: base(FlowDirection.TopToBottom) : base(FlowDirection.TopToBottom)
{ {
this.textImageButtonFactory.Options.Normal.FillColor = RGBA_Bytes.White; var buttonFactory = ApplicationController.Instance.Theme.HomingButtons;
this.textImageButtonFactory.Options.FixedHeight = 24 * GuiWidget.DeviceScale;
this.textImageButtonFactory.Options.FontSize = 12;
this.textImageButtonFactory.Options.BorderWidth = 1;
this.textImageButtonFactory.Options.Normal.BorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.Options.Hover.BorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.Options.Disabled.TextColor = RGBA_Bytes.Gray;
this.textImageButtonFactory.Options.Hover.TextColor = ActiveTheme.Instance.PrimaryTextColor;
this.textImageButtonFactory.Options.Normal.TextColor = RGBA_Bytes.Black;
this.textImageButtonFactory.Options.Pressed.TextColor = ActiveTheme.Instance.PrimaryTextColor;
this.HAnchor = HAnchor.ParentLeftRight; this.HAnchor = HAnchor.ParentLeftRight;
@ -97,36 +82,27 @@ namespace MatterHackers.MatterControl.PrinterControls
FlowLayoutWidget controlRow = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom); FlowLayoutWidget controlRow = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom);
controlRow.Margin = new BorderDouble(top: 5); controlRow.Margin = new BorderDouble(top: 5);
controlRow.HAnchor |= HAnchor.ParentLeftRight; controlRow.HAnchor |= HAnchor.ParentLeftRight;
{
this.presetButtonsContainer = GetMacroButtonContainer(); var macroButtonContainer = new FlowLayoutWidget();
controlRow.AddChild(this.presetButtonsContainer);
}
groupBox.AddChild(controlRow);
this.AddChild(groupBox);
}
private FlowLayoutWidget GetMacroButtonContainer()
{
FlowLayoutWidget macroButtonContainer = new FlowLayoutWidget();
macroButtonContainer.Margin = new BorderDouble(0, 0, 3, 0); macroButtonContainer.Margin = new BorderDouble(0, 0, 3, 0);
macroButtonContainer.Padding = new BorderDouble(0, 3, 3, 3); macroButtonContainer.Padding = new BorderDouble(0, 3, 3, 3);
if (ActiveSliceSettings.Instance?.ActionMacros().Any() != true) if (ActiveSliceSettings.Instance?.ActionMacros().Any() == true)
{ {
return macroButtonContainer; foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros())
{
Button macroButton = buttonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(right: 5);
macroButton.Click += (s, e) => macro.Run();
macroButtonContainer.AddChild(macroButton);
}
} }
foreach (GCodeMacro macro in ActiveSliceSettings.Instance.ActionMacros()) controlRow.AddChild(macroButtonContainer);
{
Button macroButton = textImageButtonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(right: 5);
macroButton.Click += (s, e) => macro.Run();
macroButtonContainer.AddChild(macroButton); groupBox.AddChild(controlRow);
} this.AddChild(groupBox);
return macroButtonContainer;
} }
} }