Skip to content

Commit 2030228

Browse files
authored
Code Quality: Refactored StorageRing/StorageBar (#16998)
1 parent 2f99a52 commit 2030228

15 files changed

+1061
-1669
lines changed

src/Files.App.Controls/Storage/RingShape/RingShape.Properties.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public partial class RingShape : Path
3232
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
3333
public partial double RadiusHeight { get; set; }
3434

35-
[GeneratedDependencyProperty]
35+
[GeneratedDependencyProperty(DefaultValue = false)]
3636
public partial bool IsCircle { get; set; }
3737

3838
[GeneratedDependencyProperty]
3939
public partial Point Center { get; set; }
4040

41-
[GeneratedDependencyProperty]
41+
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
4242
public partial double ActualRadiusWidth { get; set; }
4343

44-
[GeneratedDependencyProperty]
44+
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
4545
public partial double ActualRadiusHeight { get; set; }
4646

4747
partial void OnStartAngleChanged(double newValue)

src/Files.App.Controls/Storage/RingShape/RingShape.cs

+54-56
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Microsoft.UI.Xaml;
54
using Microsoft.UI.Xaml.Media;
65
using Microsoft.UI.Xaml.Shapes;
7-
using System;
86
using Windows.Foundation;
97

108
namespace Files.App.Controls.Primitives
@@ -18,18 +16,18 @@ public partial class RingShape : Path
1816

1917
// Fields
2018

21-
private bool _isUpdating; // Is True when path is updating
22-
private bool _isCircle; // When True, Width and Height are equalized
23-
private Size _equalSize; // Calculated where Width and Height are equal
24-
private double _equalRadius; // Calculated where RadiusWidth and RadiusHeight are equal
25-
private Point _centerPoint; // Center Point within Width and Height bounds
26-
private double _normalizedMinAngle; // Normalized MinAngle between -180 and 540
27-
private double _normalizedMaxAngle; // Normalized MaxAngle between 0 and 360
28-
private double _validStartAngle; // The validated StartAngle
29-
private double _validEndAngle; // The validated EndAngle
30-
private double _radiusWidth; // The radius Width
31-
private double _radiusHeight; // The radius Height
32-
private SweepDirection _sweepDirection; // The SweepDirection
19+
private bool _isUpdating; // Is True when path is updating
20+
private bool _isCircle; // When True, Width and Height are equalized
21+
private Size _equalSize; // Calculated where Width and Height are equal
22+
private double _equalRadius; // Calculated where RadiusWidth and RadiusHeight are equal
23+
private Point _centerPoint; // Center Point within Width and Height bounds
24+
private double _normalizedMinAngle; // Normalized MinAngle between -180 and 540
25+
private double _normalizedMaxAngle; // Normalized MaxAngle between 0 and 360
26+
private double _validStartAngle; // The validated StartAngle
27+
private double _validEndAngle; // The validated EndAngle
28+
private double _radiusWidth; // The radius Width
29+
private double _radiusHeight; // The radius Height
30+
private SweepDirection _sweepDirection; // The SweepDirection
3331

3432
// Constants
3533

@@ -168,41 +166,41 @@ public void UpdateSizeAndStroke(DependencyObject d)
168166
{
169167
RingShape ringShape = (RingShape)d;
170168

171-
AdjustRadiusWidth( ringShape , ringShape.RadiusWidth , ringShape.StrokeThickness );
172-
AdjustRadiusHeight( ringShape , ringShape.RadiusHeight , ringShape.StrokeThickness );
169+
AdjustRadiusWidth(ringShape, ringShape.RadiusWidth, ringShape.StrokeThickness);
170+
AdjustRadiusHeight(ringShape, ringShape.RadiusHeight, ringShape.StrokeThickness);
173171

174-
_equalSize = CalculateEqualSize( new Size( ringShape.Width , ringShape.Height ) , ringShape.StrokeThickness );
175-
_equalRadius = CalculateEqualRadius( ringShape , ringShape.RadiusWidth , ringShape.RadiusHeight , ringShape.StrokeThickness );
172+
_equalSize = CalculateEqualSize(new Size(ringShape.Width, ringShape.Height), ringShape.StrokeThickness);
173+
_equalRadius = CalculateEqualRadius(ringShape, ringShape.RadiusWidth, ringShape.RadiusHeight, ringShape.StrokeThickness);
176174

177-
_centerPoint = new Point( ringShape.Width / 2 , ringShape.Height / 2 );
175+
_centerPoint = new Point(ringShape.Width / 2, ringShape.Height / 2);
178176
ringShape.Center = _centerPoint;
179177

180-
CalculateAndSetNormalizedAngles( ringShape , ringShape.MinAngle , ringShape.MaxAngle );
178+
CalculateAndSetNormalizedAngles(ringShape, ringShape.MinAngle, ringShape.MaxAngle);
181179

182-
ValidateAngle( ringShape , ringShape.StartAngle , true );
183-
ValidateAngle( ringShape , ringShape.EndAngle , false );
180+
ValidateAngle(ringShape, ringShape.StartAngle, true);
181+
ValidateAngle(ringShape, ringShape.EndAngle, false);
184182
}
185183

186184
private static EllipseGeometry DrawEllipse(bool IsCircle, Point Center, double EqualRadius, double RadiusWidth, double RadiusHeight)
187185
{
188186
EllipseGeometry eg;
189187

190-
if ( IsCircle == true )
188+
if (IsCircle == true)
191189
{
192190
eg = new EllipseGeometry
193191
{
194-
Center = Center ,
195-
RadiusX = EqualRadius ,
196-
RadiusY = EqualRadius ,
192+
Center = Center,
193+
RadiusX = EqualRadius,
194+
RadiusY = EqualRadius,
197195
};
198196
}
199197
else
200198
{
201199
eg = new EllipseGeometry
202200
{
203-
Center = Center ,
204-
RadiusX = RadiusWidth ,
205-
RadiusY = RadiusHeight ,
201+
Center = Center,
202+
RadiusX = RadiusWidth,
203+
RadiusY = RadiusHeight,
206204
};
207205
}
208206

@@ -220,19 +218,19 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
220218

221219
var arcSegment = new ArcSegment();
222220

223-
if ( IsCircle == true )
221+
if (IsCircle == true)
224222
{
225223
var radius = EqualRadius;
226224

227225
RingShape.ActualRadiusWidth = radius;
228226
RingShape.ActualRadiusHeight = radius;
229227

230228
// Start Point
231-
pathFigure.StartPoint = ArcStartPoint( SweepDirection , newCenter, StartAngle, radius, radius);
229+
pathFigure.StartPoint = ArcStartPoint(SweepDirection, newCenter, StartAngle, radius, radius);
232230

233231

234232
// Arc Segment and End Point
235-
arcSegment = CreateArcSegment( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius );
233+
arcSegment = CreateArcSegment(SweepDirection, newCenter, StartAngle, EndAngle, radius, radius);
236234
}
237235
else
238236
{
@@ -243,63 +241,63 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
243241
RingShape.ActualRadiusHeight = radiusHeight;
244242

245243
// Start Point
246-
pathFigure.StartPoint = ArcStartPoint( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight );
244+
pathFigure.StartPoint = ArcStartPoint(SweepDirection, newCenter, StartAngle, radiusWidth, radiusHeight);
247245

248246

249247
// Arc Segment and End Point
250-
arcSegment = CreateArcSegment( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight );
248+
arcSegment = CreateArcSegment(SweepDirection, newCenter, StartAngle, EndAngle, radiusWidth, radiusHeight);
251249
}
252250

253-
pathFigure.Segments.Add( arcSegment );
254-
pathGeometry.Figures.Add( pathFigure );
251+
pathFigure.Segments.Add(arcSegment);
252+
pathGeometry.Figures.Add(pathFigure);
255253

256254
return pathGeometry;
257255
}
258256

259-
private static Point ArcStartPoint(SweepDirection SweepDirection , Point Center, double StartAngle , double RadiusWidth, double RadiusHeight)
257+
private static Point ArcStartPoint(SweepDirection SweepDirection, Point Center, double StartAngle, double RadiusWidth, double RadiusHeight)
260258
{
261259
var finalPoint = new Point();
262260

263261
// Counterclockwise
264-
if ( SweepDirection == SweepDirection.Counterclockwise )
262+
if (SweepDirection == SweepDirection.Counterclockwise)
265263
{
266264
finalPoint =
267265
new Point(
268-
Center.X - Math.Sin( StartAngle * DegreesToRadians ) * RadiusWidth ,
269-
Center.Y - Math.Cos( StartAngle * DegreesToRadians ) * RadiusHeight );
266+
Center.X - Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
267+
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
270268
}
271269
// Clockwise
272270
else
273271
{
274272
finalPoint =
275273
new Point(
276-
Center.X + Math.Sin( StartAngle * DegreesToRadians ) * RadiusWidth ,
277-
Center.Y - Math.Cos( StartAngle * DegreesToRadians ) * RadiusHeight );
274+
Center.X + Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
275+
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
278276
}
279277

280278
return finalPoint;
281279
}
282280

283-
private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point Center , double StartAngle, double EndAngle , double RadiusWidth , double RadiusHeight)
284-
{
281+
private static ArcSegment CreateArcSegment(SweepDirection SweepDirection, Point Center, double StartAngle, double EndAngle, double RadiusWidth, double RadiusHeight)
282+
{
285283
var finalArcSegment = new ArcSegment();
286284

287285
// Counterclockwise
288-
if ( SweepDirection == SweepDirection.Counterclockwise )
286+
if (SweepDirection == SweepDirection.Counterclockwise)
289287
{
290288
finalArcSegment.Point =
291289
new Point(
292-
Center.X - Math.Sin( EndAngle * DegreesToRadians ) * RadiusWidth ,
293-
Center.Y - Math.Cos( EndAngle * DegreesToRadians ) * RadiusHeight );
290+
Center.X - Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
291+
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
294292

295-
if ( EndAngle < StartAngle )
293+
if (EndAngle < StartAngle)
296294
{
297-
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) <= -180.0;
295+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
298296
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
299297
}
300298
else
301299
{
302-
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
300+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
303301
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
304302
}
305303
}
@@ -308,21 +306,21 @@ private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point
308306
{
309307
finalArcSegment.Point =
310308
new Point(
311-
Center.X + Math.Sin( EndAngle * DegreesToRadians ) * RadiusWidth ,
312-
Center.Y - Math.Cos( EndAngle * DegreesToRadians ) * RadiusHeight );
309+
Center.X + Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
310+
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
313311
//ArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
314-
if ( EndAngle < StartAngle )
312+
if (EndAngle < StartAngle)
315313
{
316-
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) <= -180.0;
314+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
317315
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
318316
}
319317
else
320318
{
321-
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
319+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
322320
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
323321
}
324322
}
325-
finalArcSegment.Size = new Size( RadiusWidth , RadiusHeight );
323+
finalArcSegment.Size = new Size(RadiusWidth, RadiusHeight);
326324

