Skip to content

Commit c06428b

Browse files
committed
Fix various remarks
1 parent 712db9c commit c06428b

3 files changed

Lines changed: 43 additions & 47 deletions

File tree

src/HierarchyGrid.Definitions/HierarchyGridViewModel.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,23 @@ public Seq<PositionedCell> Selections
140140
public ConcurrentBag<(
141141
ElementCoordinates Coord,
142142
PositionedDefinition Definition
143-
)> HeadersCoordinates { get; } = new();
143+
)> HeadersCoordinates { get; } = [];
144144

145145
/// <summary>
146146
/// Represents a collection of tuples that associate the coordinates of grid elements with their corresponding positioned cells.
147147
/// </summary>
148148
public ConcurrentBag<(
149149
ElementCoordinates Coord,
150150
PositionedCell Cell
151-
)> CellsCoordinates { get; } = new();
151+
)> CellsCoordinates { get; } = [];
152152

153153
private HashMap<(int Row, int Column), PositionedCell> CellsCoordinatesMap { get; set; }
154154

155155
public ConcurrentBag<(
156156
ElementCoordinates Coord,
157157
Guid Guid,
158158
Action Action
159-
)> GlobalHeadersCoordinates { get; } = new();
159+
)> GlobalHeadersCoordinates { get; } = [];
160160

161161
[Reactive]
162162
public partial int HorizontalOffset { get; set; }
@@ -239,33 +239,41 @@ public void SetGridState(HierarchyGridState state, bool useCompare = false)
239239
{
240240
var rowsFlat = RowsDefinitions.FlatList();
241241
if (rowsFlat.Length == state.RowToggles.Length)
242+
{
242243
Parallel.For(
243244
0,
244245
state.RowToggles.Length,
245246
i => rowsFlat[i].IsExpanded = state.RowToggles[i]
246247
);
248+
}
247249
else
250+
{
248251
rowsFlat
249252
.AsParallel()
250253
.ForAll(x =>
251254
{
252255
x.IsExpanded = true;
253256
});
257+
}
254258

255259
var columnsFlat = ColumnsDefinitions.FlatList();
256260
if (columnsFlat.Length == state.ColumnToggles.Length)
261+
{
257262
Parallel.For(
258263
0,
259264
state.ColumnToggles.Length,
260265
i => columnsFlat[i].IsExpanded = state.ColumnToggles[i]
261266
);
267+
}
262268
else
269+
{
263270
columnsFlat
264271
.AsParallel()
265272
.ForAll(x =>
266273
{
267274
x.IsExpanded = true;
268275
});
276+
}
269277

270278
VerticalOffset = state.VerticalOffset;
271279
HorizontalOffset = state.HorizontalOffset;
@@ -618,15 +626,15 @@ public void Set(HierarchyDefinitions hierarchyDefinitions, bool preserveSizes =
618626
var rowDefinitions = Producers;
619627
var columnDefinitions = Consumers;
620628

621-
RowsHeadersWidth = Enumerable
622-
.Range(0, rowDefinitions.TotalDepth())
623-
.Select(_ => DefaultHeaderWidth)
624-
.ToArray();
629+
RowsHeadersWidth =
630+
[
631+
.. Enumerable.Range(0, rowDefinitions.TotalDepth()).Select(_ => DefaultHeaderWidth)
632+
];
625633

626-
ColumnsHeadersHeight = Enumerable
627-
.Range(0, columnDefinitions.TotalDepth())
628-
.Select(_ => DefaultHeaderHeight)
629-
.ToArray();
634+
ColumnsHeadersHeight =
635+
[
636+
.. Enumerable.Range(0, columnDefinitions.TotalDepth()).Select(_ => DefaultHeaderHeight)
637+
];
630638

631639
var columnsCount = columnDefinitions.TotalCount(true);
632640
if (!preserveSizes || columnsCount != ColumnsWidths.Count)
@@ -959,6 +967,11 @@ bool isRightClick
959967
}
960968
}
961969

