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
|
|
@ -292,6 +292,7 @@
|
|||
<Compile Include="SetupWizard\SetupWizardTroubleshooting.cs" />
|
||||
<Compile Include="SetupWizard\SetupWizardWifi.cs" />
|
||||
<Compile Include="SetupWizard\WizardWindow.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\BasicField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\DoubleField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\DoubleOrPercentField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\IntOrMmField.cs" />
|
||||
|
|
@ -303,7 +304,6 @@
|
|||
<Compile Include="SlicerConfiguration\UIFields\Offset2Field.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\Vector2Field.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\StringField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\OffsetField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\IntField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\PositiveDoubleField.cs" />
|
||||
<Compile Include="SlicerConfiguration\SettingsContext.cs" />
|
||||
|
|
|
|||
|
|
@ -786,7 +786,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
settingsRow.AddChild(restoreArea);
|
||||
settingsRow.Name = settingData.SlicerConfigName + " Edit Field";
|
||||
|
||||
ISettingsField field = null;
|
||||
ISettingsField OLDFIELDXXXXX = null;
|
||||
IUIField uiField = null;
|
||||
|
||||
if (!PrinterSettings.KnownSettings.Contains(settingData.SlicerConfigName))
|
||||
|
|
@ -810,60 +810,73 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
switch (settingData.DataEditType)
|
||||
{
|
||||
case SliceSettingData.DataEditTypes.INT:
|
||||
|
||||
uiField = new NumberField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.DOUBLE:
|
||||
field = new DoubleField();
|
||||
case SliceSettingData.DataEditTypes.OFFSET:
|
||||
uiField = new DoubleField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.POSITIVE_DOUBLE:
|
||||
field = new PositiveDoubleField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.OFFSET:
|
||||
field = new OffsetField();
|
||||
OLDFIELDXXXXX = new PositiveDoubleField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.DOUBLE_OR_PERCENT:
|
||||
field = new DoubleOrPercentField();
|
||||
uiField = new DoubleOrPercentField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.INT_OR_MM:
|
||||
field = new IntOrMmField();
|
||||
uiField = new ValueOrUnitsField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.CHECK_BOX:
|
||||
field = new CheckboxField();
|
||||
uiField = new CheckboxField();
|
||||
uiField.ValueChanged += (s, e) =>
|
||||
{
|
||||
// Linked settings should be updated in all cases (user clicked checkbox, user clicked clear)
|
||||
foreach (var setSettingsData in settingData.SetSettingsOnChange)
|
||||
{
|
||||
string targetValue;
|
||||
|
||||
if (uiField.Content is CheckBox checkbox)
|
||||
{
|
||||
if (setSettingsData.TryGetValue(checkbox.Checked ? "OnValue" : "OffValue", out targetValue))
|
||||
{
|
||||
settingsContext.SetValue(setSettingsData["TargetSetting"], targetValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.STRING:
|
||||
field = new StringField();
|
||||
uiField = new TextField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.MULTI_LINE_TEXT:
|
||||
field = new MultilineStringField();
|
||||
OLDFIELDXXXXX = new MultilineStringField();
|
||||
break;
|
||||
case SliceSettingData.DataEditTypes.COM_PORT:
|
||||
field = new ComPortField();
|
||||
OLDFIELDXXXXX = new ComPortField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.LIST:
|
||||
field = new ListField();
|
||||
OLDFIELDXXXXX = new ListField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.HARDWARE_PRESENT:
|
||||
field = new HardwarePresetField();
|
||||
OLDFIELDXXXXX = new HardwarePresetField();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.VECTOR2:
|
||||
field = new Vector2Field();
|
||||
OLDFIELDXXXXX = new Vector2Field();
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.OFFSET2:
|
||||
field = new Offset2Field();
|
||||
if (field is Offset2Field offset2)
|
||||
OLDFIELDXXXXX = new Offset2Field();
|
||||
if (OLDFIELDXXXXX is Offset2Field offset2)
|
||||
{
|
||||
offset2.ExtruderIndex = extruderIndex;
|
||||
}
|
||||
|
|
@ -974,19 +987,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
};
|
||||
|
||||
if (field != null)
|
||||
if (OLDFIELDXXXXX != null)
|
||||
{
|
||||
allFields.Add(settingData.SlicerConfigName, field);
|
||||
allFields.Add(settingData.SlicerConfigName, OLDFIELDXXXXX);
|
||||
|
||||
field.Value = sliceSettingValue;
|
||||
OLDFIELDXXXXX.Value = sliceSettingValue;
|
||||
|
||||
this.PrepareRow(
|
||||
field.Create(settingsContext, settingData, tabIndexForItem++),
|
||||
OLDFIELDXXXXX.Create(settingsContext, settingData, tabIndexForItem++),
|
||||
dataArea,
|
||||
unitsArea,
|
||||
settingData);
|
||||
|
||||
field.UpdateStyle = settingsRow.UpdateStyle;
|
||||
OLDFIELDXXXXX.UpdateStyle = settingsRow.UpdateStyle;
|
||||
}
|
||||
|
||||
if (uiField != null)
|
||||
|
|
@ -997,6 +1010,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
uiField.Value = sliceSettingValue;
|
||||
|
||||
uiField.ValueChanged += (s, e) =>
|
||||
{
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
|
||||
settingsRow.UpdateStyle();
|
||||
};
|
||||
|
||||
// After initializing the field, wrap with dropmenu if applicable
|
||||
if (settingData.QuickMenuSettings.Count > 0)
|
||||
{
|
||||
|
|
@ -1010,11 +1029,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
unitsArea,
|
||||
settingData);
|
||||
|
||||
uiField.ValueChanged += (s, e) =>
|
||||
{
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, uiField.Value);
|
||||
settingsRow.UpdateStyle();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
234
SlicerConfiguration/UIFields/BasicField.cs
Normal file
234
SlicerConfiguration/UIFields/BasicField.cs
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class BasicField
|
||||
{
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
private string fieldValue;
|
||||
public string Value
|
||||
{
|
||||
get => fieldValue;
|
||||
set
|
||||
{
|
||||
string convertedValue = this.ConvertValue(value);
|
||||
|
||||
if (fieldValue != convertedValue)
|
||||
{
|
||||
fieldValue = convertedValue;
|
||||
this.OnValueChanged();
|
||||
}
|
||||
else if (value != convertedValue)
|
||||
{
|
||||
// If the validated value matches the current value, then UI element values were rejected and must be discarded
|
||||
this.OnValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuiWidget Content { get; protected set; }
|
||||
|
||||
public string HelpText { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
protected virtual string ConvertValue(string newValue)
|
||||
{
|
||||
return newValue;
|
||||
}
|
||||
|
||||
protected virtual void OnValueChanged()
|
||||
{
|
||||
ValueChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
public class NumberField : BasicField, IUIField
|
||||
{
|
||||
protected MHNumberEdit numberEdit;
|
||||
|
||||
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
|
||||
public virtual void Initialize(int tabIndex)
|
||||
{
|
||||
numberEdit = new MHNumberEdit(0, pixelWidth: ControlWidth, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = this.HelpText,
|
||||
SelectAllOnFocus = true,
|
||||
Name = this.Name,
|
||||
};
|
||||
numberEdit.ActuallNumberEdit.EditComplete += (s, e) =>
|
||||
{
|
||||
if (this.Value != numberEdit.Value.ToString())
|
||||
{
|
||||
this.Value = numberEdit.Value.ToString();
|
||||
}
|
||||
};
|
||||
|
||||
numberEdit.ActuallNumberEdit.BackgroundColor = RGBA_Bytes.Blue;
|
||||
|
||||
this.Content = numberEdit;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
int.TryParse(this.Value, out int currentValue);
|
||||
numberEdit.ActuallNumberEdit.Value = currentValue;
|
||||
|
||||
base.OnValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public class TextField : BasicField, IUIField
|
||||
{
|
||||
protected MHTextEditWidget textEditWidget;
|
||||
|
||||
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
|
||||
public virtual void Initialize(int tabIndex)
|
||||
{
|
||||
textEditWidget = new MHTextEditWidget("", pixelWidth: ControlWidth, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = this.HelpText,
|
||||
SelectAllOnFocus = true,
|
||||
Name = this.Name,
|
||||
};
|
||||
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
|
||||
{
|
||||
if (this.Value != textEditWidget.Text)
|
||||
{
|
||||
this.Value = textEditWidget.Text;
|
||||
}
|
||||
};
|
||||
|
||||
textEditWidget.ActualTextEditWidget.BackgroundColor = RGBA_Bytes.Yellow;
|
||||
|
||||
this.Content = textEditWidget;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
if (this.Value != textEditWidget.Text)
|
||||
{
|
||||
textEditWidget.Text = this.Value;
|
||||
}
|
||||
|
||||
base.OnValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public class DropMenuWrappedField : IUIField
|
||||
{
|
||||
private IUIField uiField;
|
||||
private SliceSettingData settingData;
|
||||
|
||||
public DropMenuWrappedField(IUIField uiField, SliceSettingData settingData)
|
||||
{
|
||||
this.settingData = settingData;
|
||||
this.uiField = uiField;
|
||||
}
|
||||
|
||||
public string Value { get => uiField.Value; set => uiField.Value = value; }
|
||||
|
||||
public GuiWidget Content { get; private set; }
|
||||
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
public void Initialize(int tabIndex)
|
||||
{
|
||||
var totalContent = new FlowLayoutWidget();
|
||||
|
||||
var selectableOptions = new DropDownList("Custom", maxHeight: 200);
|
||||
selectableOptions.Margin = new BorderDouble(0, 0, 10, 0);
|
||||
|
||||
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
|
||||
{
|
||||
string valueLocal = nameValue.Value;
|
||||
|
||||
MenuItem newItem = selectableOptions.AddItem(nameValue.MenuName);
|
||||
if (uiField.Value == valueLocal)
|
||||
{
|
||||
selectableOptions.SelectedLabel = nameValue.MenuName;
|
||||
}
|
||||
|
||||
newItem.Selected += (s, e) =>
|
||||
{
|
||||
uiField.Value = valueLocal;
|
||||
};
|
||||
}
|
||||
|
||||
totalContent.AddChild(selectableOptions);
|
||||
|
||||
uiField.Content.VAnchor = VAnchor.Center;
|
||||
totalContent.AddChild(uiField.Content);
|
||||
|
||||
EventHandler localUnregisterEvents = null;
|
||||
|
||||
ActiveSliceSettings.SettingChanged.RegisterEvent((sender, e) =>
|
||||
{
|
||||
if (e is StringEventArgs stringArgs
|
||||
&& stringArgs.Data == settingData.SlicerConfigName)
|
||||
{
|
||||
bool foundSetting = false;
|
||||
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
|
||||
{
|
||||
string localName = nameValue.MenuName;
|
||||
string newSliceSettingValue = uiField.Value;
|
||||
if (newSliceSettingValue == nameValue.Value)
|
||||
{
|
||||
selectableOptions.SelectedLabel = localName;
|
||||
foundSetting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSetting)
|
||||
{
|
||||
selectableOptions.SelectedLabel = "Custom";
|
||||
}
|
||||
}
|
||||
}, ref localUnregisterEvents);
|
||||
|
||||
totalContent.Closed += (s, e) =>
|
||||
{
|
||||
localUnregisterEvents?.Invoke(s, null);
|
||||
};
|
||||
|
||||
totalContent.DebugShowBounds = true;
|
||||
|
||||
this.Content = totalContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,35 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class CheckboxField : ISettingsField
|
||||
public class CheckboxField : BasicField, IUIField
|
||||
{
|
||||
private CheckBox checkBoxWidget;
|
||||
|
||||
public virtual void Initialize(int tabIndex)
|
||||
{
|
||||
checkBoxWidget = new CheckBox("")
|
||||
{
|
||||
//Name = settingData.PresentationName + " Checkbox",
|
||||
//ToolTipText = settingData.HelpText,
|
||||
VAnchor = VAnchor.Bottom,
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
Checked = this.Value == "1"
|
||||
};
|
||||
checkBoxWidget.CheckedStateChanged += (s, e) =>
|
||||
{
|
||||
this.Value = checkBoxWidget.Checked ? "1" : "0";
|
||||
};
|
||||
|
||||
this.Content = checkBoxWidget;
|
||||
}
|
||||
|
||||
public void OnValueChanged(string text)
|
||||
{
|
||||
checkBoxWidget.Checked = text == "1";
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckboxField2 : ISettingsField
|
||||
{
|
||||
private CheckBox checkBoxWidget;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,38 +32,14 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class DoubleField : ISettingsField
|
||||
public class DoubleField : NumberField
|
||||
{
|
||||
public static int DoubleEditWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
|
||||
public Action UpdateStyle { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
private MHNumberEdit doubleEditWidget;
|
||||
|
||||
public GuiWidget Create(SettingsContext settingsContext, SliceSettingData settingData, int tabIndex)
|
||||
{
|
||||
double.TryParse(this.Value, out double currentValue);
|
||||
|
||||
doubleEditWidget = new MHNumberEdit(currentValue, allowNegatives: true, allowDecimals: true, pixelWidth: DoubleEditWidth, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = settingData.HelpText,
|
||||
SelectAllOnFocus = true
|
||||
};
|
||||
doubleEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
||||
{
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
|
||||
this.UpdateStyle();
|
||||
};
|
||||
|
||||
return doubleEditWidget;
|
||||
}
|
||||
|
||||
public void OnValueChanged(string text)
|
||||
{
|
||||
double.TryParse(text, out double currentValue);
|
||||
doubleEditWidget.ActuallNumberEdit.Value = currentValue;
|
||||
numberEdit.ActuallNumberEdit.Value = currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,68 +32,26 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class DoubleOrPercentField : ISettingsField
|
||||
public class DoubleOrPercentField : ValueOrUnitsField
|
||||
{
|
||||
public Action UpdateStyle { get; set; }
|
||||
|
||||
private MHTextEditWidget editWidget;
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public GuiWidget Create(SettingsContext settingsContext, SliceSettingData settingData, int tabIndex)
|
||||
public DoubleOrPercentField()
|
||||
{
|
||||
editWidget = new MHTextEditWidget(this.Value, pixelWidth: DoubleField.DoubleEditWidth - 2, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = settingData.HelpText,
|
||||
SelectAllOnFocus = true
|
||||
};
|
||||
editWidget.ActualTextEditWidget.EditComplete += (sender, e) =>
|
||||
{
|
||||
var textEditWidget = (TextEditWidget)sender;
|
||||
string text = textEditWidget.Text.Trim();
|
||||
|
||||
bool isPercent = text.Contains("%");
|
||||
if (isPercent)
|
||||
{
|
||||
text = text.Substring(0, text.IndexOf("%"));
|
||||
}
|
||||
double result;
|
||||
double.TryParse(text, out result);
|
||||
text = result.ToString();
|
||||
if (isPercent)
|
||||
{
|
||||
text += "%";
|
||||
}
|
||||
textEditWidget.Text = text;
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, textEditWidget.Text);
|
||||
|
||||
this.UpdateStyle();
|
||||
};
|
||||
|
||||
editWidget.ActualTextEditWidget.InternalTextEditWidget.AllSelected += (sender, e) =>
|
||||
{
|
||||
// select everything up to the % (if present)
|
||||
InternalTextEditWidget textEditWidget = (InternalTextEditWidget)sender;
|
||||
int percentIndex = textEditWidget.Text.IndexOf("%");
|
||||
if (percentIndex != -1)
|
||||
{
|
||||
textEditWidget.SetSelection(0, percentIndex - 1);
|
||||
}
|
||||
};
|
||||
|
||||
if (settingData.QuickMenuSettings.Count > 0)
|
||||
{
|
||||
return SliceSettingsWidget.CreateQuickMenu(settingData, settingsContext, editWidget, editWidget.ActualTextEditWidget.InternalTextEditWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
return editWidget;
|
||||
}
|
||||
unitsToken = "%";
|
||||
}
|
||||
|
||||
public void OnValueChanged(string text)
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
editWidget.Text = text;
|
||||
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 : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,151 +33,7 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class BasicField
|
||||
{
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
private string fieldValue;
|
||||
public string Value
|
||||
{
|
||||
get => fieldValue;
|
||||
set
|
||||
{
|
||||
if (fieldValue != value)
|
||||
{
|
||||
fieldValue = value;
|
||||
this.OnValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuiWidget Content { get; protected set; }
|
||||
|
||||
public string HelpText { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
protected virtual void OnValueChanged()
|
||||
{
|
||||
ValueChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
public class NumberField : BasicField, IUIField
|
||||
{
|
||||
protected MHNumberEdit numberEdit;
|
||||
|
||||
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
|
||||
public void Initialize(int tabIndex)
|
||||
{
|
||||
numberEdit = new MHNumberEdit(0, pixelWidth: ControlWidth, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = this.HelpText,
|
||||
SelectAllOnFocus = true,
|
||||
Name = this.Name,
|
||||
};
|
||||
numberEdit.ActuallNumberEdit.EditComplete += (s, e) =>
|
||||
{
|
||||
if (this.Value != numberEdit.Value.ToString())
|
||||
{
|
||||
this.Value = numberEdit.Value.ToString();
|
||||
}
|
||||
};
|
||||
|
||||
this.Content = numberEdit;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
int.TryParse(this.Value, out int currentValue);
|
||||
numberEdit.ActuallNumberEdit.Value = currentValue;
|
||||
|
||||
base.OnValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public class DropMenuWrappedField : IUIField
|
||||
{
|
||||
private IUIField uiField;
|
||||
private SliceSettingData settingData;
|
||||
|
||||
public DropMenuWrappedField(IUIField uiField, SliceSettingData settingData)
|
||||
{
|
||||
this.settingData = settingData;
|
||||
this.uiField = uiField;
|
||||
}
|
||||
|
||||
public string Value { get => uiField.Value; set => uiField.Value = value; }
|
||||
|
||||
public GuiWidget Content { get; private set; }
|
||||
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
public void Initialize(int tabIndex)
|
||||
{
|
||||
var totalContent = new FlowLayoutWidget();
|
||||
|
||||
var selectableOptions = new DropDownList("Custom", maxHeight: 200);
|
||||
selectableOptions.Margin = new BorderDouble(0, 0, 10, 0);
|
||||
|
||||
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
|
||||
{
|
||||
string valueLocal = nameValue.Value;
|
||||
|
||||
MenuItem newItem = selectableOptions.AddItem(nameValue.MenuName);
|
||||
if (uiField.Value == valueLocal)
|
||||
{
|
||||
selectableOptions.SelectedLabel = nameValue.MenuName;
|
||||
}
|
||||
|
||||
newItem.Selected += (s, e) =>
|
||||
{
|
||||
uiField.Value = valueLocal;
|
||||
};
|
||||
}
|
||||
|
||||
totalContent.AddChild(selectableOptions);
|
||||
|
||||
uiField.Content.VAnchor = VAnchor.Center;
|
||||
totalContent.AddChild(uiField.Content);
|
||||
|
||||
EventHandler localUnregisterEvents = null;
|
||||
|
||||
ActiveSliceSettings.SettingChanged.RegisterEvent((sender, e) =>
|
||||
{
|
||||
if (e is StringEventArgs stringArgs
|
||||
&& stringArgs.Data == settingData.SlicerConfigName)
|
||||
{
|
||||
bool foundSetting = false;
|
||||
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
|
||||
{
|
||||
string localName = nameValue.MenuName;
|
||||
string newSliceSettingValue = uiField.Value;
|
||||
if (newSliceSettingValue == nameValue.Value)
|
||||
{
|
||||
selectableOptions.SelectedLabel = localName;
|
||||
foundSetting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSetting)
|
||||
{
|
||||
selectableOptions.SelectedLabel = "Custom";
|
||||
}
|
||||
}
|
||||
}, ref localUnregisterEvents);
|
||||
|
||||
totalContent.Closed += (s, e) =>
|
||||
{
|
||||
localUnregisterEvents?.Invoke(s, null);
|
||||
};
|
||||
|
||||
this.Content = totalContent;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public class IntField : NumberField, ISettingsField
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class OffsetField : ISettingsField
|
||||
{
|
||||
private MHNumberEdit editWidget;
|
||||
|
||||
public Action UpdateStyle { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public GuiWidget Create(SettingsContext settingsContext, SliceSettingData settingData, int tabIndex)
|
||||
{
|
||||
double.TryParse(this.Value, out double currentValue);
|
||||
|
||||
editWidget = new MHNumberEdit(currentValue, allowDecimals: true, allowNegatives: true, pixelWidth: DoubleField.DoubleEditWidth, tabIndex: tabIndex)
|
||||
{
|
||||
ToolTipText = settingData.HelpText,
|
||||
SelectAllOnFocus = true
|
||||
|
||||
};
|
||||
editWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
||||
{
|
||||
settingsContext.SetValue(settingData.SlicerConfigName, ((NumberEdit)sender).Value.ToString());
|
||||
this.UpdateStyle();
|
||||
};
|
||||
|
||||
return editWidget;
|
||||
}
|
||||
|
||||
public void OnValueChanged(string text)
|
||||
{
|
||||
double.TryParse(text, out double currentValue);
|
||||
editWidget.ActuallNumberEdit.Value = currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
settingsContext.SetValue(settingData.SlicerConfigName, numberEdit.Value.ToString());
|
||||
this.UpdateStyle();
|
||||
};
|
||||
|
||||
|
||||
if (settingData.QuickMenuSettings.Count > 0)
|
||||
{
|
||||
return SliceSettingsWidget.CreateQuickMenu(settingData, settingsContext, doubleEditWidget, doubleEditWidget.ActuallNumberEdit.InternalTextEditWidget);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit e7d56c39bf93ffd0423b31b12cfb13f2bb267b2f
|
||||
Subproject commit 9d31357530977b2fb0a8371af64df276d8245d26
|
||||
Loading…
Add table
Add a link
Reference in a new issue