From b1cc3fe5ac383c5d293e9cdae5edd28924f2bc2f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 14 Apr 2018 20:51:01 -0700 Subject: [PATCH] Remove WizardButton factory --- ApplicationView/ThemeConfig.cs | 35 +++++++++++++------ ConfigurationPage/RunningMacroPage.cs | 2 +- ControlElements/StyledMessageBoxWindow.cs | 2 +- CustomWidgets/ExportPrintItemPage.cs | 2 +- PrinterControls/MacroDetailPage.cs | 2 +- PrinterControls/MacroListPage.cs | 2 +- .../PrinterConnections/SetupStepBaudRate.cs | 6 ++-- .../SetupStepComPortManual.cs | 14 ++++---- .../PrinterConnections/SetupStepComPortOne.cs | 2 +- .../PrinterConnections/SetupStepComPortTwo.cs | 8 ++--- .../SetupStepMakeModelName.cs | 4 +-- .../PrinterConnections/ShowAuthPanel.cs | 4 +-- SetupWizard/CopyGuestProfilesToUser.cs | 2 +- SetupWizard/DialogPage.cs | 8 ++--- SetupWizard/ImportSettingsPage.cs | 2 +- SetupWizard/InputBoxPage.cs | 4 +-- SetupWizard/LicenseAgreementPage.cs | 2 +- SetupWizard/PrinterProfileHistoryPage.cs | 4 +-- SetupWizard/PublishPartToMatterHackers.cs | 2 +- 19 files changed, 60 insertions(+), 47 deletions(-) diff --git a/ApplicationView/ThemeConfig.cs b/ApplicationView/ThemeConfig.cs index 0b44e627d..e51d68773 100644 --- a/ApplicationView/ThemeConfig.cs +++ b/ApplicationView/ThemeConfig.cs @@ -77,7 +77,6 @@ namespace MatterHackers.MatterControl public TextImageButtonFactory WhiteButtonFactory { get; private set; } public TextImageButtonFactory ButtonFactory { get; private set; } - public TextImageButtonFactory WizardButtons { get; private set; } public int SplitterWidth => (int)(6 * (GuiWidget.DeviceScale <= 1 ? GuiWidget.DeviceScale : GuiWidget.DeviceScale * 1.4)); @@ -127,6 +126,8 @@ namespace MatterHackers.MatterControl { } + private BorderDouble commonFactoryMargin = new BorderDouble(14, 0); + public void RebuildTheme(IThemeColors colors) { this.Colors = colors; @@ -138,7 +139,7 @@ namespace MatterHackers.MatterControl commonOptions.HoverTextColor = colors.PrimaryTextColor; commonOptions.PressedTextColor = colors.PrimaryTextColor; commonOptions.DisabledTextColor = colors.TertiaryBackgroundColor; - commonOptions.Margin = new BorderDouble(14, 0); + commonOptions.Margin = commonFactoryMargin; commonOptions.FontSize = this.DefaultFontSize; commonOptions.ImageSpacing = 8; commonOptions.BorderWidth = 0; @@ -164,15 +165,6 @@ namespace MatterHackers.MatterControl this.ButtonFactory = new TextImageButtonFactory(commonOptions); - this.WizardButtons = new TextImageButtonFactory(new ButtonFactoryOptions(commonOptions) - { -#if __ANDROID__ - FontSize = this.FontSize14, - FixedHeight = 34 * GuiWidget.DeviceScale, - Margin = commonOptions.Margin * 1.2 -#endif - }); - var commonGray = new ButtonFactoryOptions(commonOptions) { NormalTextColor = Color.Black, @@ -229,6 +221,27 @@ namespace MatterHackers.MatterControl return radioButton; } + public TextButton CreateDialogButton(string text) + { + var textSize = -1; + +#if __ANDROID__ + textSize = this.FontSize14, +#endif + + var button = new TextButton(text, this, textSize) + { + BackgroundColor = this.SlightShade, +#if __ANDROID__ + // Enlarge button height and margin on Android + Height = 34 * GuiWidget.DeviceScale, + Margin = commonFactoryMargin * 1.2 +#endif + }; + + return button; + } + public Color GetBorderColor(int alpha) { return new Color(this.Colors.SecondaryTextColor, alpha); diff --git a/ConfigurationPage/RunningMacroPage.cs b/ConfigurationPage/RunningMacroPage.cs index 938681e5d..c7409557c 100644 --- a/ConfigurationPage/RunningMacroPage.cs +++ b/ConfigurationPage/RunningMacroPage.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PrinterControls if (macroData.waitOk | macroData.expireTime > 0) { - Button okButton = textImageButtonFactory.Generate("Continue".Localize()); + var okButton = theme.CreateDialogButton("Continue".Localize()); okButton.Click += (s, e) => { printer.Connection.MacroContinue(); diff --git a/ControlElements/StyledMessageBoxWindow.cs b/ControlElements/StyledMessageBoxWindow.cs index 594605835..e22aa37c0 100644 --- a/ControlElements/StyledMessageBoxWindow.cs +++ b/ControlElements/StyledMessageBoxWindow.cs @@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl } } - Button affirmativeButton = textImageButtonFactory.Generate(yesOk); + var affirmativeButton = theme.CreateDialogButton(yesOk); affirmativeButton.Click += (s, e) => { UiThread.RunOnIdle(this.WizardWindow.Close); diff --git a/CustomWidgets/ExportPrintItemPage.cs b/CustomWidgets/ExportPrintItemPage.cs index e6470ad69..dc5495f07 100644 --- a/CustomWidgets/ExportPrintItemPage.cs +++ b/CustomWidgets/ExportPrintItemPage.cs @@ -122,7 +122,7 @@ namespace MatterHackers.MatterControl contentRow.AddChild(showInFolderAfterSave); } - var exportButton = textImageButtonFactory.Generate("Export".Localize()); + var exportButton = theme.CreateDialogButton("Export".Localize()); exportButton.Name = "Export Button"; exportButton.Click += (s, e) => { diff --git a/PrinterControls/MacroDetailPage.cs b/PrinterControls/MacroDetailPage.cs index f2aa77af9..8c49bcd6a 100644 --- a/PrinterControls/MacroDetailPage.cs +++ b/PrinterControls/MacroDetailPage.cs @@ -109,7 +109,7 @@ namespace MatterHackers.MatterControl contentRow.AddChild(container); - Button addMacroButton = textImageButtonFactory.Generate("Save".Localize()); + var addMacroButton = theme.CreateDialogButton("Save".Localize()); addMacroButton.Click += (s, e) => { UiThread.RunOnIdle(() => diff --git a/PrinterControls/MacroListPage.cs b/PrinterControls/MacroListPage.cs index f3e38732c..3e036a6b8 100644 --- a/PrinterControls/MacroListPage.cs +++ b/PrinterControls/MacroListPage.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl this.RebuildList(printerSettings, linkButtonFactory); - Button addMacroButton = textImageButtonFactory.Generate("Add".Localize(), AggContext.StaticData.LoadIcon("fa-plus_16.png", theme.InvertIcons)); + var addMacroButton = theme.CreateDialogButton("Add".Localize()); addMacroButton.ToolTipText = "Add a new Macro".Localize(); addMacroButton.Click += (s, e) => { diff --git a/PrinterControls/PrinterConnections/SetupStepBaudRate.cs b/PrinterControls/PrinterConnections/SetupStepBaudRate.cs index 85b936f11..5fe6fc259 100644 --- a/PrinterControls/PrinterConnections/SetupStepBaudRate.cs +++ b/PrinterControls/PrinterConnections/SetupStepBaudRate.cs @@ -45,8 +45,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private GuiWidget baudRateWidget; private RadioButton otherBaudRateRadioButton; private MHTextEditWidget otherBaudRateInput; - private Button nextButton; - private Button printerBaudRateHelpLink; + private GuiWidget nextButton; + private GuiWidget printerBaudRateHelpLink; private TextWidget printerBaudRateHelpMessage; private PrinterConfig printer; @@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections printerBaudRateContainer = createPrinterBaudRateContainer(); contentRow.AddChild(printerBaudRateContainer); { - nextButton = textImageButtonFactory.Generate("Continue".Localize()); + nextButton = theme.CreateDialogButton("Continue".Localize()); nextButton.Click += (s, e) => { bool canContinue = this.OnSave(); diff --git a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs index efc29e358..fd06f08bb 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs @@ -40,10 +40,10 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { public class SetupStepComPortManual : DialogPage { - private Button nextButton; - private Button connectButton; - private Button refreshButton; - private Button printerComPortHelpLink; + private GuiWidget nextButton; + private GuiWidget connectButton; + private GuiWidget refreshButton; + private GuiWidget printerComPortHelpLink; private bool printerComPortIsAvailable = false; @@ -62,11 +62,11 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections contentRow.AddChild(printerComPortContainer); //Construct buttons - nextButton = textImageButtonFactory.Generate("Done".Localize()); + nextButton = theme.CreateDialogButton("Done".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); nextButton.Visible = false; - connectButton = textImageButtonFactory.Generate("Connect".Localize()); + connectButton = theme.CreateDialogButton("Connect".Localize()); connectButton.Click += (s, e) => { try @@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections } }; - refreshButton = textImageButtonFactory.Generate("Refresh".Localize()); + refreshButton = theme.CreateDialogButton("Refresh".Localize()); refreshButton.Click += (s, e) => UiThread.RunOnIdle(() => { WizardWindow.ChangeToPage(new SetupStepComPortManual(printer)); diff --git a/PrinterControls/PrinterConnections/SetupStepComPortOne.cs b/PrinterControls/PrinterConnections/SetupStepComPortOne.cs index 6e9c42047..745e8b572 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortOne.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortOne.cs @@ -112,7 +112,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections contentRow.AddChild(container); //Construct buttons - var nextButton = textImageButtonFactory.Generate("Continue".Localize()); + var nextButton = theme.CreateDialogButton("Continue".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(() => { WizardWindow.ChangeToPage(new SetupStepComPortTwo(printer)); diff --git a/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs b/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs index 543feae52..0b0ac4fb1 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs @@ -42,8 +42,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { private string[] startingPortNames; - private Button nextButton; - private Button connectButton; + private GuiWidget nextButton; + private GuiWidget connectButton; private TextWidget printerErrorMessage; private EventHandler unregisterEvents; @@ -57,11 +57,11 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections contentRow.AddChild(createPrinterConnectionMessageContainer()); //Construct buttons - nextButton = textImageButtonFactory.Generate("Done".Localize()); + nextButton = theme.CreateDialogButton("Done".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); nextButton.Visible = false; - connectButton = textImageButtonFactory.Generate("Connect".Localize()); + connectButton = theme.CreateDialogButton("Connect".Localize()); connectButton.Click += (s, e) => { // Select the first port that's in GetPortNames() but not in startingPortNames diff --git a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 3935c38e5..a8a281fa7 100644 --- a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private TextWidget printerNameError; - private Button nextButton; + private GuiWidget nextButton; private bool usingDefaultName; @@ -99,7 +99,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections contentRow.AddChild(createPrinterNameContainer()); //Construct buttons - nextButton = textImageButtonFactory.Generate("Save & Continue".Localize()); + nextButton = theme.CreateDialogButton("Save & Continue".Localize()); nextButton.Name = "Save & Continue Button"; nextButton.Click += async (s, e) => { diff --git a/PrinterControls/PrinterConnections/ShowAuthPanel.cs b/PrinterControls/PrinterConnections/ShowAuthPanel.cs index cf1f9afd6..d084b8903 100644 --- a/PrinterControls/PrinterConnections/ShowAuthPanel.cs +++ b/PrinterControls/PrinterConnections/ShowAuthPanel.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections this.SetCancelButtonName("Connection Wizard Skip Sign In Button"); - var createAccountButton = textImageButtonFactory.Generate("Create Account".Localize()); + var createAccountButton = theme.CreateDialogButton("Create Account".Localize()); createAccountButton.Name = "Create Account From Connection Wizard Button"; createAccountButton.Margin = new Agg.BorderDouble(right: 5); createAccountButton.Click += (s, e) => @@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections }); }; - var signInButton = textImageButtonFactory.Generate("Sign In".Localize()); + var signInButton = theme.CreateDialogButton("Sign In".Localize()); signInButton.Name = "Sign In From Connection Wizard Button"; signInButton.Click += (s, e) => { diff --git a/SetupWizard/CopyGuestProfilesToUser.cs b/SetupWizard/CopyGuestProfilesToUser.cs index 9627a3858..c150bc83f 100644 --- a/SetupWizard/CopyGuestProfilesToUser.cs +++ b/SetupWizard/CopyGuestProfilesToUser.cs @@ -94,7 +94,7 @@ namespace MatterHackers.MatterControl } } - var syncButton = textImageButtonFactory.Generate("Copy".Localize()); + var syncButton = theme.CreateDialogButton("Copy".Localize()); syncButton.Name = "CopyProfilesButton"; syncButton.Click += (s, e) => { diff --git a/SetupWizard/DialogPage.cs b/SetupWizard/DialogPage.cs index c0ad41055..1af2d225e 100644 --- a/SetupWizard/DialogPage.cs +++ b/SetupWizard/DialogPage.cs @@ -43,11 +43,10 @@ namespace MatterHackers.MatterControl private FlowLayoutWidget footerRow; private WrappedTextWidget headerLabel; - private Button cancelButton; + private GuiWidget cancelButton; public Vector2 WindowSize { get; set; } - protected TextImageButtonFactory textImageButtonFactory { get; } protected LinkButtonFactory linkButtonFactory { get; } protected double labelFontSize = 12 * GuiWidget.DeviceScale; @@ -61,7 +60,6 @@ namespace MatterHackers.MatterControl { theme = ApplicationController.Instance.Theme; - textImageButtonFactory = theme.WizardButtons; linkButtonFactory = theme.LinkButtonFactory; if (cancelButtonText == null) @@ -76,7 +74,8 @@ namespace MatterHackers.MatterControl this.AnchorAll(); - cancelButton = textImageButtonFactory.Generate(cancelButtonText); + cancelButton = theme.CreateDialogButton(cancelButtonText); + cancelButton.Margin = 0; cancelButton.Name = "Cancel Wizard Button"; // Create the main container @@ -154,6 +153,7 @@ namespace MatterHackers.MatterControl public void AddPageAction(GuiWidget button) { button.Margin = new BorderDouble(right: ApplicationController.Instance.Theme.ButtonSpacing.Left); + button.Margin = new BorderDouble(right: footerRow.Margin.Top); footerRow.AddChild(button); } diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index aa6e6287e..8d6f98a62 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -158,7 +158,7 @@ namespace MatterHackers.MatterControl } var importButtonTitle = "Import".Localize(); - var mergeButton = textImageButtonFactory.Generate(importButtonTitle); + var mergeButton = theme.CreateDialogButton(importButtonTitle); mergeButton.Name = "Merge Profile"; mergeButton.Click += (s, e) => UiThread.RunOnIdle(() => { diff --git a/SetupWizard/InputBoxPage.cs b/SetupWizard/InputBoxPage.cs index 2fd1eeecc..8645b8dbc 100644 --- a/SetupWizard/InputBoxPage.cs +++ b/SetupWizard/InputBoxPage.cs @@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl this.HeaderText = windowTitle; this.WindowSize = new Vector2(500, 200); - Button actionButton = null; + GuiWidget actionButton = null; contentRow.AddChild(new TextWidget(label, pointSize: 12) { @@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl }; contentRow.AddChild(textEditWidget); - actionButton = textImageButtonFactory.Generate(actionButtonTitle); + actionButton = theme.CreateDialogButton(actionButtonTitle); actionButton.Name = "InputBoxPage Action Button"; actionButton.Cursor = Cursors.Hand; actionButton.Click += (s, e) => diff --git a/SetupWizard/LicenseAgreementPage.cs b/SetupWizard/LicenseAgreementPage.cs index 4886208e7..710ffdeb7 100644 --- a/SetupWizard/LicenseAgreementPage.cs +++ b/SetupWizard/LicenseAgreementPage.cs @@ -54,7 +54,7 @@ public class LicenseAgreementPage : DialogPage Name = "LicenseAgreementPage", }); - var acceptButton = textImageButtonFactory.Generate("Accept".Localize()); + var acceptButton = theme.CreateDialogButton("Accept".Localize()); acceptButton.Click += (s, e) => { UserSettings.Instance.set("SoftwareLicenseAccepted", "true"); diff --git a/SetupWizard/PrinterProfileHistoryPage.cs b/SetupWizard/PrinterProfileHistoryPage.cs index 270b82ef6..6f411fa68 100644 --- a/SetupWizard/PrinterProfileHistoryPage.cs +++ b/SetupWizard/PrinterProfileHistoryPage.cs @@ -34,7 +34,7 @@ namespace MatterHackers.MatterControl.SetupWizard contentRow.FlowDirection = FlowDirection.TopToBottom; contentRow.AddChild(scrollWindow); - var revertButton = textImageButtonFactory.Generate("Restore".Localize()); + var revertButton = theme.CreateDialogButton("Restore".Localize()); revertButton.Click += async (s, e) => { int index = radioButtonList.IndexOf(radioButtonList.Where(r => r.Checked).FirstOrDefault()); @@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.SetupWizard // Update active instance without calling ReloadAll ApplicationController.Instance.RefreshActiveInstance(printerSettings); } - + UiThread.RunOnIdle(WizardWindow.Close); } }; diff --git a/SetupWizard/PublishPartToMatterHackers.cs b/SetupWizard/PublishPartToMatterHackers.cs index ad617963d..4f8a05eba 100644 --- a/SetupWizard/PublishPartToMatterHackers.cs +++ b/SetupWizard/PublishPartToMatterHackers.cs @@ -109,7 +109,7 @@ namespace MatterHackers.MatterControl Margin = new BorderDouble(5, 0, 0, 0) }); - var publishButton = textImageButtonFactory.Generate("Publish".Localize()); + var publishButton = theme.CreateDialogButton("Publish".Localize()); publishButton.Name = "PublishPartButton"; publishButton.Click += (s, e) => {