Add support for themed text/number edit fields

This commit is contained in:
John Lewin 2018-10-14 20:05:37 -07:00
parent 151e753db2
commit 34708054ee
44 changed files with 598 additions and 108 deletions

View file

@ -34,22 +34,32 @@ namespace MatterHackers.MatterControl
{
public class MHNumberEdit : GuiWidget
{
private ThemeConfig theme;
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)
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)
{
using (this.LayoutLock())
{
this.Padding = new BorderDouble(3);
this.BackgroundColor = Color.White;
this.Padding = 3;
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
this.Border = 1;
this.theme = theme;
this.ActuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight, allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex)
this.ActuallNumberEdit = new NumberEdit(startingValue, 0, 0, theme.DefaultFontSize, pixelWidth, pixelHeight, allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex)
{
VAnchor = VAnchor.Bottom,
};
var internalWidget = this.ActuallNumberEdit.InternalTextEditWidget;
internalWidget.TextColor = theme.EditFieldColors.Inactive.TextColor;
internalWidget.FocusChanged += (s, e) =>
{
internalWidget.TextColor = (internalWidget.Focused) ? theme.EditFieldColors.Focused.TextColor : theme.EditFieldColors.Inactive.TextColor;
};
this.ActuallNumberEdit.InternalNumberEdit.MaxDecimalsPlaces = 5;
this.AddChild(this.ActuallNumberEdit);
}
@ -57,6 +67,48 @@ namespace MatterHackers.MatterControl
this.PerformLayout();
}
public override Color BackgroundColor
{
get
{
if (base.BackgroundColor != Color.Transparent)
{
return base.BackgroundColor;
}
else if (this.ContainsFocus)
{
return theme.EditFieldColors.Focused.BackgroundColor;
}
else if (this.mouseInBounds)
{
return theme.EditFieldColors.Hovered.BackgroundColor;
}
else
{
return theme.EditFieldColors.Inactive.BackgroundColor;
}
}
set => base.BackgroundColor = value;
}
private bool mouseInBounds = false;
public override void OnMouseEnterBounds(MouseEventArgs mouseEvent)
{
mouseInBounds = true;
base.OnMouseEnterBounds(mouseEvent);
this.Invalidate();
}
public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent)
{
mouseInBounds = false;
base.OnMouseLeaveBounds(mouseEvent);
this.Invalidate();
}
public override int TabIndex
{
// TODO: This looks invalid - setter and getter should use same context