Simplify and unify MHEdit controls
- Issue MatterHackers/MCCentral#2020 Improve control sizing and positions
This commit is contained in:
parent
2ac944f576
commit
4947ac483c
4 changed files with 67 additions and 91 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 4fe2d44bc07300da6d96c49621875734eb3e134f
|
||||
Subproject commit e247cf97823a362f86ff436e282925704fb956e4
|
||||
Loading…
Add table
Add a link
Reference in a new issue