From 1c6814fffc5e4e97617104552022e7a0134c2b82 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 2 Jan 2019 22:45:08 -0800 Subject: [PATCH] Vector2 single char label --- .../ControlElements/MHNumberEdit.cs | 19 ++++++++++++++++++- .../UIFields/Vector2Field.cs | 17 ++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/MatterControlLib/ControlElements/MHNumberEdit.cs b/MatterControlLib/ControlElements/MHNumberEdit.cs index ee369fb45..03da563b3 100644 --- a/MatterControlLib/ControlElements/MHNumberEdit.cs +++ b/MatterControlLib/ControlElements/MHNumberEdit.cs @@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl public NumberEdit ActuallNumberEdit { get; } - public MHNumberEdit(double startingValue, ThemeConfig theme, double pixelWidth = 0, double pixelHeight = 0, bool allowNegatives = false, bool allowDecimals = false, double minValue = int.MinValue, double maxValue = int.MaxValue, double increment = 1, int tabIndex = 0) + public MHNumberEdit(double startingValue, ThemeConfig theme, char singleCharLabel = char.MaxValue, double pixelWidth = 0, double pixelHeight = 0, bool allowNegatives = false, bool allowDecimals = false, double minValue = int.MinValue, double maxValue = int.MaxValue, double increment = 1, int tabIndex = 0) { using (this.LayoutLock()) { @@ -48,11 +48,28 @@ namespace MatterHackers.MatterControl this.Border = 1; this.theme = theme; + double labelWidth = 0; + + if (singleCharLabel != char.MaxValue) + { + var labelWidget = new TextWidget(singleCharLabel.ToString(), pointSize: theme.DefaultFontSize - 2, textColor: theme.PrimaryAccentColor) + { + Margin = new BorderDouble(left: 2), + HAnchor = HAnchor.Left, + VAnchor = VAnchor.Center + }; + labelWidth = labelWidget.Width + labelWidget.Margin.Left; + + this.AddChild(labelWidget); + } + this.ActuallNumberEdit = new NumberEdit(startingValue, 0, 0, theme.DefaultFontSize, pixelWidth, pixelHeight, allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex) { VAnchor = VAnchor.Bottom, }; + ActuallNumberEdit.Margin = ActuallNumberEdit.Margin.Clone(left: labelWidth + 2); + var internalWidget = this.ActuallNumberEdit.InternalTextEditWidget; internalWidget.TextColor = theme.EditFieldColors.Inactive.TextColor; internalWidget.FocusChanged += (s, e) => diff --git a/MatterControlLib/SlicerConfiguration/UIFields/Vector2Field.cs b/MatterControlLib/SlicerConfiguration/UIFields/Vector2Field.cs index a9d313f54..80500c651 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/Vector2Field.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/Vector2Field.cs @@ -74,11 +74,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration double.TryParse(xyValueStrings[0], out double currentXValue); - xEditWidget = new MHNumberEdit(currentXValue, theme, allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex) + xEditWidget = new MHNumberEdit(currentXValue, theme, singleCharLabel: 'X', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex) { ToolTipText = this.HelpText, TabIndex = tabIndex, - SelectAllOnFocus = true + SelectAllOnFocus = true, + Margin = theme.ButtonSpacing }; xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) => { @@ -87,16 +88,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration userInitiated: true); }; - container.AddChild(new TextWidget("X:", pointSize: 10, textColor: theme.TextColor) - { - VAnchor = VAnchor.Center, - Margin = new BorderDouble(5, 0), - }); container.AddChild(xEditWidget); double.TryParse(xyValueStrings[1], out double currentYValue); - yEditWidget = new MHNumberEdit(currentYValue, theme, allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex) + yEditWidget = new MHNumberEdit(currentYValue, theme, 'Y', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex) { ToolTipText = this.HelpText, TabIndex = tabIndex + 1, @@ -109,11 +105,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration userInitiated: true); }; - container.AddChild(new TextWidget("Y:", pointSize: 10, textColor: theme.TextColor) - { - VAnchor = VAnchor.Center, - Margin = new BorderDouble(15, 0, 5, 0), - }); container.AddChild(yEditWidget); this.Content = container;