diff --git a/ControlElements/MHNumberEdit.cs b/ControlElements/MHNumberEdit.cs index 7f9b6de75..bd5449fa1 100644 --- a/ControlElements/MHNumberEdit.cs +++ b/ControlElements/MHNumberEdit.cs @@ -34,39 +34,27 @@ namespace MatterHackers.MatterControl { public class MHNumberEdit : GuiWidget { - public NumberEdit ActuallNumberEdit { get; private set; } - - public double Value - { - get { return ActuallNumberEdit.Value; } - set { ActuallNumberEdit.Value = value; } - } + public NumberEdit ActuallNumberEdit { get; } public MHNumberEdit(double startingValue, double x = 0, double y = 0, double pointSize = 12, 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) { - Padding = new BorderDouble(3); + this.Padding = new BorderDouble(3); + this.BackgroundColor = RGBA_Bytes.White; + this.HAnchor = HAnchor.Fit; + this.VAnchor = VAnchor.Fit; - ActuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight, - allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex); - ActuallNumberEdit.VAnchor = Agg.UI.VAnchor.Bottom; - - AddChild(ActuallNumberEdit); - - BackgroundColor = RGBA_Bytes.White; - HAnchor = HAnchor.Fit; - VAnchor = VAnchor.Fit; + this.ActuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight, allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex) + { + VAnchor = VAnchor.Bottom + }; + this.AddChild(this.ActuallNumberEdit); } public override int TabIndex { - get - { - return base.TabIndex; - } - set - { - ActuallNumberEdit.TabIndex = value; - } + // TODO: This looks invalid - setter and getter should use same context + get => base.TabIndex; + set => this.ActuallNumberEdit.TabIndex = value; } public override void OnDraw(Graphics2D graphics2D) @@ -78,22 +66,22 @@ namespace MatterHackers.MatterControl } } + public double Value + { + get => this.ActuallNumberEdit.Value; + set => this.ActuallNumberEdit.Value = value; + } + public override string Text { - get - { - return ActuallNumberEdit.Text; - } - set - { - ActuallNumberEdit.Text = value; - } + get => this.ActuallNumberEdit.Text; + set => this.ActuallNumberEdit.Text = value; } public bool SelectAllOnFocus { - get { return ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus; } - set { ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus = value; } + get => this.ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus; + set => this.ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus = value; } } } \ No newline at end of file diff --git a/ControlElements/MHPasswordTextEditWidget.cs b/ControlElements/MHPasswordTextEditWidget.cs index 947ead699..5aaabbb34 100644 --- a/ControlElements/MHPasswordTextEditWidget.cs +++ b/ControlElements/MHPasswordTextEditWidget.cs @@ -40,30 +40,32 @@ namespace MatterHackers.MatterControl public MHPasswordTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "") : base(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex, messageWhenEmptyAndNotSelected) { - // remove this so that we can have other content first (the hiden letters) - RemoveChild(noContentFieldDescription); + // remove this so that we can have other content first (the hidden letters) + this.RemoveChild(noContentFieldDescription); - passwordCoverText = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine); - passwordCoverText.Selectable = false; - passwordCoverText.HAnchor = Agg.UI.HAnchor.Stretch; - passwordCoverText.MinimumSize = new Vector2(Math.Max(passwordCoverText.MinimumSize.x, pixelWidth), Math.Max(passwordCoverText.MinimumSize.y, pixelHeight)); - passwordCoverText.VAnchor = Agg.UI.VAnchor.Bottom; - AddChild(passwordCoverText); - - actuallTextEditWidget.TextChanged += (sender, e) => + passwordCoverText = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine) { - passwordCoverText.Text = new string('●', actuallTextEditWidget.Text.Length); + Selectable = false, + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Bottom + }; + passwordCoverText.MinimumSize = new Vector2(Math.Max(passwordCoverText.MinimumSize.x, pixelWidth), Math.Max(passwordCoverText.MinimumSize.y, pixelHeight)); + this.AddChild(passwordCoverText); + + this.ActualTextEditWidget.TextChanged += (sender, e) => + { + passwordCoverText.Text = new string('●', this.ActualTextEditWidget.Text.Length); }; // put in back in after the hidden text noContentFieldDescription.ClearRemovedFlag(); - AddChild(noContentFieldDescription); + this.AddChild(noContentFieldDescription); } public bool Hidden { - get { return !passwordCoverText.Visible; } - set { passwordCoverText.Visible = !value; } + get => !passwordCoverText.Visible; + set => passwordCoverText.Visible = !value; } } } \ No newline at end of file diff --git a/ControlElements/MHTextEditWidget.cs b/ControlElements/MHTextEditWidget.cs index 03b331f01..0d47078ca 100644 --- a/ControlElements/MHTextEditWidget.cs +++ b/ControlElements/MHTextEditWidget.cs @@ -37,32 +37,31 @@ namespace MatterHackers.MatterControl { public class MHTextEditWidget : GuiWidget { - protected TextEditWidget actuallTextEditWidget; protected TextWidget noContentFieldDescription = null; - public TextEditWidget ActualTextEditWidget - { - get { return actuallTextEditWidget; } - } + public TextEditWidget ActualTextEditWidget { get; } public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "", TypeFace typeFace = null) { - Padding = new BorderDouble(3); + this.Padding = new BorderDouble(3); + this.BackgroundColor = RGBA_Bytes.White; + this.HAnchor = HAnchor.Fit; + this.VAnchor = VAnchor.Fit; - actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace); - actuallTextEditWidget.HAnchor = HAnchor.Stretch; - actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight)); - actuallTextEditWidget.VAnchor = VAnchor.Bottom; + this.ActualTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace) + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Bottom + }; + this.ActualTextEditWidget.MinimumSize = new Vector2(Math.Max(ActualTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(ActualTextEditWidget.MinimumSize.y, pixelHeight)); + this.AddChild(this.ActualTextEditWidget); - AddChild(actuallTextEditWidget); - BackgroundColor = RGBA_Bytes.White; - HAnchor = HAnchor.Fit; - VAnchor = VAnchor.Fit; + this.AddChild(noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray) + { + VAnchor = VAnchor.Top, + AutoExpandBoundsToText = true + }); - noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray); - noContentFieldDescription.VAnchor = VAnchor.Top; - noContentFieldDescription.AutoExpandBoundsToText = true; - AddChild(noContentFieldDescription); SetNoContentFieldDescriptionVisibility(); } @@ -70,14 +69,7 @@ namespace MatterHackers.MatterControl { if (noContentFieldDescription != null) { - if (Text == "") - { - noContentFieldDescription.Visible = true; - } - else - { - noContentFieldDescription.Visible = false; - } + noContentFieldDescription.Visible = (Text == ""); } } @@ -94,25 +86,14 @@ namespace MatterHackers.MatterControl public override string Text { - get - { - return actuallTextEditWidget.Text; - } - set - { - actuallTextEditWidget.Text = value; - } - } - - public override void Focus() - { - actuallTextEditWidget.Focus(); + get => ActualTextEditWidget.Text; + set => ActualTextEditWidget.Text = value; } public bool SelectAllOnFocus { - get { return actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus; } - set { actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus = value; } + get => ActualTextEditWidget.InternalTextEditWidget.SelectAllOnFocus; + set => ActualTextEditWidget.InternalTextEditWidget.SelectAllOnFocus = value; } public void DrawFromHintedCache() @@ -120,5 +101,10 @@ namespace MatterHackers.MatterControl ActualTextEditWidget.Printer.DrawFromHintedCache = true; ActualTextEditWidget.DoubleBuffer = false; } + + public override void Focus() + { + ActualTextEditWidget.Focus(); + } } } \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 4fe2d44bc..e247cf978 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 4fe2d44bc07300da6d96c49621875734eb3e134f +Subproject commit e247cf97823a362f86ff436e282925704fb956e4