Convert common types to UIField
- Investigate feasibility of NumberField, TextField, CheckboxField, etc...
This commit is contained in:
parent
0b5148067b
commit
e5c7802e90
11 changed files with 364 additions and 329 deletions
|
|
@ -32,7 +32,44 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class IntOrMmField : ISettingsField
|
||||
//IntOrMmField
|
||||
|
||||
public class ValueOrUnitsField : TextField
|
||||
{
|
||||
protected string unitsToken = "mm";
|
||||
|
||||
public override void Initialize(int tabIndex)
|
||||
{
|
||||
base.Initialize(tabIndex);
|
||||
|
||||
textEditWidget.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (s, e) =>
|
||||
{
|
||||
// select everything up to the token (if present)
|
||||
int tokenIndex = textEditWidget.ActualTextEditWidget.Text.IndexOf(unitsToken);
|
||||
if (tokenIndex != -1)
|
||||
{
|
||||
textEditWidget.ActualTextEditWidget.InternalTextEditWidget.SetSelection(0, tokenIndex - 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
string text = newValue.Trim();
|
||||
|
||||
int tokenIndex = text.IndexOf(unitsToken);
|
||||
bool hasUnitsToken = tokenIndex != -1;
|
||||
if (hasUnitsToken)
|
||||
{
|
||||
text = text.Substring(0, tokenIndex);
|
||||
}
|
||||
|
||||
double.TryParse(text, out double currentValue);
|
||||
return currentValue + (hasUnitsToken ? unitsToken : "");
|
||||
}
|
||||
}
|
||||
|
||||
public class IntOrMmField2 : ISettingsField
|
||||
{
|
||||
private MHTextEditWidget editWidget;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue