Skip to content

Commit

Permalink
wip: scrolling refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Oct 17, 2024
1 parent f8e4153 commit ff4ee69
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 207 deletions.
2 changes: 2 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/ZoomContentControlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace Uno.Toolkit.RuntimeTests.Tests
{
#if false
[TestClass]
[RunsOnUIThread]
internal class ZoomContentControlTest
Expand Down Expand Up @@ -220,4 +221,5 @@ public async Task When_Pan_ShouldUpdateOffsets()
translation.Y.Should().Be(50);
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,14 @@ namespace Uno.Toolkit.UI;

public partial class ZoomContentControl
{
#region DependencyProperty: HorizontalOffset

/// <summary>Identifies the HorizontalOffset dependency property.</summary>
public static DependencyProperty HorizontalOffsetProperty { get; } = DependencyProperty.Register(
nameof(HorizontalOffset),
typeof(double),
typeof(ZoomContentControl),
new PropertyMetadata(default(double), OnHorizontalOffsetChanged));

/// <summary>Gets or sets the horizontal offset for panning the content.</summary>
public double HorizontalOffset
{
get => (double)GetValue(HorizontalOffsetProperty);
set => SetValue(HorizontalOffsetProperty, value);
}

#endregion
#region DependencyProperty: HorizontalScrollValue

/// <summary>Identifies the HorizontalScrollValue dependency property.</summary>
public static DependencyProperty HorizontalScrollValueProperty { get; } = DependencyProperty.Register(
nameof(HorizontalScrollValue),
typeof(double),
typeof(ZoomContentControl),
new PropertyMetadata(default(double)));
new PropertyMetadata(default(double), OnHorizontalScrollValueChanged));

/// <summary>Gets or sets the value of the horizontal scrollbar. It's used to represent the scroll position within the scroll bar UI.</summary>
public double HorizontalScrollValue
{
get => (double)GetValue(HorizontalScrollValueProperty);
Expand Down Expand Up @@ -119,22 +100,37 @@ public double HorizontalZoomCenter
set => SetValue(HorizontalZoomCenterProperty, value);
}

#endregion
#region DependencyProperty: IsHorizontalScrollBarVisible

/// <summary>Identifies the IsHorizontalScrollBarVisible dependency property.</summary>
public static DependencyProperty IsHorizontalScrollBarVisibleProperty { get; } = DependencyProperty.Register(
nameof(IsHorizontalScrollBarVisible),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether the horizontal scrollbar is visible.</summary>
public bool IsHorizontalScrollBarVisible
{
get => (bool)GetValue(IsHorizontalScrollBarVisibleProperty);
set => SetValue(IsHorizontalScrollBarVisibleProperty, value);
}

#endregion

#region DependencyProperty: VerticalOffset
#region DependencyProperty: VerticalScrollValue

/// <summary>Identifies the VerticalOffset dependency property.</summary>
public static DependencyProperty VerticalOffsetProperty { get; } = DependencyProperty.Register(
nameof(VerticalOffset),
public static DependencyProperty VerticalScrollValueProperty { get; } = DependencyProperty.Register(
nameof(VerticalScrollValue),
typeof(double),
typeof(ZoomContentControl),
new PropertyMetadata(default(double), OnVerticalOffsetChanged));
new PropertyMetadata(default(double), OnVerticalScrollValueChanged));

/// <summary>Gets or sets the vertical offset for panning the content.</summary>
public double VerticalOffset
public double VerticalScrollValue
{
get => (double)GetValue(VerticalOffsetProperty);
set => SetValue(VerticalOffsetProperty, value);
get => (double)GetValue(VerticalScrollValueProperty);
set => SetValue(VerticalScrollValueProperty, value);
}

#endregion
Expand Down Expand Up @@ -188,6 +184,23 @@ public double VerticalZoomCenter
set => SetValue(VerticalZoomCenterProperty, value);
}

#endregion
#region DependencyProperty: IsVerticalScrollBarVisible

/// <summary>Identifies the IsVerticalScrollBarVisible dependency property.</summary>
public static DependencyProperty IsVerticalScrollBarVisibleProperty { get; } = DependencyProperty.Register(
nameof(IsVerticalScrollBarVisible),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether the vertical scrollbar is visible.</summary>
public bool IsVerticalScrollBarVisible
{
get => (bool)GetValue(IsVerticalScrollBarVisibleProperty);
set => SetValue(IsVerticalScrollBarVisibleProperty, value);
}

#endregion

#region DependencyProperty: ZoomLevel
Expand Down Expand Up @@ -241,7 +254,41 @@ public double MaxZoomLevel
}

#endregion
#region DependencyProperty: IsZoomAllowed

/// <summary>Identifies the IsZoomAllowed dependency property.</summary>
public static DependencyProperty IsZoomAllowedProperty { get; } = DependencyProperty.Register(
nameof(IsZoomAllowed),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether zooming is allowed.</summary>
public bool IsZoomAllowed
{
get => (bool)GetValue(IsZoomAllowedProperty);
set => SetValue(IsZoomAllowedProperty, value);
}

#endregion

#region DependencyProperty: ScaleWheelRatio

/// <summary>Identifies the ScaleWheelRatio dependency property.</summary>
public static DependencyProperty ScaleWheelRatioProperty { get; } = DependencyProperty.Register(
nameof(ScaleWheelRatio),
typeof(double),
typeof(ZoomContentControl),
new PropertyMetadata(0.0006d));

/// <summary>Gets or sets the ratio used for scaling the zoom level with the mouse wheel.</summary>
public double ScaleWheelRatio
{
get => (double)GetValue(ScaleWheelRatioProperty);
set => SetValue(ScaleWheelRatioProperty, value);
}

#endregion
#region DependencyProperty: PanWheelRatio

/// <summary>Identifies the PanWheelRatio dependency property.</summary>
Expand All @@ -259,20 +306,20 @@ public double PanWheelRatio
}

#endregion
#region DependencyProperty: ScaleWheelRatio
#region DependencyProperty: IsPanAllowed

/// <summary>Identifies the ScaleWheelRatio dependency property.</summary>
public static DependencyProperty ScaleWheelRatioProperty { get; } = DependencyProperty.Register(
nameof(ScaleWheelRatio),
typeof(double),
/// <summary>Identifies the IsPanAllowed dependency property.</summary>
public static DependencyProperty IsPanAllowedProperty { get; } = DependencyProperty.Register(
nameof(IsPanAllowed),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(0.0006d));
new PropertyMetadata(true));

/// <summary>Gets or sets the ratio used for scaling the zoom level with the mouse wheel.</summary>
public double ScaleWheelRatio
/// <summary>Gets or sets a value indicating whether panning is allowed.</summary>
public bool IsPanAllowed
{
get => (double)GetValue(ScaleWheelRatioProperty);
set => SetValue(ScaleWheelRatioProperty, value);
get => (bool)GetValue(IsPanAllowedProperty);
set => SetValue(IsPanAllowedProperty, value);
}

#endregion
Expand Down Expand Up @@ -328,74 +375,6 @@ public bool IsActive
set => SetValue(IsActiveProperty, value);
}

