mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-06-30 16:23:41 -04:00
[Core] Settings improvements: Grouping w/labels, support for doubles (#137)
* [Core] Settings improvements: Grouping w/labels, support for doubles Layout improvements: * Plugins can set `[SettingSuggestedColumnWidth(123)]` on a settings class to adjust the settings view column width to make it wider or narrower to fit things nicely. * Plugins can set `[SettingNewGroup("label")]` on any setting property to force a "new paragraph", or group, of settings. If "label" is also provided, a grouping header with that text will also be created. * A double precision up/down numeric control has been added. In support of this, there is now a precision value on the existing `[SettingNumericBounds]` attribute to specify the number of digits of precision the control displays/allows. Plugins: * The above have been applied/demonstrated on the Botanist and Explorer plugin settings.
This commit is contained in:
@ -6,6 +6,32 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Observatory.Framework
|
||||
{
|
||||
|
||||
#region Settings class attributes
|
||||
/// <summary>
|
||||
/// Specifies the width of a settings column in the settings view. There are two columns.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
public class SettingSuggestedColumnWidth : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the width of a settings column in the settings view. There are two columns.
|
||||
/// </summary>
|
||||
/// <param name="width">Provides a hint of the width of a settings column.</param>
|
||||
public SettingSuggestedColumnWidth(int width)
|
||||
{
|
||||
Width = width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a hint of the width of a settings column.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Setting property attributes
|
||||
|
||||
/// <summary>
|
||||
/// Specifies text to display as the name of the setting in the UI instead of the property name.
|
||||
/// </summary>
|
||||
@ -34,17 +60,24 @@ namespace Observatory.Framework
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suggests default column width when building basic UI
|
||||
/// Starts a new visual group of settings beginning with the current setting with an optional label.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
||||
public class ColumnSuggestedWidth : Attribute
|
||||
{
|
||||
public ColumnSuggestedWidth(int width)
|
||||
public class SettingNewGroup : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts a new visual group of settings beginning with the current setting with an optional label.
|
||||
/// </summary>
|
||||
/// <param name="label">An optional label describing the group.</param>
|
||||
public SettingNewGroup(string label = "")
|
||||
{
|
||||
Width = width;
|
||||
Label = label;
|
||||
}
|
||||
|
||||
public int Width { get; }
|
||||
/// <summary>
|
||||
/// An optional label describing the group.
|
||||
/// </summary>
|
||||
public string Label { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -97,6 +130,7 @@ namespace Observatory.Framework
|
||||
private double minimum;
|
||||
private double maximum;
|
||||
private double increment;
|
||||
private int precision;
|
||||
|
||||
/// <summary>
|
||||
/// Specify bounds for numeric inputs.
|
||||
@ -104,11 +138,13 @@ namespace Observatory.Framework
|
||||
/// <param name="minimum">Minimum allowed value.</param>
|
||||
/// <param name="maximum">Maximum allowed value.</param>
|
||||
/// <param name="increment">Increment between allowed values in slider/roller inputs.</param>
|
||||
public SettingNumericBounds(double minimum, double maximum, double increment = 1.0)
|
||||
/// <param name="precision">The number of digits to display for non integer values.</param>
|
||||
public SettingNumericBounds(double minimum, double maximum, double increment = 1.0, int precision = 1)
|
||||
{
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.increment = increment;
|
||||
this.precision = precision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -121,7 +157,7 @@ namespace Observatory.Framework
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maxunyn allowed value.
|
||||
/// Maximum allowed value.
|
||||
/// </summary>
|
||||
public double Maximum
|
||||
{
|
||||
@ -137,5 +173,38 @@ namespace Observatory.Framework
|
||||
get => increment;
|
||||
set => increment = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The number of digits to display for non integer values.
|
||||
/// </summary>
|
||||
public int Precision
|
||||
{
|
||||
get => precision;
|
||||
set => precision = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region BasicUI attributes
|
||||
/// <summary>
|
||||
/// Suggests default column width when building basic plugin grid UI.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
||||
public class ColumnSuggestedWidth : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Suggests default column width when building basic plugin grid UI.
|
||||
/// </summary>
|
||||
/// <param name="width">The suggested width of the annotated column.</param>
|
||||
public ColumnSuggestedWidth(int width)
|
||||
{
|
||||
Width = width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The suggested width of the annotated column.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user