Skip to content

Commit

Permalink
Update StorageBar
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Aug 15, 2024
1 parent 10ef2b6 commit 5acc4c7
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 1,172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public double Percent

private void OnPercentChanged(double oldValue, double newValue)
{
return; //Read-only

DoubleToPercentage(Value, Minimum, Maximum);

UpdateControl(this);
Expand Down Expand Up @@ -184,7 +186,7 @@ protected override void OnValueChanged(double oldValue, double newValue)
{
_oldValue = oldValue;
base.OnValueChanged(oldValue, newValue);
OnValueChanged(this);
UpdateValue(this, Value, _oldValue, false, -1.0);
}

/// <inheritdoc/>
Expand Down
15 changes: 3 additions & 12 deletions src/Files.App.Controls/Storage/StorageBar/StorageBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void OnApplyTemplate()
UpdateInitialLayout(this);
}

#region 5. Handle Property Changes
#region Handle Property Changes

/// <summary>
/// Handles the IsEnabledChanged event
Expand Down Expand Up @@ -97,18 +97,9 @@ private void StorageBar_SizeChanged(object sender, SizeChangedEventArgs e)
UpdateControl(this);
}

/// <summary>
/// Handles the RangeBase's ValueChanged event
/// </summary>
/// <param name="d"></param>
private void OnValueChanged(DependencyObject d)
{
UpdateValue(this, Value, _oldValue, false, -1.0);
}

#endregion

#region 6. Update functions
#region Update functions

/// <summary>
/// Updates the initial layout of the StorageBar control
Expand Down Expand Up @@ -479,7 +470,7 @@ private void UpdateVisualState(DependencyObject d)

#endregion

#region 7. Conversion return functions
#region Conversion return functions

/// <summary>
/// Converts a value within a specified range to a percentage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Files.App.Controls.Primitives;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls.Primitives;
using System;

namespace Files.App.Controls
Expand Down
135 changes: 52 additions & 83 deletions src/Files.App.Controls/Storage/StorageRing/StorageRing.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls.Primitives;

namespace Files.App.Controls
{
Expand All @@ -18,7 +17,7 @@ public partial class StorageRing
nameof(ValueRingThickness),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(0.0, OnValueRingThicknessChanged));
new PropertyMetadata(0.0, (d, e) => ((StorageRing)d).OnValueRingThicknessChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the Track ring Thickness.
Expand All @@ -32,16 +31,10 @@ public double ValueRingThickness
set => SetValue(ValueRingThicknessProperty, value);
}

/// <summary>
/// Function invoked as the ValueRingThicknessProperty is changed
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnValueRingThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnValueRingThicknessChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.ValueRingThicknessChanged(d, (double)e.NewValue);
UpdateRingThickness(this, newValue, false);
UpdateRings(this);
}

#endregion
Expand All @@ -56,7 +49,7 @@ private static void OnValueRingThicknessChanged(DependencyObject d, DependencyPr
nameof(TrackRingThickness),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(0.0, OnTrackRingThicknessChanged));
new PropertyMetadata(0.0, (d, e) => ((StorageRing)d).OnTrackRingThicknessChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the Track ring Thickness.
Expand All @@ -70,16 +63,10 @@ public double TrackRingThickness
set => SetValue(TrackRingThicknessProperty, value);
}

/// <summary>
/// Function invoked as the TrackRingThicknessProperty is changed
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnTrackRingThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnTrackRingThicknessChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.TrackRingThicknessChanged(d, (double)e.NewValue);
UpdateRingThickness(this, newValue, true);
UpdateRings(this);
}

#endregion
Expand All @@ -94,7 +81,7 @@ private static void OnTrackRingThicknessChanged(DependencyObject d, DependencyPr
nameof(MinAngle),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(0.0, OnMinAngleChanged));
new PropertyMetadata(0.0, (d, e) => ((StorageRing)d).OnMinAngleChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the MinAngle
Expand All @@ -105,16 +92,11 @@ public double MinAngle
set => SetValue(MinAngleProperty, value);
}

/// <summary>
/// Function invoked as the MinAngleProperty is changed
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnMinAngleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnMinAngleChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.MinAngleChanged(d, (double)e.NewValue);
UpdateValues(this, Value, _oldValue, false, -1.0);
CalculateAndSetNormalizedAngles(this, newValue, MaxAngle);
UpdateRings(this);
}

#endregion
Expand All @@ -129,7 +111,7 @@ private static void OnMinAngleChanged(DependencyObject d, DependencyPropertyChan
nameof(MaxAngle),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(360.0, OnMaxAngleChanged));
new PropertyMetadata(360.0, (d, e) => ((StorageRing)d).OnMaxAngleChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the MaxAngle
Expand All @@ -140,16 +122,11 @@ public double MaxAngle
set => SetValue(MaxAngleProperty, value);
}

