From 9af153f1fea8f981b6fbe58a959b356518b4de26 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 4 Aug 2017 08:49:38 -0700 Subject: [PATCH 1/3] Use existing button factory, use existing Options in SplitButton factory --- ControlElements/SplitButtonFactory.cs | 70 +++++-------------- Library/Widgets/PrintLibraryWidget.cs | 24 +------ .../SlicePresetsWindow/SlicePresetsWindow.cs | 9 +-- 3 files changed, 21 insertions(+), 82 deletions(-) diff --git a/ControlElements/SplitButtonFactory.cs b/ControlElements/SplitButtonFactory.cs index bb53bad1f..cdbac74a4 100644 --- a/ControlElements/SplitButtonFactory.cs +++ b/ControlElements/SplitButtonFactory.cs @@ -8,23 +8,6 @@ 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; @@ -32,30 +15,32 @@ namespace MatterHackers.MatterControl public double FixedHeight = 30 * GuiWidget.DeviceScale; + public ButtonFactoryOptions Options { get; set; } = ApplicationController.Instance.Theme.ButtonFactory.Options; + public SplitButton Generate(List actions, Direction direction = Direction.Down, string imageName = null) { var menuFactory = new DropDownMenuFactory() { - normalFillColor = this.normalFillColor, - hoverFillColor = this.hoverFillColor, - pressedFillColor = this.pressedFillColor, - normalBorderColor = this.normalBorderColor, - hoverBorderColor = this.hoverBorderColor, - pressedBorderColor = this.pressedBorderColor, - disabledBorderColor = this.disabledBorderColor, - normalTextColor = this.normalTextColor, - hoverTextColor = this.hoverTextColor, - pressedTextColor = this.pressedTextColor, - disabledTextColor = this.disabledTextColor, + normalFillColor = this.Options.Normal.FillColor, + hoverFillColor = this.Options.Hover.FillColor, + pressedFillColor = this.Options.Pressed.FillColor, + normalBorderColor = this.Options.Normal.BorderColor, + hoverBorderColor = this.Options.Hover.BorderColor, + pressedBorderColor = this.Options.Pressed.BorderColor, + disabledBorderColor = this.Options.Disabled.BorderColor, + normalTextColor = this.Options.Normal.TextColor, + hoverTextColor = this.Options.Hover.TextColor, + pressedTextColor = this.Options.Pressed.TextColor, + disabledTextColor = this.Options.Disabled.TextColor, FixedWidth = 20, }; DropDownMenu menu = menuFactory.Generate(actions: actions.Skip(1).ToList(), direction: direction); menu.Height = FixedHeight; - menu.BorderColor = normalBorderColor; - menu.HoverArrowColor = this.hoverTextColor; - menu.NormalArrowColor = this.normalTextColor; - menu.BackgroundColor = normalFillColor; + menu.BorderColor = this.Options.Normal.BorderColor; + menu.HoverArrowColor = this.Options.Hover.TextColor; + menu.NormalArrowColor = this.Options.Normal.TextColor; + menu.BackgroundColor = this.Options.Normal.FillColor; menu.Margin = new BorderDouble(); // TODO: Why? @@ -66,26 +51,7 @@ namespace MatterHackers.MatterControl var primaryAction = actions[0]; - var buttonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - FixedHeight = this.FixedHeight, - - Normal = new ButtonOptionSection() - { - - FillColor = this.normalFillColor, - TextColor = this.normalTextColor, - BorderColor = this.normalBorderColor, - }, - Hover = new ButtonOptionSection() - { - TextColor = this.hoverTextColor, - FillColor = this.hoverFillColor, - BorderColor = this.hoverBorderColor - }, - - BorderWidth = 1, - }); + var buttonFactory = ApplicationController.Instance.Theme.SmallMarginButtonFactory; Button button = buttonFactory.Generate(primaryAction.Title, normalImageName: imageName, centerText: true); button.Name = $"{primaryAction.Title} Button"; diff --git a/Library/Widgets/PrintLibraryWidget.cs b/Library/Widgets/PrintLibraryWidget.cs index e71f492a6..6c40e2ab7 100644 --- a/Library/Widgets/PrintLibraryWidget.cs +++ b/Library/Widgets/PrintLibraryWidget.cs @@ -54,8 +54,6 @@ namespace MatterHackers.MatterControl.PrintLibrary private static CreateFolderWindow createFolderWindow = null; private static RenameItemWindow renameItemWindow = null; private ExportToFolderFeedbackWindow exportingWindow = null; - private TextImageButtonFactory textImageButtonFactory; - private TextImageButtonFactory editButtonFactory; private Button addToLibraryButton; private Button createFolderButton; @@ -79,26 +77,6 @@ namespace MatterHackers.MatterControl.PrintLibrary this.BackgroundColor = ApplicationController.Instance.Theme.TabBodyBackground; this.AnchorAll(); - textImageButtonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - BorderWidth = 0, - - Normal = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Hover = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Pressed = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Disabled = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.TabLabelUnselected, FillColor = new RGBA_Bytes() } - }); - - editButtonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - Normal = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Hover = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Disabled = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.TabLabelUnselected, FillColor = new RGBA_Bytes() }, - Pressed = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - BorderWidth = 0, - Margin = new BorderDouble(10, 0) - }); - var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom); libraryView = new ListView(ApplicationController.Instance.Library) @@ -266,6 +244,8 @@ namespace MatterHackers.MatterControl.PrintLibrary private void AddLibraryButtonElements() { + var textImageButtonFactory = ApplicationController.Instance.Theme.SmallMarginButtonFactory; + buttonPanel.RemoveAllChildren(); // the add button diff --git a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs index a8fdad625..9b5825663 100644 --- a/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs +++ b/SlicerConfiguration/SlicePresetsWindow/SlicePresetsWindow.cs @@ -84,14 +84,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration textColor = ActiveTheme.Instance.SecondaryAccentColor }; - var buttonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - Normal = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Hover = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Disabled = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - Pressed = new ButtonOptionSection() { TextColor = ActiveTheme.Instance.PrimaryTextColor }, - BorderWidth = 0 - }); + var buttonFactory = ApplicationController.Instance.Theme.ButtonFactory; FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom) { From 6fabdf441379acac419af1fcb2c9136d354c884b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 4 Aug 2017 08:50:17 -0700 Subject: [PATCH 2/3] Reduce SplitButton to actual behavior --- CustomWidgets/SplitButton.cs | 63 ++++++++---------------------------- 1 file changed, 13 insertions(+), 50 deletions(-) diff --git a/CustomWidgets/SplitButton.cs b/CustomWidgets/SplitButton.cs index 77f3e0542..72a334ba1 100644 --- a/CustomWidgets/SplitButton.cs +++ b/CustomWidgets/SplitButton.cs @@ -27,79 +27,42 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using MatterHackers.Agg; using MatterHackers.Agg.UI; namespace MatterHackers.MatterControl { public class SplitButton : FlowLayoutWidget { - private DropDownMenu altChoices; - - private Button DefaultButton { get; } - public SplitButton(string buttonText, Direction direction = Direction.Down) : base(FlowDirection.LeftToRight) { HAnchor = HAnchor.FitToChildren; VAnchor = VAnchor.FitToChildren; - this.DefaultButton = CreateDefaultButton(buttonText); - this.DefaultButton.VAnchor = VAnchor.ParentCenter; + var button = ApplicationController.Instance.Theme.ButtonFactory.Generate(buttonText, centerText: true); + button.VAnchor = VAnchor.ParentCenter; - altChoices = CreateDropDown(direction); + AddChild(button); - AddChild(this.DefaultButton); - AddChild(altChoices); + AddChild(new DropDownMenu("", direction) + { + VAnchor = VAnchor.ParentCenter, + MenuAsWideAsItems = false, + AlignToRightEdge = true, + Height = button.Height + }); } - public SplitButton(Button button, DropDownMenu menu) + public SplitButton(Button button, DropDownMenu altChoices) : base(FlowDirection.LeftToRight) { HAnchor = HAnchor.FitToChildren; VAnchor = VAnchor.FitToChildren; - this.DefaultButton = button; - this.DefaultButton.VAnchor = VAnchor.ParentCenter; + button.VAnchor = VAnchor.ParentCenter; - altChoices = menu; - - AddChild(this.DefaultButton); + AddChild(button); AddChild(altChoices); } - - private DropDownMenu CreateDropDown(Direction direction) - { - return new DropDownMenu("", direction) - { - VAnchor = VAnchor.ParentCenter, - MenuAsWideAsItems = false, - AlignToRightEdge = true, - Height = this.DefaultButton.Height - }; - } - - private Button CreateDefaultButton(string buttonText) - { - var buttonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - FixedHeight = 30 * GuiWidget.DeviceScale, - Normal = new ButtonOptionSection() - { - FillColor = RGBA_Bytes.White, - TextColor = RGBA_Bytes.Black, - BorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200), - }, - Hover = new ButtonOptionSection() - { - TextColor = RGBA_Bytes.Black, - FillColor = new RGBA_Bytes(255, 255, 255, 200), - BorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200) - }, - BorderWidth = 1, - }); - - return buttonFactory.Generate(buttonText, centerText: true); - } } } \ No newline at end of file From e75bb81c78cd0d0c1040556f2b9460096ae0c59f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 4 Aug 2017 09:00:20 -0700 Subject: [PATCH 3/3] Extract unique button types to theme config --- ActionBar/TemperatureWidgetExtruder.cs | 24 +---------------------- ApplicationView/ThemeConfig.cs | 27 +++++++++++++++++++++++++- PrinterControls/XYZJogControls.cs | 18 ++--------------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index 5d7d2722a..1d64d99cf 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -170,29 +170,7 @@ namespace MatterHackers.MatterControl.ActionBar // Extrude buttons {{ - var moveButtonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - FixedHeight = 20 * GuiWidget.DeviceScale, - FixedWidth = 30 * GuiWidget.DeviceScale, - FontSize = 8, - Margin = new BorderDouble(2, 0), - CheckedBorderColor = buttonFactory.normalTextColor, - - Normal = new ButtonOptionSection() - { - TextColor = buttonFactory.normalTextColor, - FillColor = buttonFactory.normalFillColor, - }, - Hover = new ButtonOptionSection() - { - FillColor = buttonFactory.hoverFillColor, - }, - Pressed = new ButtonOptionSection() - { - FillColor = buttonFactory.pressedFillColor, - TextColor = buttonFactory.pressedTextColor - } - }); + var moveButtonFactory = ApplicationController.Instance.Theme.MicroButtonMenu; var buttonContainer = new FlowLayoutWidget() { diff --git a/ApplicationView/ThemeConfig.cs b/ApplicationView/ThemeConfig.cs index 1be8c2a1e..04b14ec64 100644 --- a/ApplicationView/ThemeConfig.cs +++ b/ApplicationView/ThemeConfig.cs @@ -90,6 +90,8 @@ namespace MatterHackers.MatterControl public TextImageButtonFactory DisableableControlBase { get; private set; } public TextImageButtonFactory HomingButtons { get; private set; } + public TextImageButtonFactory MicroButton { get; private set; } + public TextImageButtonFactory MicroButtonMenu { get; private set; } private EventHandler unregisterEvents; @@ -139,13 +141,17 @@ namespace MatterHackers.MatterControl options.Margin = new BorderDouble(8, 0); })); - this.MenuButtonFactory = new TextImageButtonFactory(commonOptions.Clone(options => + var commonGray = commonOptions.Clone(options => { options.Normal.TextColor = RGBA_Bytes.Black; options.Normal.FillColor = RGBA_Bytes.LightGray; options.Hover.TextColor = RGBA_Bytes.Black; options.Pressed.TextColor = RGBA_Bytes.Black; options.Pressed.FillColor = RGBA_Bytes.LightGray; + }); + + this.MenuButtonFactory = new TextImageButtonFactory(commonGray.Clone(options => + { options.Margin = new BorderDouble(8, 0); })); @@ -166,6 +172,25 @@ namespace MatterHackers.MatterControl options.CheckedBorderColor = RGBA_Bytes.White; })); + this.MicroButton = new TextImageButtonFactory(new ButtonFactoryOptions() + { + FixedHeight = 20 * GuiWidget.DeviceScale, + FixedWidth = 30 * GuiWidget.DeviceScale, + FontSize = 8, + Margin = 0, + CheckedBorderColor = ActiveTheme.Instance.PrimaryTextColor + }); + + this.MicroButtonMenu = new TextImageButtonFactory(commonGray.Clone(options => + { + options.FixedHeight = 20 * GuiWidget.DeviceScale; + options.FixedWidth = 30 * GuiWidget.DeviceScale; + options.FontSize = 8; + options.Margin = 0; + options.BorderWidth = 1; + options.CheckedBorderColor = RGBA_Bytes.Black; + })); + #region PartPreviewWidget if (UserSettings.Instance.IsTouchScreen) { diff --git a/PrinterControls/XYZJogControls.cs b/PrinterControls/XYZJogControls.cs index 07c777269..cd5aac5ef 100644 --- a/PrinterControls/XYZJogControls.cs +++ b/PrinterControls/XYZJogControls.cs @@ -95,14 +95,7 @@ namespace MatterHackers.MatterControl //setMoveDistanceControl.AddChild(buttonsLabel); { - var buttonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - FixedHeight = 20 * GuiWidget.DeviceScale, - FixedWidth = 30 * GuiWidget.DeviceScale, - FontSize = 8, - Margin = new BorderDouble(0), - CheckedBorderColor = ActiveTheme.Instance.PrimaryTextColor, - }); + var buttonFactory = ApplicationController.Instance.Theme.MicroButton; FlowLayoutWidget moveRadioButtons = new FlowLayoutWidget(); @@ -501,14 +494,7 @@ namespace MatterHackers.MatterControl //setMoveDistanceControl.AddChild(buttonsLabel); { - var buttonFactory = new TextImageButtonFactory(new ButtonFactoryOptions() - { - FixedHeight = 20 * GuiWidget.DeviceScale, - FixedWidth = 30 * GuiWidget.DeviceScale, - FontSize = 8, - Margin = 0, - CheckedBorderColor = ActiveTheme.Instance.PrimaryTextColor - }); + var buttonFactory = ApplicationController.Instance.Theme.MicroButton; var moveRadioButtons = new FlowLayoutWidget(); RadioButton oneButton = buttonFactory.GenerateRadioButton("1");