2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 08:23:42 -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:
F K
2024-01-29 15:37:00 -05:00
committed by GitHub
parent a555c86083
commit 351dcdb732
5 changed files with 227 additions and 28 deletions

View File

@ -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
}

View File

@ -4,6 +4,22 @@
<name>ObservatoryFramework</name>
</assembly>
<members>
<member name="T:Observatory.Framework.SettingSuggestedColumnWidth">
<summary>
Specifies the width of a settings column in the settings view. There are two columns.
</summary>
</member>
<member name="M:Observatory.Framework.SettingSuggestedColumnWidth.#ctor(System.Int32)">
<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>
</member>
<member name="P:Observatory.Framework.SettingSuggestedColumnWidth.Width">
<summary>
Provides a hint of the width of a settings column.
</summary>
</member>
<member name="T:Observatory.Framework.SettingDisplayName">
<summary>
Specifies text to display as the name of the setting in the UI instead of the property name.
@ -20,9 +36,20 @@
Accessor to get/set displayed name.
</summary>
</member>
<member name="T:Observatory.Framework.ColumnSuggestedWidth">
<member name="T:Observatory.Framework.SettingNewGroup">
<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>
</member>
<member name="M:Observatory.Framework.SettingNewGroup.#ctor(System.String)">
<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>
</member>
<member name="P:Observatory.Framework.SettingNewGroup.Label">
<summary>
An optional label describing the group.
</summary>
</member>
<member name="T:Observatory.Framework.SettingIgnore">
@ -56,13 +83,14 @@
Specify bounds for numeric inputs.
</summary>
</member>
<member name="M:Observatory.Framework.SettingNumericBounds.#ctor(System.Double,System.Double,System.Double)">
<member name="M:Observatory.Framework.SettingNumericBounds.#ctor(System.Double,System.Double,System.Double,System.Int32)">
<summary>
Specify bounds for numeric inputs.
</summary>
<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>
<param name="precision">The number of digits to display for non integer values.</param>
</member>
<member name="P:Observatory.Framework.SettingNumericBounds.Minimum">
<summary>
@ -71,7 +99,7 @@
</member>
<member name="P:Observatory.Framework.SettingNumericBounds.Maximum">
<summary>
Maxunyn allowed value.
Maximum allowed value.
</summary>
</member>
<member name="P:Observatory.Framework.SettingNumericBounds.Increment">
@ -79,6 +107,27 @@
Increment between allowed values in slider/roller inputs.
</summary>
</member>
<member name="P:Observatory.Framework.SettingNumericBounds.Precision">
<summary>
The number of digits to display for non integer values.
</summary>
</member>
<member name="T:Observatory.Framework.ColumnSuggestedWidth">
<summary>
Suggests default column width when building basic plugin grid UI.
</summary>
</member>
<member name="M:Observatory.Framework.ColumnSuggestedWidth.#ctor(System.Int32)">
<summary>
Suggests default column width when building basic plugin grid UI.
</summary>
<param name="width">The suggested width of the annotated column.</param>
</member>
<member name="P:Observatory.Framework.ColumnSuggestedWidth.Width">
<summary>
The suggested width of the annotated column.
</summary>
</member>
<member name="T:Observatory.Framework.JournalEventArgs">
<summary>
Provides data for Elite Dangerous journal events.