Skip to content

Commit

Permalink
Merge pull request #82 from SiMet/master
Browse files Browse the repository at this point in the history
Fixes for issues:
  • Loading branch information
wieslawsoltes authored Oct 31, 2024
2 parents 6008600 + 23f0656 commit 7ca13f2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ public partial class ZoomBorder : ILogicalScrollable
/// Calculate scrollable properties.
/// </summary>
/// <param name="source">The source bounds.</param>
/// <param name="borderSize">The size of border (this control)</param>
/// <param name="matrix">The transform matrix.</param>
/// <param name="extent">The extent of the scrollable content.</param>
/// <param name="viewport">The size of the viewport.</param>
/// <param name="offset">The current scroll offset.</param>
public static void CalculateScrollable(Rect source, Matrix matrix, out Size extent, out Size viewport, out Vector offset)
public static void CalculateScrollable(Rect source, Size borderSize, Matrix matrix, out Size extent, out Size viewport, out Vector offset)
{
var bounds = new Rect(0, 0, source.Width, source.Height);

viewport = bounds.Size;
viewport = borderSize;

var transformed = bounds.TransformToAABB(matrix);

Expand Down Expand Up @@ -188,7 +189,7 @@ private void InvalidateScrollable()
return;
}

CalculateScrollable(_element.Bounds, _matrix, out var extent, out var viewport, out var offset);
CalculateScrollable(_element.Bounds, this.Bounds.Size, _matrix, out var extent, out var viewport, out var offset);

Log($"[InvalidateScrollable] _element.Bounds: {_element.Bounds}, _matrix: {_matrix}");
Log($"[InvalidateScrollable] _extent: {_extent}, extent: {extent}, diff: {extent - _extent}");
Expand Down
22 changes: 20 additions & 2 deletions src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using Avalonia.Controls.Metadata;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Transformation;
Expand All @@ -11,6 +12,8 @@ namespace Avalonia.Controls.PanAndZoom;
/// <summary>
/// Pan and zoom control for Avalonia.
/// </summary>

[PseudoClasses(":isPanning")]
public partial class ZoomBorder : Border
{
[Conditional("DEBUG")]
Expand Down Expand Up @@ -136,10 +139,18 @@ private void Border_PointerMoved(object? sender, PointerEventArgs e)
Moved(e);
}

private void Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if(e.Property == BoundsProperty)
{
InvalidateScrollable();
}
}

private void BoundsChanged(Rect bounds)
{
// Log($"[BoundsChanged] {bounds}");
//InvalidateScrollable();
InvalidateScrollable();
}

private void ChildChanged(Control? element)
Expand All @@ -164,6 +175,7 @@ private void AttachElement(Control? element)
return;
}
_element = element;
_element.PropertyChanged += Element_PropertyChanged;

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 178 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).
PointerWheelChanged += Border_PointerWheelChanged;
PointerPressed += Border_PointerPressed;
PointerReleased += Border_PointerReleased;
Expand All @@ -176,10 +188,12 @@ private void DetachElement()
{
return;
}

PointerWheelChanged -= Border_PointerWheelChanged;
PointerPressed -= Border_PointerPressed;
PointerReleased -= Border_PointerReleased;
PointerMoved -= Border_PointerMoved;
_element.PropertyChanged -= Element_PropertyChanged;

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).

Check warning on line 196 in src/Avalonia.Controls.PanAndZoom/ZoomBorder.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Nullability of reference types in type of parameter 'sender' of 'void ZoomBorder.Element_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)' doesn't match the target delegate 'EventHandler<AvaloniaPropertyChangedEventArgs>' (possibly because of nullability attributes).
_element.RenderTransform = null;
_element = null;
}
Expand Down Expand Up @@ -214,6 +228,7 @@ private void Pressed(PointerPressedEventArgs e)
BeginPanTo(point.X, point.Y);
_captured = true;
_isPanning = true;
SetPseudoClass(":isPanning", _isPanning);
}
}

Expand All @@ -229,6 +244,7 @@ private void Released(PointerReleasedEventArgs e)
}
_captured = false;
_isPanning = false;
SetPseudoClass(":isPanning", _isPanning);
}

private void Moved(PointerEventArgs e)
Expand Down Expand Up @@ -426,7 +442,7 @@ public void ZoomTo(double ratio, double x, double y, bool skipTransitions = fals
{
return;
}

_updating = true;

Log("[ZoomTo]");
Expand Down Expand Up @@ -792,4 +808,6 @@ public void AutoFit(bool skipTransitions = false)
}
AutoFit(Bounds.Width, Bounds.Height, _element.Bounds.Width, _element.Bounds.Height, skipTransitions);
}

