Skip to content

Commit

Permalink
Added Max-, MinValue & StepSize to PropertyAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 17, 2020
1 parent 4622c7c commit 63ca3c7
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 31 deletions.
1 change: 1 addition & 0 deletions Arma.Studio.Data/ArmA.Studio.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<Compile Include="UI\EditorInfoDrawingBrush.cs" />
<Compile Include="UI\EditorInfoIcon.cs" />
<Compile Include="UI\RelayDataTemplateSelector.cs" />
<Compile Include="Utility.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="TypeExtensions.tt">
Expand Down
19 changes: 19 additions & 0 deletions Arma.Studio.Data/UI/PropertyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,32 @@ public class PropertyAttribute : Attribute
/// </summary>
public object Default { get; set; }

/// <summary>
/// UI-Configuration.
/// The Minimum value the property is supposed to have.
/// </summary>
public double MinValue { get; set; }
/// <summary>
/// UI-Configuration.
/// The Maximum value the property is supposed to have.
/// </summary>
public double MaxValue { get; set; }
/// <summary>
/// UI-Configuration.
/// Stepsize for numeric up-down.
/// </summary>
public double Stepsize { get; set; }

public PropertyAttribute(string title)
{
this.Title = title;
this.Display = true;
this.Description = string.Empty;
this.Group = null;
this.Default = null;
this.MinValue = double.MinValue;
this.MaxValue = double.MaxValue;
this.Stepsize = 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ public object Value
}
}

/// <summary>
/// UI-Configuration.
/// The Minimum value the property is supposed to have.
/// </summary>
public double MinValue { get; set; }
/// <summary>
/// UI-Configuration.
/// The Maximum value the property is supposed to have.
/// </summary>
public double MaxValue { get; set; }
/// <summary>
/// UI-Configuration.
/// Stepsize for numeric up-down.
/// </summary>
public double Stepsize { get; set; }

public string Title { get; }
public string ToolTip { get; }
public PropertyContainerBase(string title, string tooltip, object data, string propertyName, Func<object, object> getFunc, Action<object, object> setFunc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public static PropertyContainerColor Create(object data, PropertyInfo propertyIn
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerColor(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Color)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerColor(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Color)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ public static PropertyContainerEnum Create(object data, PropertyInfo propertyInf
}

var enumValues = Enum.GetValues(propertyInfo.PropertyType);
return new PropertyContainerEnum(
var container = new PropertyContainerEnum(
attribute.Title,
attribute.Description,
data,
propertyInfo.Name,
enumValues.Cast<object>().Select((it) => new EnumValue(it, Studio.Data.UI.Converters.EnumNameConverter.Instance.Convert(propertyInfo.PropertyType, it))),
(obj) => propertyInfo.GetValue(obj, null),
(obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public static PropertyContainerByte Create(object data, PropertyInfo propertyInf
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Byte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Byte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerSByte : PropertyContainerBase
Expand All @@ -41,7 +45,11 @@ public static PropertyContainerSByte Create(object data, PropertyInfo propertyIn
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerSByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (SByte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerSByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (SByte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerInt32 : PropertyContainerBase
Expand All @@ -62,7 +70,11 @@ public static PropertyContainerInt32 Create(object data, PropertyInfo propertyIn
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerUInt32 : PropertyContainerBase
Expand All @@ -83,7 +95,11 @@ public static PropertyContainerUInt32 Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerUInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerUInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerInt16 : PropertyContainerBase
Expand All @@ -104,7 +120,11 @@ public static PropertyContainerInt16 Create(object data, PropertyInfo propertyIn
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerUInt16 : PropertyContainerBase
Expand All @@ -125,7 +145,11 @@ public static PropertyContainerUInt16 Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerUInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerUInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerInt64 : PropertyContainerBase
Expand All @@ -146,7 +170,11 @@ public static PropertyContainerInt64 Create(object data, PropertyInfo propertyIn
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerUInt64 : PropertyContainerBase
Expand All @@ -167,7 +195,11 @@ public static PropertyContainerUInt64 Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerUInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerUInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerSingle : PropertyContainerBase
Expand All @@ -188,7 +220,11 @@ public static PropertyContainerSingle Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerSingle(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Single)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerSingle(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Single)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerDouble : PropertyContainerBase
Expand All @@ -209,7 +245,11 @@ public static PropertyContainerDouble Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerDouble(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Double)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerDouble(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Double)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerChar : PropertyContainerBase
Expand All @@ -230,7 +270,11 @@ public static PropertyContainerChar Create(object data, PropertyInfo propertyInf
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerChar(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Char)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerChar(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Char)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerBoolean : PropertyContainerBase
Expand All @@ -251,7 +295,11 @@ public static PropertyContainerBoolean Create(object data, PropertyInfo property
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerBoolean(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Boolean)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerBoolean(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Boolean)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerString : PropertyContainerBase
Expand All @@ -272,7 +320,11 @@ public static PropertyContainerString Create(object data, PropertyInfo propertyI
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerString(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (String)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerString(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (String)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
public class PropertyContainerDecimal : PropertyContainerBase
Expand All @@ -293,7 +345,11 @@ public static PropertyContainerDecimal Create(object data, PropertyInfo property
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainerDecimal(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Decimal)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainerDecimal(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Decimal)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ namespace Arma.Studio.PropertiesWindow.PropertyContainers
{
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
}
return new PropertyContainer<#= type.Name #>(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (<#= type.Name #>)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
var container = new PropertyContainer<#= type.Name #>(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (<#= type.Name #>)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
container.Stepsize = attribute.Stepsize;
container.MinValue = attribute.MinValue;
container.MaxValue = attribute.MaxValue;
return container;
}
}
<# } #>
Expand Down
Loading

0 comments on commit 63ca3c7

Please sign in to comment.