From 50153c3ba97b6326ff8d851f86eb7a50fa5cce87 Mon Sep 17 00:00:00 2001 From: Mark Otway Date: Mon, 1 Jan 2024 12:39:50 +0000 Subject: [PATCH] Code style --- .editorconfig | 15 +++ .../Components/General/Bricks.razor.css | 4 +- Damselfly.Web.Client/Shared/ImageCanvas.razor | 119 +++++++++--------- 3 files changed, 80 insertions(+), 58 deletions(-) diff --git a/.editorconfig b/.editorconfig index 74abe078..7972ea2a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -44,6 +44,21 @@ dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_property = false:suggestion dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion +# Start of NO underscore prefix on private fields +# Define the 'private_fields' symbol group: +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private + +# Define the 'notunderscored' naming style +dotnet_naming_style.notunderscored.capitalization = camel_case +dotnet_naming_style.notunderscored.required_prefix = + +# Define the 'private_fields_notunderscored' naming rule +dotnet_naming_rule.private_fields_notunderscored.symbols = private_fields +dotnet_naming_rule.private_fields_notunderscored.style = notunderscored +dotnet_naming_rule.private_fields_notunderscored.severity = error +# End of No underscore prefix on private fields + # ReSharper properties resharper_autodetect_indent_settings = true resharper_csharp_extra_spaces = leave_all diff --git a/Damselfly.Web.Client/Components/General/Bricks.razor.css b/Damselfly.Web.Client/Components/General/Bricks.razor.css index de463571..9e5ab2c1 100644 --- a/Damselfly.Web.Client/Components/General/Bricks.razor.css +++ b/Damselfly.Web.Client/Components/General/Bricks.razor.css @@ -15,7 +15,7 @@ display: flex; align-items: center; margin: 2px; - padding: 2px 1px 1px 0px; + padding: 2px 1px 1px; flex-wrap: nowrap; font-size: 9pt; cursor: default; @@ -32,7 +32,7 @@ } .bricktext-label { - margin: 0 2px 0 2px; + margin: 5px 2px 0 2px; text-wrap: none; flex: 0 1 auto; } diff --git a/Damselfly.Web.Client/Shared/ImageCanvas.razor b/Damselfly.Web.Client/Shared/ImageCanvas.razor index 3a3bee6d..0ec72642 100644 --- a/Damselfly.Web.Client/Shared/ImageCanvas.razor +++ b/Damselfly.Web.Client/Shared/ImageCanvas.razor @@ -48,7 +48,7 @@ @code { [Parameter] - public Image Image { get; set; } + public Image? Image { get; set; } [Parameter] public string Class { get; set; } @@ -57,7 +57,7 @@ private string CropTooltip => isCropping ? "Click to apply crop" : "Click to start crop mode"; private SKBlendMode mode = SKBlendMode.Color; - private SKGLView glViewRef; + private SKGLView? glViewRef; private SKBitmap? sourceBitmap; private int currentImageId = 0; private CancellationTokenSource loadCancellationSource = new(); @@ -76,7 +76,7 @@ private SKRect paintArea = new SKRect(0, 0, 0, 0); private float paintScale = 0f; - private float lastDPI = 1.0f; + private float lastDpi = 1.0f; private float zoomAmount = 0.0f; private SKPoint zoomOffset = new SKPoint(); @@ -97,30 +97,33 @@ /// private void DoRotate(int degrees) { - var oldBitmap = sourceBitmap; + if( Image != null ) + { + var oldBitmap = sourceBitmap; - rotation += degrees; - if (rotation >= 360) - rotation = 0; - if (rotation < 0) - rotation = 270; + rotation += degrees; + if ( rotation >= 360 ) + rotation = 0; + if ( rotation < 0 ) + rotation = 270; - tagService.SetExifFieldAsync(new[] { Image.ImageId }, ExifOperation.ExifType.Rotate, rotation.ToString() ); + tagService.SetExifFieldAsync(new[] { Image.ImageId }, ExifOperation.ExifType.Rotate, rotation.ToString() ); - sourceBitmap = Rotate(oldBitmap, degrees); - oldBitmap.Dispose(); - ClearCrop(); - Repaint(); + sourceBitmap = Rotate(oldBitmap, degrees); + oldBitmap.Dispose(); + ClearCrop(); + Repaint(); + } } private SKRect? GetDragRect() { if (dragStart.HasValue && dragEnd.HasValue) { - SKRect rect = new SKRect(dragStart.Value.X * lastDPI, - dragStart.Value.Y * lastDPI, - dragEnd.Value.X * lastDPI, - dragEnd.Value.Y * lastDPI); + SKRect rect = new SKRect(dragStart.Value.X * lastDpi, + dragStart.Value.Y * lastDpi, + dragEnd.Value.X * lastDpi, + dragEnd.Value.Y * lastDpi); if (rect.Left > rect.Right) { @@ -196,7 +199,7 @@ if (obj != null) dpi = (double)obj.GetValue(glViewRef)!; - lastDPI = (float)dpi; + lastDpi = (float)dpi; } private SKPoint GetCoords(MouseEventArgs e) @@ -272,57 +275,61 @@ private async Task LoadImage(CancellationToken token) { - var url = Image.ThumbUrl(ThumbSize.Medium); - - SKBitmap? bmp = null; - try + if( Image != null ) { - using var imageStream = await restClient.GetStreamAsync(url, token); + var url = Image.ThumbUrl(ThumbSize.Medium); - bmp = LoadOriented(imageStream); + try + { + using var imageStream = await restClient.GetStreamAsync(url, token); - if (bmp != null && !token.IsCancellationRequested) + var bmp = LoadOriented(imageStream); + + if ( !token.IsCancellationRequested ) + { + logger.LogInformation($"Loaded image {url} successfully"); + SetBitmap(bmp); + } + else + logger.LogError($"Failed to decode {url} - bitmap was null"); + } + catch ( OperationCanceledException ) { - logger.LogInformation($"Loaded image {url} successfully"); - SetBitmap(bmp); + logger.LogWarning($"Cancelling low-res load as hi-res image is already loaded {url}"); + } + catch ( Exception ex ) + { + logger.LogError($"Unable to load image {url}: {ex}"); } - else - logger.LogError($"Failed to decode {url} - bitmap was null"); - } - catch (OperationCanceledException) - { - logger.LogWarning($"Cancelling low-res load as hi-res image is already loaded {url}"); - } - catch (Exception ex) - { - logger.LogError($"Unable to load image {url}: {ex}"); } } private async Task LoadHiResImage() { - var url = Image.ThumbUrl(ThumbSize.ExtraLarge); - - SKBitmap? bmp = null; - try + if( Image != null ) { - using var imageStream = await restClient.GetStreamAsync(url); + var url = Image.ThumbUrl(ThumbSize.ExtraLarge); + + try + { + using var imageStream = await restClient.GetStreamAsync(url); - bmp = SKBitmap.Decode(imageStream); + var bmp = SKBitmap.Decode(imageStream); - if (bmp != null) + if ( bmp != null ) + { + logger.LogInformation($"Loaded hi-res image {url} successfully"); + // Cancel the low-res load. + loadCancellationSource.Cancel(); + SetBitmap(bmp); + } + else + logger.LogError($"Failed to decode hi-res {url} - bitmap was null"); + } + catch ( Exception ex ) { - logger.LogInformation($"Loaded hi-res image {url} successfully"); - // Cancel the low-res load. - loadCancellationSource.Cancel(); - SetBitmap(bmp); + logger.LogError($"Unable to load hi-res image {url}: {ex}"); } - else - logger.LogError($"Failed to decode hi-res {url} - bitmap was null"); - } - catch (Exception ex) - { - logger.LogError($"Unable to load hi-res image {url}: {ex}"); } } @@ -508,7 +515,7 @@ StrokeCap = SKStrokeCap.Round, StrokeWidth = 2f, Color = SKColor.Parse("#ffffff"), - PathEffect = SKPathEffect.CreateDash(new[] { 5 * lastDPI, 2 * lastDPI }, 20) + PathEffect = SKPathEffect.CreateDash(new[] { 5 * lastDpi, 2 * lastDpi }, 20) }; canvas.DrawRect(dragRect.Value, dragBorder);