970+
[System.Diagnostics.CodeAnalysis.SuppressMessage(
971+
"Performance",
972+
"CA1868:Unnecessary call to 'Contains(item)'",
973+
Justification = "<Pending>"
974+
)]
962975
private void HandleMultiExtendedSelection(
963976
PositionedCell cell,
964977
bool isShiftPressed,

src/HierarchyGrid.Skia/CanvasExtensions.cs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HierarchyGrid.Skia
88
{
99
internal static class CanvasExtensions
1010
{
11-
private static Dictionary<string, Option<SKSvg>> _svgCache = new();
11+
private static readonly Dictionary<string, Option<SKSvg>> _svgCache = [];
1212

1313
private static Option<SKSvg> GetSvg(string path)
1414
{
@@ -292,10 +292,7 @@ double screenScale
292292
{
293293
double height = ComputeHeaderHeight(viewModel, hdef);
294294

295-
var top = Enumerable
296-
.Range(0, hdef.Level)
297-
.Select(x => viewModel.ColumnsHeadersHeight[x])
298-
.Sum();
295+
var top = Enumerable.Range(0, hdef.Level).Sum(x => viewModel.ColumnsHeadersHeight[x]);
299296

300297
canvas.DrawHeader(
301298
viewModel,
@@ -336,8 +333,7 @@ HierarchyDefinition hdef
336333
? viewModel.ColumnsHeadersHeight[hdef.Level]
337334
: Enumerable
338335
.Range(hdef.Level, viewModel.ColumnsHeadersHeight.Length - hdef.Level)
339-
.Select(x => viewModel.ColumnsHeadersHeight[x])
340-
.Sum();
336+
.Sum(x => viewModel.ColumnsHeadersHeight[x]);
341337
return height;
342338
}
343339

@@ -363,13 +359,9 @@ double screenScale
363359

364360
var width = Enumerable
365361
.Range(column, hdef.Count() - origin.RelativePositionFrom(hdef))
366-
.Select(x => viewModel.ColumnsWidths.GetValueOrDefault(x, 0))
367-
.Sum();
362+
.Sum(x => viewModel.ColumnsWidths.GetValueOrDefault(x, 0));
368363

369-
var top = Enumerable
370-
.Range(0, hdef.Level)
371-
.Select(x => viewModel.ColumnsHeadersHeight[x])
372-
.Sum();
364+
var top = Enumerable.Range(0, hdef.Level).Sum(x => viewModel.ColumnsHeadersHeight[x]);
373365
var height = viewModel.ColumnsHeadersHeight[hdef.Level];
374366

375367
canvas.DrawHeader(
@@ -474,14 +466,12 @@ double screenScale
474466
: Enumerable
475467
.Range(hdef.Level, viewModel.RowsHeadersWidth.Length - hdef.Level)
476468
.Where(x => x < viewModel.RowsHeadersWidth.Length)
477-
.Select(x => viewModel.RowsHeadersWidth[x])
478-
.Sum();
469+
.Sum(x => viewModel.RowsHeadersWidth[x]);
479470

480471
var left = Enumerable
481472
.Range(0, hdef.Level)
482473
.Where(x => x < viewModel.RowsHeadersWidth.Length)
483-
.Select(x => viewModel.RowsHeadersWidth[x])
484-
.Sum();
474+
.Sum(x => viewModel.RowsHeadersWidth[x]);
485475

486476
canvas.DrawHeader(
487477
viewModel,
@@ -531,14 +521,12 @@ double screenScale
531521

532522
var height = Enumerable
533523
.Range(row, hdef.Count() - origin.RelativePositionFrom(hdef))
534-
.Select(x => viewModel.RowsHeights.GetValueOrDefault(x, 0))
535-
.Sum();
524+
.Sum(x => viewModel.RowsHeights.GetValueOrDefault(x, 0));
536525

537526
var left = Enumerable
538527
.Range(0, hdef.Level)
539528
.Where(x => x < viewModel.RowsHeadersWidth.Length)
540-
.Select(x => viewModel.RowsHeadersWidth[x])
541-
.Sum();
529+
.Sum(x => viewModel.RowsHeadersWidth[x]);
542530
var width = viewModel.RowsHeadersWidth[hdef.Level];
543531

544532
canvas.DrawHeader(
@@ -711,25 +699,24 @@ GlobalHeader globalHeader
711699

712700
private static SKPath BuildFoldAllPath(float left, float top, float width, float height)
713701
{
714-
float startX = left + (width - 24) / 2;
715-
float startY = top + (height - 24) / 2;
702+
float startX = left + ((width - 24) / 2);
703+
float startY = top + ((height - 24) / 2);
716704

717705
const string data = """
718706
M19 9h-2.58l3.29-3.29a1 1 0 1 0-1.42-1.42L15 7.57V5a1 1 0 0 0-1-1 1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h5a1 1 0 0 0 0-2z
719707
M10 13H5a1 1 0 0 0 0 2h2.57l-3.28 3.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0L9 16.42V19a1 1 0 0 0 1 1 1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1z
720708
""";
721709

722710
var p = SKPath.ParseSvgPathData(data);
723-
//p.Transform(SKMatrix.CreateScale(1.5f, 1.5f));
724711
p.Transform(SKMatrix.CreateTranslation(startX, startY));
725712

726713
return p;
727714
}
728715

729716
private static SKPath BuildExpandAllPath(float left, float top, float width, float height)
730717
{
731-
float startX = left + (width - 24) / 2;
732-
float startY = top + (height - 24) / 2;
718+
float startX = left + ((width - 24) / 2);
719+
float startY = top + ((height - 24) / 2);
733720

734721
const string data = """
735722
M20 5a1 1 0 0 0-1-1h-5a1 1 0 0 0 0 2h2.57l-3.28 3.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0L18 7.42V10a1 1 0 0 0 1 1 1 1 0 0 0 1-1z
@@ -751,7 +738,7 @@ private static SKPath BuildFoldedPath(
751738
{
752739
var startPoint =
753740
width > 0f && height > 0f
754-
? new SKPoint(left + (width - 24) / 2, top + (height - 24) / 2)
741+
? new SKPoint(left + ((width - 24) / 2), top + ((height - 24) / 2))
755742
: new SKPoint(3f + left, 5f + top);
756743

757744
const string data = """
@@ -773,7 +760,7 @@ private static SKPath BuildExpandedPath(
773760
{
774761
var startPoint =
775762
width > 0f && height > 0f
776-
? new SKPoint(left + (width - 24f) / 2, top + (height - 24f) / 2)
763+
? new SKPoint(left + ((width - 24f) / 2), top + ((height - 24f) / 2))
777764
: new SKPoint(3f + left, 5f + top);
778765

779766
const string data = """
@@ -892,7 +879,7 @@ private static void RenderDecor(
892879
picture.CullRect.Height > cell.Height
893880
? (float)(cell.Top * screenScale)
894881
: (float)(
895-
cell.Top + ((cell.Height - picture.CullRect.Height) / 2) * screenScale
882+
cell.Top + (screenScale * ((cell.Height - picture.CullRect.Height) / 2))
896883
);
897884

898885
canvas.DrawPicture(
@@ -1032,10 +1019,6 @@ ref SKRect rect
10321019

10331020
private static TextBlock TextDrawer { get; } = new();
10341021
private static TextPaintOptions TextPaintOptions { get; } =
1035-
new TextPaintOptions
1036-
{
1037-
Edging = SKFontEdging.SubpixelAntialias,
1038-
SubpixelPositioning = true
1039-
};
1022+
new TextPaintOptions { Edging = SKFontEdging.SubpixelAntialias };
10401023
}
10411024
}

src/HierarchyGrid.Skia/HierarchyGridDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static async Task Draw(
4646
canvas.DrawColumnHeaders(
4747
viewModel,
4848
theme,
49-
v => v.ColumnsDefinitions.Leaves().ToArray(),
49+
v => [.. v.ColumnsDefinitions.Leaves()],
5050
width,
5151
ref headerCount,
5252
screenScale
@@ -55,7 +55,7 @@ public static async Task Draw(
5555
canvas.DrawRowHeaders(
5656
viewModel,
5757
theme,
58-
v => v.RowsDefinitions.Leaves().ToArray(),
58+
v => [.. v.RowsDefinitions.Leaves()],
5959
height,
6060
ref headerCount,
6161
screenScale

0 commit comments

Comments
 (0)