private void SetPseudoClass(string name, bool flag) => PseudoClasses.Set(name, flag);
}
63 changes: 45 additions & 18 deletions tests/Avalonia.Controls.PanAndZoom.UnitTests/ZoomBorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,34 @@ public void CalculateMatrix_StretchMode_UniformToFill()
[Fact]
public void CalculateScrollable_Default()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 100, 100);
var matrix = CreateMatrix();
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(100, 100), extent);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
}

[Fact]
public void CalculateScrollable_ViewportSmallerThenContent()
{
var borderSize = new Size(100, 100);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix();
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 300), extent);
Assert.Equal(new Size(100, 100), viewport);
Assert.Equal(new Vector(0, 0), offset);
}

[Fact]
public void CalculateScrollable_OffsetX_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(offsetX: -100);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(400, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(100, 0), offset);
Expand All @@ -117,9 +131,10 @@ public void CalculateScrollable_OffsetX_Negative()
[Fact]
public void CalculateScrollable_OffsetX_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(offsetX: 100);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(400, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -128,9 +143,10 @@ public void CalculateScrollable_OffsetX_Positive()
[Fact]
public void CalculateScrollable_OffsetY_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(offsetY: -100);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 400), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 100), offset);
Expand All @@ -139,9 +155,10 @@ public void CalculateScrollable_OffsetY_Negative()
[Fact]
public void CalculateScrollable_OffsetY_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(offsetY: 100);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 400), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -150,9 +167,10 @@ public void CalculateScrollable_OffsetY_Positive()
[Fact]
public void CalculateScrollable_ZoomIn_2x()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 2, scaleY: 2);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(600, 600), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -161,9 +179,10 @@ public void CalculateScrollable_ZoomIn_2x()
[Fact]
public void CalculateScrollable_ZoomIn_2x_OffsetX_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 2, scaleY: 2, offsetX: -150);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(600, 600), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(150, 0), offset);
Expand All @@ -172,9 +191,10 @@ public void CalculateScrollable_ZoomIn_2x_OffsetX_Negative()
[Fact]
public void CalculateScrollable_ZoomIn_2x_OffsetX_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 2, scaleY: 2, offsetX: 150);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(600, 600), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -183,9 +203,10 @@ public void CalculateScrollable_ZoomIn_2x_OffsetX_Positive()
[Fact]
public void CalculateScrollable_ZoomIn_2x_OffsetY_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 2, scaleY: 2, offsetY: -150);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds,borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(600, 600), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 150), offset);
Expand All @@ -194,9 +215,10 @@ public void CalculateScrollable_ZoomIn_2x_OffsetY_Negative()
[Fact]
public void CalculateScrollable_ZoomIn_2x_OffsetY_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 2, scaleY: 2, offsetY: 150);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(600, 600), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -205,9 +227,10 @@ public void CalculateScrollable_ZoomIn_2x_OffsetY_Positive()
[Fact]
public void CalculateScrollable_ZoomOut_0_5x()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 0.5, scaleY: 0.5);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -216,9 +239,10 @@ public void CalculateScrollable_ZoomOut_0_5x()
[Fact]
public void CalculateScrollable_ZoomOut_0_5x_OffsetX_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 0.5, scaleY: 0.5, offsetX: -200);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(500, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(200, 0), offset);
Expand All @@ -227,9 +251,10 @@ public void CalculateScrollable_ZoomOut_0_5x_OffsetX_Negative()
[Fact]
public void CalculateScrollable_ZoomOut_0_5x_OffsetX_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 0.5, scaleY: 0.5, offsetX: 200);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(350, 300), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
Expand All @@ -238,9 +263,10 @@ public void CalculateScrollable_ZoomOut_0_5x_OffsetX_Positive()
[Fact]
public void CalculateScrollable_ZoomOut_0_5x_OffsetY_Negative()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 0.5, scaleY: 0.5, offsetY: -200);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 500), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 200), offset);
Expand All @@ -249,11 +275,12 @@ public void CalculateScrollable_ZoomOut_0_5x_OffsetY_Negative()
[Fact]
public void CalculateScrollable_ZoomOut_0_5x_OffsetY_Positive()
{
var borderSize = new Size(300, 300);
var bounds = new Rect(0, 0, 300, 300);
var matrix = CreateMatrix(scaleX: 0.5, scaleY: 0.5, offsetY: 200);
ZoomBorder.CalculateScrollable(bounds, matrix, out var extent, out var viewport, out var offset);
ZoomBorder.CalculateScrollable(bounds, borderSize, matrix, out var extent, out var viewport, out var offset);
Assert.Equal(new Size(300, 350), extent);
Assert.Equal(new Size(300, 300), viewport);
Assert.Equal(new Vector(0, 0), offset);
}
}
}

0 comments on commit 7ca13f2

Please sign in to comment.