327325
return finalArcSegment;
328326
}

src/Files.App.Controls/Storage/StorageBar/StorageBar.Constants.cs

-40
This file was deleted.

src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Microsoft.UI.Xaml;
65

76
namespace Files.App.Controls
87
{
98
public partial class StorageBar
109
{
11-
[GeneratedDependencyProperty(DefaultValue = 4.0d)]
10+
[GeneratedDependencyProperty(DefaultValue = 6.0d)]
1211
public partial double ValueBarHeight { get; set; }
1312

14-
[GeneratedDependencyProperty(DefaultValue = 2.0d)]
13+
[GeneratedDependencyProperty(DefaultValue = 3.0d)]
1514
public partial double TrackBarHeight { get; set; }
1615

1716
[GeneratedDependencyProperty(DefaultValue = BarShapes.Round)]
@@ -28,57 +27,56 @@ public partial class StorageBar
2827

2928
partial void OnValueBarHeightChanged(double newValue)
3029
{
31-
UpdateControl(this);
30+
UpdateControl();
3231
}
3332

3433
partial void OnTrackBarHeightChanged(double newValue)
3534
{
36-
UpdateControl(this);
35+
UpdateControl();
3736
}
3837

3938
partial void OnBarShapeChanged(BarShapes newValue)
4039
{
41-
UpdateControl(this);
40+
UpdateControl();
4241
}
4342

4443
partial void OnPercentChanged(double newValue)
4544
{
4645
return; //Read-only
47-
48-
DoubleToPercentage(Value, Minimum, Maximum);
49-
UpdateControl(this);
5046
}
5147

5248
partial void OnPercentCautionChanged(double newValue)
5349
{
54-
UpdateControl(this);
50+
UpdateControl();
5551
}
5652

5753
partial void OnPercentCriticalChanged(double newValue)
5854
{
59-
UpdateControl(this);
55+
UpdateControl();
6056
}
6157

6258
/// <inheritdoc/>
6359
protected override void OnValueChanged(double oldValue, double newValue)
6460
{
65-
_oldValue = oldValue;
6661
base.OnValueChanged(oldValue, newValue);
67-
UpdateValue(this, Value, _oldValue, false, -1.0);
62+
63+
UpdateValue(Value, _oldValue, false, -1.0);
6864
}
6965

7066
/// <inheritdoc/>
7167
protected override void OnMaximumChanged(double oldValue, double newValue)
7268
{
7369
base.OnMaximumChanged(oldValue, newValue);
74-
UpdateValue(this, oldValue, newValue, false, -1.0);
70+
71+
UpdateValue(oldValue, newValue, false, -1.0);
7572
}
7673

7774
/// <inheritdoc/>
7875
protected override void OnMinimumChanged(double oldValue, double newValue)
7976
{
8077
base.OnMinimumChanged(oldValue, newValue);
81-
UpdateValue(this, oldValue, newValue, false, -1.0);
78+
79+
UpdateValue(oldValue, newValue, false, -1.0);
8280
}
8381
}
8482
}

0 commit comments

Comments
 (0)