/// <summary>
/// Function invoked as the MaxAngleProperty is changed
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnMaxAngleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnMaxAngleChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.MaxAngleChanged(d, (double)e.NewValue);
UpdateValues(this, Value, _oldValue, false, -1.0);
CalculateAndSetNormalizedAngles(this, MinAngle, newValue);
UpdateRings(this);
}

#endregion
Expand All @@ -164,7 +141,7 @@ private static void OnMaxAngleChanged(DependencyObject d, DependencyPropertyChan
nameof(StartAngle),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(0.0, OnStartAngleChanged));
new PropertyMetadata(0.0, (d, e) => ((StorageRing)d).OnStartAngleChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the StartAngle
Expand All @@ -175,16 +152,12 @@ public double StartAngle
set => SetValue(StartAngleProperty, value);
}

/// <summary>
/// Function invoked as the StartAngleProperty is changed
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnStartAngleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnStartAngleChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.StartAngleChanged(d, (double)e.NewValue);
UpdateValues(this, Value, _oldValue, false, -1.0);
CalculateAndSetNormalizedAngles(this, MinAngle, newValue);
ValidateStartAngle(this, newValue);
UpdateRings(this);
}

#endregion
Expand All @@ -199,7 +172,7 @@ private static void OnStartAngleChanged(DependencyObject d, DependencyPropertyCh
nameof(Percent),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(null, OnPercentChanged));
new PropertyMetadata(null, (d, e) => ((StorageRing)d).OnPercentChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the current value as a Percentage between 0.0 and 100.0.
Expand All @@ -210,16 +183,25 @@ public double Percent
set => SetValue(PercentProperty, value);
}

/// <summary>
/// Handles the change in the Percent property, and ensures the range is between 0.0 and 100.0.
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnPercentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnPercentChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;
return; //Read-only

DoubleToPercentage(Value, Minimum, Maximum);

double adjustedPercentage;

if (newValue <= 0.0)
adjustedPercentage = 0.0;
else if (newValue <= 100.0)
adjustedPercentage = 100.0;
else
adjustedPercentage = newValue;

UpdateValues(this, Value, _oldValue, true, adjustedPercentage);
UpdateVisualState(this);
UpdateRings(this);

storageRing.DoubleToPercentage(storageRing.Value, storageRing.Minimum, storageRing.Maximum);
}

#endregion
Expand All @@ -234,7 +216,7 @@ private static void OnPercentChanged(DependencyObject d, DependencyPropertyChang
nameof(PercentCaution),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(75.01, OnPercentCautionChanged));
new PropertyMetadata(75.01, (d, e) => ((StorageRing)d).OnPercentCautionChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the PercentCaution double value
Expand All @@ -245,16 +227,11 @@ public double PercentCaution
set => SetValue(PercentCautionProperty, value);
}

/// <summary>
/// Handles the change in the PercentCaution property
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnPercentCautionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnPercentCautionChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.PercentCautionChanged(d, (double)e.NewValue);
UpdateValues(this, Value, _oldValue, false, -1.0);
UpdateVisualState(this);
UpdateRings(this);
}

#endregion
Expand All @@ -269,7 +246,7 @@ private static void OnPercentCautionChanged(DependencyObject d, DependencyProper
nameof(PercentCritical),
typeof(double),
typeof(StorageRing),
new PropertyMetadata(90.01, OnPercentCriticalChanged));
new PropertyMetadata(90.01, (d, e) => ((StorageRing)d).OnPercentCriticalChanged((double)e.OldValue, (double)e.NewValue)));

/// <summary>
/// Gets or sets the PercentCritical double value
Expand All @@ -280,16 +257,11 @@ public double PercentCritical
set => SetValue(PercentCriticalProperty, value);
}

/// <summary>
/// Handles the change in the PercentCritical property
/// </summary>
/// <param name="d">The DependencyObject which holds the DependencyProperty</param>
/// <param name="e">DependencyPropertyChangedEventArgs</param>
private static void OnPercentCriticalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private void OnPercentCriticalChanged(double oldValue, double newValue)
{
StorageRing storageRing = (StorageRing)d;

storageRing.PercentCriticalChanged(d, (double)e.NewValue);
UpdateValues(this, Value, _oldValue, false, -1.0);
UpdateVisualState(this);
UpdateRings(this);
}

#endregion
Expand All @@ -300,23 +272,20 @@ private static void OnPercentCriticalChanged(DependencyObject d, DependencyPrope
protected override void OnValueChanged(double oldValue, double newValue)
{
base.OnValueChanged(oldValue, newValue);

StorageRing_ValueChanged(this, newValue, oldValue);
}

/// <inheritdoc/>
protected override void OnMinimumChanged(double oldMinimum, double newMinimum)
{
base.OnMinimumChanged(oldMinimum, newMinimum);

StorageRing_MinimumChanged(this, newMinimum);
}

/// <inheritdoc/>
protected override void OnMaximumChanged(double oldMaximum, double newMaximum)
{
base.OnMaximumChanged(oldMaximum, newMaximum);

StorageRing_MaximumChanged(this, newMaximum);
}

Expand Down
Loading

0 comments on commit 5acc4c7

Please sign in to comment.