From eaebe4ed4c2a41dfd76cc27a9b67d77e5e211b91 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Tue, 26 Nov 2019 19:47:05 -0800 Subject: [PATCH] adding read only property display --- .../DesignTools/PublicPropertyEditor.cs | 42 ++++++++++++------- .../SlicerConfiguration/SettingsRow.cs | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/MatterControlLib/DesignTools/PublicPropertyEditor.cs b/MatterControlLib/DesignTools/PublicPropertyEditor.cs index 3322c1393..95f87cf3c 100644 --- a/MatterControlLib/DesignTools/PublicPropertyEditor.cs +++ b/MatterControlLib/DesignTools/PublicPropertyEditor.cs @@ -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().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) { diff --git a/MatterControlLib/SlicerConfiguration/SettingsRow.cs b/MatterControlLib/SlicerConfiguration/SettingsRow.cs index b8e874edf..46490a943 100644 --- a/MatterControlLib/SlicerConfiguration/SettingsRow.cs +++ b/MatterControlLib/SlicerConfiguration/SettingsRow.cs @@ -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);