#endregion
#region DependencyProperty: IsZoomAllowed

/// <summary>Identifies the IsZoomAllowed dependency property.</summary>
public static DependencyProperty IsZoomAllowedProperty { get; } = DependencyProperty.Register(
nameof(IsZoomAllowed),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether zooming is allowed.</summary>
public bool IsZoomAllowed
{
get => (bool)GetValue(IsZoomAllowedProperty);
set => SetValue(IsZoomAllowedProperty, value);
}

#endregion
#region DependencyProperty: IsHorizontalScrollBarVisible

/// <summary>Identifies the IsHorizontalScrollBarVisible dependency property.</summary>
public static DependencyProperty IsHorizontalScrollBarVisibleProperty { get; } = DependencyProperty.Register(
nameof(IsHorizontalScrollBarVisible),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether the horizontal scrollbar is visible.</summary>
public bool IsHorizontalScrollBarVisible
{
get => (bool)GetValue(IsHorizontalScrollBarVisibleProperty);
set => SetValue(IsHorizontalScrollBarVisibleProperty, value);
}

#endregion
#region DependencyProperty: IsPanAllowed

/// <summary>Identifies the IsPanAllowed dependency property.</summary>
public static DependencyProperty IsPanAllowedProperty { get; } = DependencyProperty.Register(
nameof(IsPanAllowed),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether panning is allowed.</summary>
public bool IsPanAllowed
{
get => (bool)GetValue(IsPanAllowedProperty);
set => SetValue(IsPanAllowedProperty, value);
}

#endregion
#region DependencyProperty: IsVerticalScrollBarVisible

/// <summary>Identifies the IsVerticalScrollBarVisible dependency property.</summary>
public static DependencyProperty IsVerticalScrollBarVisibleProperty { get; } = DependencyProperty.Register(
nameof(IsVerticalScrollBarVisible),
typeof(bool),
typeof(ZoomContentControl),
new PropertyMetadata(true));

/// <summary>Gets or sets a value indicating whether the vertical scrollbar is visible.</summary>
public bool IsVerticalScrollBarVisible
{
get => (bool)GetValue(IsVerticalScrollBarVisibleProperty);
set => SetValue(IsVerticalScrollBarVisibleProperty, value);
}

#endregion
#region DependencyProperty: AutoZoomToCanvasOnSizeChanged

Expand All @@ -415,14 +394,14 @@ public bool AutoZoomToCanvasOnSizeChanged

#endregion
#region DependencyProperty: AdditionalMargin

/// <summary>Identifies the AdditionalMargin dependency property.</summary>
public static DependencyProperty AdditionalMarginProperty { get; } = DependencyProperty.Register(
nameof(AdditionalMargin),
typeof(Thickness),
typeof(ZoomContentControl),
new PropertyMetadata(new Thickness(0)));

new PropertyMetadata(Thickness.Empty, OnAdditionalMarginChanged));
/// <summary>Gets or sets additional margins around the content.</summary>
public Thickness AdditionalMargin
{
Expand All @@ -449,10 +428,11 @@ public BoundsVisibilityFlag ContentBoundsVisibility

#endregion

private static void OnHorizontalOffsetChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnHorizontalOffsetChanged();
private static void OnVerticalOffsetChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnVerticalOffsetChanged();
private static void OnHorizontalScrollValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnHorizontalScrollValueChanged();
private static void OnVerticalScrollValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnVerticalScrollValueChanged();
private static void OnZoomLevelChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnZoomLevelChanged();
private static void OnMinZoomLevelChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).CoerceZoomLevel();
private static void OnMaxZoomLevelChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).CoerceZoomLevel();
private static void OnIsActiveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).IsActiveChanged();
private static void OnAdditionalMarginChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => ((ZoomContentControl)sender).OnAdditionalMarginChanged();
}
Loading

0 comments on commit ff4ee69

Please sign in to comment.