2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2016-08-10 15:18:03 -07:00
|
|
|
|
using MatterHackers.Agg.Font;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Diagnostics;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class MHTextEditWidget : GuiWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
protected TextEditWidget actuallTextEditWidget;
|
|
|
|
|
|
protected TextWidget noContentFieldDescription = null;
|
|
|
|
|
|
|
|
|
|
|
|
public TextEditWidget ActualTextEditWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return actuallTextEditWidget; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-10 15:18:03 -07:00
|
|
|
|
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)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
Padding = new BorderDouble(3);
|
2016-08-10 15:18:03 -07:00
|
|
|
|
actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace);
|
2017-08-07 15:47:27 -07:00
|
|
|
|
actuallTextEditWidget.HAnchor = Agg.UI.HAnchor.Stretch;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight));
|
2017-08-07 15:47:27 -07:00
|
|
|
|
actuallTextEditWidget.VAnchor = Agg.UI.VAnchor.Bottom;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(actuallTextEditWidget);
|
|
|
|
|
|
BackgroundColor = RGBA_Bytes.White;
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Fit;
|
|
|
|
|
|
VAnchor = VAnchor.Fit;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
|
2017-08-31 15:52:27 -07:00
|
|
|
|
noContentFieldDescription.VAnchor = VAnchor.Top;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
noContentFieldDescription.AutoExpandBoundsToText = true;
|
|
|
|
|
|
AddChild(noContentFieldDescription);
|
|
|
|
|
|
SetNoContentFieldDescriptionVisibility();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetNoContentFieldDescriptionVisibility()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (noContentFieldDescription != null)
|
|
|
|
|
|
{
|
2015-07-27 19:03:54 -07:00
|
|
|
|
if (Text == "")
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
noContentFieldDescription.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
noContentFieldDescription.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetNoContentFieldDescriptionVisibility();
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
|
|
|
|
|
|
if (ContainsFocus)
|
|
|
|
|
|
{
|
|
|
|
|
|
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return actuallTextEditWidget.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
actuallTextEditWidget.Text = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-29 16:31:24 -07:00
|
|
|
|
public override void Focus()
|
2015-07-22 18:30:22 -07:00
|
|
|
|
{
|
2015-07-29 16:31:24 -07:00
|
|
|
|
actuallTextEditWidget.Focus();
|
2015-07-22 18:30:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public bool SelectAllOnFocus
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus; }
|
|
|
|
|
|
set { actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus = value; }
|
|
|
|
|
|
}
|
2016-12-03 12:48:19 -08:00
|
|
|
|
|
|
|
|
|
|
public void DrawFromHintedCache()
|
|
|
|
|
|
{
|
|
|
|
|
|
ActualTextEditWidget.Printer.DrawFromHintedCache = true;
|
|
|
|
|
|
ActualTextEditWidget.DoubleBuffer = false;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MHPasswordTextEditWidget : MHTextEditWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private TextEditWidget passwordCoverText;
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2015-07-07 10:09:35 -07:00
|
|
|
|
// remove this so that we can have other content first (the hiden letters)
|
|
|
|
|
|
RemoveChild(noContentFieldDescription);
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
passwordCoverText = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine);
|
|
|
|
|
|
passwordCoverText.Selectable = false;
|
2017-08-07 15:47:27 -07:00
|
|
|
|
passwordCoverText.HAnchor = Agg.UI.HAnchor.Stretch;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
passwordCoverText.MinimumSize = new Vector2(Math.Max(passwordCoverText.MinimumSize.x, pixelWidth), Math.Max(passwordCoverText.MinimumSize.y, pixelHeight));
|
2017-08-07 15:47:27 -07:00
|
|
|
|
passwordCoverText.VAnchor = Agg.UI.VAnchor.Bottom;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(passwordCoverText);
|
|
|
|
|
|
|
|
|
|
|
|
actuallTextEditWidget.TextChanged += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
passwordCoverText.Text = new string('●', actuallTextEditWidget.Text.Length);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2015-07-07 10:09:35 -07:00
|
|
|
|
// put in back in after the hidden text
|
|
|
|
|
|
noContentFieldDescription.ClearRemovedFlag();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(noContentFieldDescription);
|
|
|
|
|
|
}
|
2017-01-30 11:22:18 -08:00
|
|
|
|
|
|
|
|
|
|
public bool Hidden
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return !passwordCoverText.Visible; }
|
|
|
|
|
|
set { passwordCoverText.Visible = !value; }
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MHNumberEdit : GuiWidget
|
|
|
|
|
|
{
|
2017-06-26 15:42:42 -07:00
|
|
|
|
public NumberEdit ActuallNumberEdit { get; private set; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-06-26 15:42:42 -07:00
|
|
|
|
public double Value
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-26 15:42:42 -07:00
|
|
|
|
get { return ActuallNumberEdit.Value; }
|
|
|
|
|
|
set { ActuallNumberEdit.Value = value; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2017-06-26 15:42:42 -07:00
|
|
|
|
ActuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight,
|
2015-04-08 15:20:10 -07:00
|
|
|
|
allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex);
|
2017-08-07 15:47:27 -07:00
|
|
|
|
ActuallNumberEdit.VAnchor = Agg.UI.VAnchor.Bottom;
|
2017-06-26 15:42:42 -07:00
|
|
|
|
AddChild(ActuallNumberEdit);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
BackgroundColor = RGBA_Bytes.White;
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Fit;
|
|
|
|
|
|
VAnchor = VAnchor.Fit;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int TabIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return base.TabIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2017-06-26 15:42:42 -07:00
|
|
|
|
ActuallNumberEdit.TabIndex = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
if (ContainsFocus)
|
|
|
|
|
|
{
|
|
|
|
|
|
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Text
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2017-06-26 15:42:42 -07:00
|
|
|
|
return ActuallNumberEdit.Text;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2017-06-26 15:42:42 -07:00
|
|
|
|
ActuallNumberEdit.Text = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SelectAllOnFocus
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus; }
|
|
|
|
|
|
set { ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|