adding read only property display

This commit is contained in:
LarsBrubaker 2019-11-26 19:47:05 -08:00
parent bddcdba380
commit eaebe4ed4c
2 changed files with 28 additions and 16 deletions

View file

@ -307,27 +307,39 @@ namespace MatterHackers.MatterControl.DesignTools
// create a double editor
if (propertyValue is double doubleValue)
{
var field = new DoubleField(theme);
field.Initialize(0);
field.DoubleValue = doubleValue;
RegisterValueChanged(field, (valueString) => { return double.Parse(valueString); });
void RefreshField(object s, InvalidateArgs e)
var readOnly = property.PropertyInfo.GetCustomAttributes(true).OfType<ReadOnlyAttribute>().FirstOrDefault() != null;
if (readOnly)
{
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
var valueField = new TextWidget(doubleValue.ToString("0.##"), textColor: theme.TextColor, pointSize: 10);
rowContainer = new SettingsRow(property.DisplayName.Localize(),
property.Description.Localize(),
valueField,
theme);
}
else // normal edit row
{
var field = new DoubleField(theme);
field.Initialize(0);
field.DoubleValue = doubleValue;
RegisterValueChanged(field, (valueString) => { return double.Parse(valueString); });
void RefreshField(object s, InvalidateArgs e)
{
double newValue = (double)property.Value;
if (newValue != field.DoubleValue)
if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues))
{
field.DoubleValue = newValue;
double newValue = (double)property.Value;
if (newValue != field.DoubleValue)
{
field.DoubleValue = newValue;
}
}
}
object3D.Invalidated += RefreshField;
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
rowContainer = CreateSettingsRow(property, field, theme);
}
object3D.Invalidated += RefreshField;
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
rowContainer = CreateSettingsRow(property, field, theme);
}
else if (propertyValue is Color color)
{

View file

@ -132,7 +132,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
public SettingsRow(string title, string helpText, GuiWidget guiWidget, ThemeConfig theme)
: this (title, helpText, theme)
: this(title, helpText, theme)
{
this.Padding = new BorderDouble(right: theme.DefaultContainerPadding);