Putting in property slider
This commit is contained in:
parent
a59244a0bb
commit
f30ee46270
5 changed files with 88 additions and 28 deletions
|
|
@ -74,7 +74,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
/// </summary>
|
||||
[DisplayName("")]
|
||||
[JsonIgnore]
|
||||
[ImageDisplay(Margin = new int[] { 30, 3, 30, 3 }, MaxXSize = 400, Stretch = true)]
|
||||
[ImageDisplay(Margin = new int[] { 9, 3, 9, 3 }, MaxXSize = 400, Stretch = true)]
|
||||
public ImageBuffer Image
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
/// This is the actual serialized with that can use expressions
|
||||
/// </summary>
|
||||
[MaxDecimalPlaces(2)]
|
||||
[Slider(1, 100, 1)]
|
||||
public DoubleOrExpression Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
[DisplayName("")]
|
||||
[JsonIgnore]
|
||||
[ImageDisplay(Margin = new int[] { 30, 3, 30, 3 }, MaxXSize = 400, Stretch = true)]
|
||||
[ImageDisplay(Margin = new int[] { 9, 3, 9, 3 }, MaxXSize = 400, Stretch = true)]
|
||||
public ImageBuffer Image
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -211,9 +211,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
}
|
||||
|
||||
private static SettingsRow CreateSettingsRow(EditableProperty property, UIField field, ThemeConfig theme, List<SettingsRow> rows = null)
|
||||
private static SettingsRow CreateSettingsRow(EditableProperty property, GuiWidget content, ThemeConfig theme, List<SettingsRow> rows = null)
|
||||
{
|
||||
var row = new SettingsRow(property.DisplayName.Localize(), property.Description, field.Content, theme);
|
||||
var row = new SettingsRow(property.DisplayName.Localize(), property.Description, content, theme);
|
||||
if (rows != null)
|
||||
{
|
||||
rows.Add(row);
|
||||
|
|
@ -263,11 +263,14 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
ToolTipText = toolTipText
|
||||
};
|
||||
|
||||
var label = SettingsRow.CreateSettingsLabel(labelText, toolTipText, theme.TextColor);
|
||||
label.VAnchor = VAnchor.Absolute;
|
||||
label.HAnchor = HAnchor.Left;
|
||||
if (!string.IsNullOrEmpty(labelText))
|
||||
{
|
||||
var label = SettingsRow.CreateSettingsLabel(labelText, toolTipText, theme.TextColor);
|
||||
label.VAnchor = VAnchor.Absolute;
|
||||
label.HAnchor = HAnchor.Left;
|
||||
|
||||
column.AddChild(label);
|
||||
column.AddChild(label);
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
|
@ -292,6 +295,55 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
.Select(p => new EditableProperty(p, item));
|
||||
}
|
||||
|
||||
public static GuiWidget GetFieldContentWithSlider(EditableProperty property, UIField field)
|
||||
{
|
||||
var sliderAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<SliderAttribute>().FirstOrDefault();
|
||||
if (sliderAttribute != null)
|
||||
{
|
||||
var slider = new Slider(new Vector2(0, 0), 60 * GuiWidget.DeviceScale, sliderAttribute.Min, sliderAttribute.Max)
|
||||
{
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
|
||||
if (field is DoubleField doubleField)
|
||||
{
|
||||
slider.Value = doubleField.DoubleValue;
|
||||
var changeDueToSlider = false;
|
||||
doubleField.ValueChanged += (s, e) =>
|
||||
{
|
||||
if (!changeDueToSlider)
|
||||
{
|
||||
slider.Value = doubleField.DoubleValue;
|
||||
}
|
||||
};
|
||||
|
||||
slider.ValueChanged += (s, e) =>
|
||||
{
|
||||
changeDueToSlider = true;
|
||||
doubleField.SetValue(slider.Value.ToString(), true);
|
||||
changeDueToSlider = false;
|
||||
};
|
||||
|
||||
var content = new FlowLayoutWidget();
|
||||
content.AddChild(slider);
|
||||
content.AddChild(new GuiWidget()
|
||||
{
|
||||
Width = 11 * GuiWidget.DeviceScale,
|
||||
Height = 3
|
||||
});
|
||||
content.AddChild(field.Content);
|
||||
|
||||
return content;
|
||||
}
|
||||
else if (field is ExpressionField expressionField)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return field.Content;
|
||||
}
|
||||
|
||||
public static GuiWidget CreatePropertyEditor(List<SettingsRow> rows, EditableProperty property, UndoBuffer undoBuffer, PPEContext context, ThemeConfig theme)
|
||||
{
|
||||
var localItem = context.item;
|
||||
|
|
@ -401,7 +453,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
field.Content.Descendants<InternalNumberEdit>().First().MaxDecimalsPlaces = decimalPlaces.Number;
|
||||
}
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, GetFieldContentWithSlider(property, field), theme);
|
||||
}
|
||||
}
|
||||
else if (propertyValue is Color color)
|
||||
|
|
@ -415,7 +467,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
||||
};
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else if (propertyValue is Vector2 vector2)
|
||||
{
|
||||
|
|
@ -489,7 +541,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
||||
};
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else if (propertyValue is DirectionAxis directionAxis)
|
||||
{
|
||||
|
|
@ -571,7 +623,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return childrenSelector;
|
||||
});
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else // show the subtract editor for boolean subtract and subtract and replace
|
||||
{
|
||||
|
|
@ -611,6 +663,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
imageWidget = new ImageWidget(imageBuffer);
|
||||
}
|
||||
|
||||
if (imageDisplayAttribute != null)
|
||||
{
|
||||
imageWidget.MaximumSize = new Vector2(imageDisplayAttribute.MaxXSize * GuiWidget.DeviceScale, int.MaxValue);
|
||||
|
|
@ -774,7 +827,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
object3D.Invalidated += RefreshField;
|
||||
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
}
|
||||
else if (propertyValue is bool boolValue)
|
||||
|
|
@ -787,7 +840,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
RegisterValueChanged(field,
|
||||
(valueString) => { return valueString == "1"; },
|
||||
(value) => { return ((bool)value) ? "1" : "0"; });
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else if (propertyValue is DoubleOrExpression doubleExpresion)
|
||||
{
|
||||
|
|
@ -798,6 +851,17 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
};
|
||||
field.Initialize(0);
|
||||
field.SetValue(doubleExpresion.Expression, false);
|
||||
void EnsureFormating(double value)
|
||||
{
|
||||
var format = "0." + new string('#', 5);
|
||||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MaxDecimalPlacesAttribute>().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces)
|
||||
{
|
||||
format = "0." + new string('#', Math.Min(10, decimalPlaces.Number));
|
||||
}
|
||||
|
||||
field.TextValue = value.ToString(format);
|
||||
}
|
||||
EnsureFormating(doubleExpresion.Value(object3D));
|
||||
field.ClearUndoHistory();
|
||||
RegisterValueChanged(field,
|
||||
(valueString) => new DoubleOrExpression(valueString),
|
||||
|
|
@ -805,7 +869,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
return ((DoubleOrExpression)value).Expression;
|
||||
});
|
||||
rowContainer = CreateSettingsRow(property, field, theme, rows);
|
||||
|
||||
rowContainer = CreateSettingsRow(property, GetFieldContentWithSlider(property, field), theme, rows);
|
||||
|
||||
void RefreshField(object s, InvalidateArgs e)
|
||||
{
|
||||
|
|
@ -814,13 +879,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
DoubleOrExpression newValue = (DoubleOrExpression)property.Value;
|
||||
if (newValue.Expression != field.Value)
|
||||
{
|
||||
var format = "0." + new string('#', 5);
|
||||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MaxDecimalPlacesAttribute>().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces)
|
||||
{
|
||||
format = "0." + new string('#', Math.Min(10, decimalPlaces.Number));
|
||||
}
|
||||
|
||||
field.TextValue = newValue.Value(object3D).ToString(format);
|
||||
EnsureFormating(newValue.Value(object3D));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -841,7 +900,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
return ((IntOrExpression)value).Expression;
|
||||
});
|
||||
rowContainer = CreateSettingsRow(property, field, theme, rows);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
||||
|
||||
void RefreshField(object s, InvalidateArgs e)
|
||||
{
|
||||
|
|
@ -971,7 +1030,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
field.ClearUndoHistory();
|
||||
field.Content.HAnchor = HAnchor.Stretch;
|
||||
RegisterValueChanged(field, (valueString) => valueString);
|
||||
rowContainer = CreateSettingsRow(property, field, theme, rows);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -990,7 +1049,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
return ((StringOrExpression)value).Expression;
|
||||
});
|
||||
rowContainer = CreateSettingsRow(property, field, theme, rows);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme, rows);
|
||||
}
|
||||
else if (propertyValue is char charValue)
|
||||
{
|
||||
|
|
@ -1006,7 +1065,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
||||
};
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else if (property.PropertyType.IsEnum)
|
||||
{
|
||||
|
|
@ -1057,7 +1116,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
if (addToSettingsRow)
|
||||
{
|
||||
rowContainer = CreateSettingsRow(property, field, theme);
|
||||
rowContainer = CreateSettingsRow(property, field.Content, theme);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 935d1ac20335e3e42cf91423b78ff0f7427f89b3
|
||||
Subproject commit 1aa3dae0051442885360631b77d9aa08121b732c
|
||||
Loading…
Add table
Add a link
Reference in a new issue