Fix QRCode render issues.
MODIFY
WalletWasabi.Gui/Controls/QrCode.cs
WalletWasabi.Gui/Controls/QrCode.cs
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
+using Avalonia.Media.Imaging;
using Avalonia.Metadata;
+using Avalonia.Platform;
+using ReactiveUI;
using System;
+using System.Reactive.Linq;
namespace WalletWasabi.Gui.Controls
{
public class QrCode : Control
{
+ private readonly int _matrixPadding;
+ private Size _coercedSize;
+ private double _factor;
+
static QrCode()
{
AffectsMeasure<QrCode>(MatrixProperty);
}
+ public QrCode()
+ {
+ _coercedSize = new Size();
+ _matrixPadding = 2;
+
+ this.WhenAnyValue(x => x.Matrix)
+ .Where(x => x != null)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(x => _matrix = AddPaddingToMatrix(x));
+ }
+
public static readonly DirectProperty<QrCode, bool[,]> MatrixProperty =
- AvaloniaProperty.RegisterDirect<QrCode, bool[,]>(nameof(Matrix), o => o.Matrix, (o, v) => o.Matrix = v);
+ AvaloniaProperty.RegisterDirect<QrCode, bool[,]>(
+ nameof(Matrix),
+ o => o.Matrix,
+ (o, v) => o.Matrix = v);
private bool[,] _matrix;
@@ -25,31 +47,49 @@ namespace WalletWasabi.Gui.Controls
set => SetAndRaise(MatrixProperty, ref _matrix, value);
}
+ private bool[,] AddPaddingToMatrix(bool[,] matrix)
+ {
+ var dims = GetMatrixDimensions(matrix);
+ var nW = dims.W + (_matrixPadding * 2);
+ var nH = dims.H + (_matrixPadding * 2);
+
+ var paddedMatrix = new bool[nH, nW];
+
+ for (var i = 0; i < dims.H; i++)
+ for (var j = 0; j < dims.W; j++)
+ {
+ paddedMatrix[i + _matrixPadding, j + _matrixPadding] = matrix[i, j];
+ }
+
+ return paddedMatrix;
+ }
+
public override void Render(DrawingContext context)
{
var source = Matrix;
- if (source != null)
+ if (source is null)
{
- var h = source.GetUpperBound(0) + 1;
- var w = source.GetUpperBound(1) + 1;
+ return;
+ }
- var minDimension = Math.Min(w, h);
- var minBound = Math.Min(Bounds.Width, Bounds.Height);
- var factor = (float)minBound / minDimension;
+ var dims = GetMatrixDimensions(source);
- for (var i = 0; i < h; i++)
- {
- for (var j = 0; j < w; j++)
+ context.FillRectangle(Brushes.White, new Rect(0, 0, _factor * dims.W, _factor * dims.H));
+
+ for (var i = 0; i < dims.H; i++)
+ for (var j = 0; j < dims.W; j++)
{
var cellValue = source[i, j];
- var rect = new Rect(i * factor, j * factor, factor, factor);
+ var rect = new Rect(i * _factor, j * _factor, _factor, _factor);
var color = cellValue ? Brushes.Black : Brushes.White;
context.FillRectangle(color, rect);
}
}
- }
- }
+
+ private (int W, int H) GetMatrixDimensions(bool[,] source)
+ => (source.GetUpperBound(0) + 1,
+ source.GetUpperBound(1) + 1);
protected override Size MeasureOverride(Size availableSize)
{
@@ -60,11 +100,17 @@ namespace WalletWasabi.Gui.Controls
return new Size();
}
- var max = Math.Min(availableSize.Width, availableSize.Height);
+ var dims = GetMatrixDimensions(source);
+ var minDimension = Math.Min(dims.W, dims.H);
+ var availMax = Math.Min(availableSize.Width, availableSize.Height);
+
+ _factor = Math.Floor(availMax / minDimension);
+
+ var maxF = Math.Min(availMax, _factor * minDimension);
- var size = new Size(max, max);
+ _coercedSize = new Size(maxF, maxF);
- return size;
+ return _coercedSize;
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
<DataTemplate>
<Grid>
<Expander Name="coinExpander" ExpandDirection="Down" IsExpanded="{Binding IsExpanded}" Classes="coloredExpander" Background="{Binding ElementName=coinExpander, Path=IsExpanded, Converter={StaticResource CoinItemExpanderColorConverter}}">
- <StackPanel Orientation="Horizontal" Spacing="16" Margin="35 10 0 25">
- <Panel Height="220" Background="#FFFEFEFE">
- <controls:QrCode Matrix="{Binding QrCode}" HorizontalAlignment="Left" Margin="20" />
+ <StackPanel Orientation="Horizontal" Spacing="16" Margin="35 10 0 5">
+ <Panel Height="220">
+ <controls:QrCode Matrix="{Binding QrCode}" HorizontalAlignment="Left" />
</Panel>
<Grid ColumnDefinitions="140, *" RowDefinitions="22,22" Margin="6">
<TextBlock Classes="monospaceFont" Text="Public key:" Grid.Row="0" Grid.Column="0" />

Fix QRCode render issues.