Update values formatting on editor options save #2213
This commit is contained in:
@@ -196,37 +196,19 @@ namespace FlaxEditor.Options
|
||||
[EditorDisplay("Interface"), EditorOrder(280), Tooltip("Editor content window orientation.")]
|
||||
public FlaxEngine.GUI.Orientation ContentWindowOrientation { get; set; } = FlaxEngine.GUI.Orientation.Horizontal;
|
||||
|
||||
private ValueFormattingType _valueFormatting = ValueFormattingType.None;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the formatting option for numeric values in the editor.
|
||||
/// </summary>
|
||||
[DefaultValue(ValueFormattingType.None)]
|
||||
[EditorDisplay("Interface"), EditorOrder(300), Tooltip("Formatting of numeric values.")]
|
||||
public ValueFormattingType ValueFormatting {
|
||||
get => _valueFormatting;
|
||||
set
|
||||
{
|
||||
_valueFormatting = value;
|
||||
Units.UseUnitsFormatting = _valueFormatting != ValueFormattingType.None;
|
||||
Units.AutomaticUnitsFormatting = _valueFormatting == ValueFormattingType.AutoUnit;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _spaceNumberAndUnits = false;
|
||||
[EditorDisplay("Interface"), EditorOrder(300)]
|
||||
public ValueFormattingType ValueFormatting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the option to put a space between numbers and units for unit formatting.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
[EditorDisplay("Interface"), EditorOrder(310), Tooltip("Put a space between numbers and units.")]
|
||||
public bool SpaceNumberAndUnits { get => _spaceNumberAndUnits;
|
||||
set
|
||||
{
|
||||
_spaceNumberAndUnits = value;
|
||||
Units.SpaceNumberAndUnits = _spaceNumberAndUnits;
|
||||
}
|
||||
}
|
||||
[EditorDisplay("Interface"), EditorOrder(310)]
|
||||
public bool SeparateValueAndUnit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timestamps prefix mode for output log messages.
|
||||
|
||||
@@ -200,6 +200,27 @@ namespace FlaxEditor.Options
|
||||
|
||||
EditorAssets.Cache.OnEditorOptionsChanged(Options);
|
||||
|
||||
// Units formatting options
|
||||
bool useUnitsFormatting = Options.Interface.ValueFormatting != InterfaceOptions.ValueFormattingType.None;
|
||||
bool automaticUnitsFormatting = Options.Interface.ValueFormatting == InterfaceOptions.ValueFormattingType.AutoUnit;
|
||||
bool separateValueAndUnit = Options.Interface.SeparateValueAndUnit;
|
||||
if (useUnitsFormatting != Utilities.Units.UseUnitsFormatting ||
|
||||
automaticUnitsFormatting != Utilities.Units.AutomaticUnitsFormatting ||
|
||||
separateValueAndUnit != Utilities.Units.SeparateValueAndUnit)
|
||||
{
|
||||
Utilities.Units.UseUnitsFormatting = useUnitsFormatting;
|
||||
Utilities.Units.AutomaticUnitsFormatting = automaticUnitsFormatting;
|
||||
Utilities.Units.SeparateValueAndUnit = separateValueAndUnit;
|
||||
|
||||
// Refresh UI in property panels
|
||||
Editor.Windows.PropertiesWin?.Presenter.BuildLayoutOnUpdate();
|
||||
foreach (var window in Editor.Windows.Windows)
|
||||
{
|
||||
if (window is Windows.Assets.PrefabWindow prefabWindow)
|
||||
prefabWindow.Presenter.BuildLayoutOnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// Send event
|
||||
OptionsChanged?.Invoke(Options);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Units
|
||||
/// <summary>
|
||||
/// Add a space between numbers and units for readability.
|
||||
/// </summary>
|
||||
public static bool SpaceNumberAndUnits = true;
|
||||
public static bool SeparateValueAndUnit = true;
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, the distance unit is chosen on the magnitude, otherwise it's meters.
|
||||
@@ -34,7 +34,7 @@ public class Units
|
||||
/// <returns>The formatted text.</returns>
|
||||
public static string Unit(string unit)
|
||||
{
|
||||
if (SpaceNumberAndUnits)
|
||||
if (SeparateValueAndUnit)
|
||||
return $" {unit}";
|
||||
return unit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user