protected override FlowLayoutPanel GenerateControl(string nesting, PropertyInfo pi, object config, ConfigEditorMetadata metadata) { if (pi.PropertyType != typeof(int)) { throw new Exception(); } var baseline = (int)pi.GetValue(config); var nestedName = $"{nesting}/{pi.Name}"; metadata.BaselineValues[nestedName] = baseline; var tag = new ConfigPropEditorUITag(metadata, this); return(new FlowLayoutPanel { AutoSize = true, Controls = { new Label { Anchor = AnchorStyles.None, AutoSize = true, Text = GetPropertyNameDesc(pi) }, new NumericUpDown { Maximum = int.MaxValue, Minimum = int.MinValue, Size = new Size(72, 20), Value = baseline }.Also(it => { if (pi.GetCustomAttributes(typeof(RangeAttribute), false).FirstOrDefault() is RangeAttribute range) { it.Maximum = (int)range.Maximum; it.Minimum = (int)range.Minimum; } it.ValueChanged += ControlEventHandler; }) },
protected override CheckBox GenerateControl(string nesting, PropertyInfo pi, object config, ConfigEditorMetadata metadata) { if (pi.PropertyType != typeof(bool)) { throw new Exception(); } var baseline = (bool)pi.GetValue(config); var nestedName = $"{nesting}/{pi.Name}"; metadata.BaselineValues[nestedName] = baseline; var tag = new ConfigPropEditorUITag(metadata, this); return(new CheckBox { AutoSize = true, Checked = baseline, ForeColor = GetUnchangedComparisonColor(nestedName, in baseline, tag), Name = nestedName, Tag = tag, Text = GetPropertyNameDesc(pi) }.Also(it => it.CheckedChanged += ControlEventHandler));
protected static Color GetComparisonColor <T>(string nestedName, T?currentValue, ConfigPropEditorUITag tag) where T : class => tag.Generator.TValueEquality(currentValue, (T?)tag.Metadata.BaselineValues[nestedName]) ? GetUnchangedComparisonColor(nestedName, currentValue, tag) : tag.Generator.TValueEquality(currentValue, (T?)tag.Metadata.Cache.DefaultValues[nestedName]) ? tag.Metadata.ComparisonColors.ChangedUnset : tag.Metadata.ComparisonColors.Changed;