1.rename AspectRatioChangeAmbiguity to AspectRatioTolerance
2.CurrentAspectRatioModeProperty to DirectProperty. 3.Fix misspelling: Updata -> Update 4.IsUseAspectRatioRange to an internal CLR property.
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
RowDefinitions="Auto,*">
|
RowDefinitions="Auto,*">
|
||||||
<StackPanel
|
<StackPanel
|
||||||
Grid.Row="0">
|
Grid.Row="0">
|
||||||
<u:NumericDoubleUpDown InnerLeftContent="AspectRatioChangeAmbiguity"
|
<u:NumericDoubleUpDown InnerLeftContent="AspectRatioTolerance"
|
||||||
Value="{Binding #AspectRatioLayout.AspectRatioChangeAmbiguity}">
|
Value="{Binding #AspectRatioLayout.AspectRatioTolerance}">
|
||||||
</u:NumericDoubleUpDown>
|
</u:NumericDoubleUpDown>
|
||||||
<TextBlock Text="{Binding #AspectRatioLayout.AspectRatioValue,StringFormat='AspectRatioValue: {0}'}"></TextBlock>
|
<TextBlock Text="{Binding #AspectRatioLayout.AspectRatioValue,StringFormat='AspectRatioValue: {0}'}"></TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ public class AspectRatioLayout : TransitioningContentControl
|
|||||||
AvaloniaProperty.Register<AspectRatioLayout, List<AspectRatioLayoutItem>>(
|
AvaloniaProperty.Register<AspectRatioLayout, List<AspectRatioLayoutItem>>(
|
||||||
nameof(Items));
|
nameof(Items));
|
||||||
|
|
||||||
public static readonly StyledProperty<double> AspectRatioChangeAmbiguityProperty =
|
public static readonly StyledProperty<double> AspectRatioToleranceProperty =
|
||||||
AvaloniaProperty.Register<AspectRatioLayout, double>(
|
AvaloniaProperty.Register<AspectRatioLayout, double>(
|
||||||
nameof(AspectRatioChangeAmbiguity), 0.2);
|
nameof(AspectRatioTolerance), 0.2);
|
||||||
|
|
||||||
public static readonly StyledProperty<AspectRatioMode> CurrentAspectRatioModeProperty =
|
private AspectRatioMode _currentAspectRatioMode;
|
||||||
AvaloniaProperty.Register<AspectRatioLayout, AspectRatioMode>(
|
|
||||||
nameof(CurrentAspectRatioMode));
|
public static readonly DirectProperty<AspectRatioLayout, AspectRatioMode> CurrentAspectRatioModeProperty =
|
||||||
|
AvaloniaProperty.RegisterDirect<AspectRatioLayout, AspectRatioMode>(
|
||||||
|
nameof(CurrentAspectRatioMode), o => o.CurrentAspectRatioMode);
|
||||||
|
|
||||||
private readonly Queue<bool> _history = new();
|
private readonly Queue<bool> _history = new();
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ public class AspectRatioLayout : TransitioningContentControl
|
|||||||
public AspectRatioMode CurrentAspectRatioMode
|
public AspectRatioMode CurrentAspectRatioMode
|
||||||
{
|
{
|
||||||
get => GetValue(CurrentAspectRatioModeProperty);
|
get => GetValue(CurrentAspectRatioModeProperty);
|
||||||
set => SetValue(CurrentAspectRatioModeProperty, value);
|
set => SetAndRaise(CurrentAspectRatioModeProperty, ref _currentAspectRatioMode, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<double> AspectRatioValueProperty =
|
public static readonly StyledProperty<double> AspectRatioValueProperty =
|
||||||
@@ -64,13 +66,13 @@ public class AspectRatioLayout : TransitioningContentControl
|
|||||||
set => SetValue(ItemsProperty, value);
|
set => SetValue(ItemsProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double AspectRatioChangeAmbiguity
|
public double AspectRatioTolerance
|
||||||
{
|
{
|
||||||
get => GetValue(AspectRatioChangeAmbiguityProperty);
|
get => GetValue(AspectRatioToleranceProperty);
|
||||||
set => SetValue(AspectRatioChangeAmbiguityProperty, value);
|
set => SetValue(AspectRatioToleranceProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdataHistory(bool value)
|
private void UpdateHistory(bool value)
|
||||||
{
|
{
|
||||||
_history.Enqueue(value);
|
_history.Enqueue(value);
|
||||||
while (_history.Count > 3)
|
while (_history.Count > 3)
|
||||||
@@ -91,7 +93,7 @@ public class AspectRatioLayout : TransitioningContentControl
|
|||||||
private AspectRatioMode GetScaleMode(Rect rect)
|
private AspectRatioMode GetScaleMode(Rect rect)
|
||||||
{
|
{
|
||||||
var scale = GetAspectRatio(rect);
|
var scale = GetAspectRatio(rect);
|
||||||
var absA = Math.Abs(AspectRatioChangeAmbiguity);
|
var absA = Math.Abs(AspectRatioTolerance);
|
||||||
var h = 1d + absA;
|
var h = 1d + absA;
|
||||||
var v = 1d - absA;
|
var v = 1d - absA;
|
||||||
if (scale >= h) return AspectRatioMode.HorizontalRectangle;
|
if (scale >= h) return AspectRatioMode.HorizontalRectangle;
|
||||||
@@ -104,14 +106,14 @@ public class AspectRatioLayout : TransitioningContentControl
|
|||||||
{
|
{
|
||||||
base.OnPropertyChanged(change);
|
base.OnPropertyChanged(change);
|
||||||
if (change.Property == ItemsProperty ||
|
if (change.Property == ItemsProperty ||
|
||||||
change.Property == AspectRatioChangeAmbiguityProperty ||
|
change.Property == AspectRatioToleranceProperty ||
|
||||||
change.Property == BoundsProperty)
|
change.Property == BoundsProperty)
|
||||||
{
|
{
|
||||||
if (change.Property == BoundsProperty)
|
if (change.Property == BoundsProperty)
|
||||||
{
|
{
|
||||||
var o = (Rect)change.OldValue!;
|
var o = (Rect)change.OldValue!;
|
||||||
var n = (Rect)change.NewValue!;
|
var n = (Rect)change.NewValue!;
|
||||||
UpdataHistory(GetAspectRatio(o) <= GetAspectRatio(n));
|
UpdateHistory(GetAspectRatio(o) <= GetAspectRatio(n));
|
||||||
if (!IsRightChanges()) return;
|
if (!IsRightChanges()) return;
|
||||||
CurrentAspectRatioMode = GetScaleMode(n);
|
CurrentAspectRatioMode = GetScaleMode(n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,42 +29,14 @@ public class AspectRatioLayoutItem : ContentControl
|
|||||||
set => SetValue(EndAspectRatioValueProperty, value);
|
set => SetValue(EndAspectRatioValueProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsUseAspectRatioRange =>
|
||||||
private bool _isUseAspectRatioRange;
|
!double.IsNaN(StartAspectRatioValue)
|
||||||
|
&& !double.IsNaN(EndAspectRatioValue)
|
||||||
public static readonly DirectProperty<AspectRatioLayoutItem, bool> IsUseAspectRatioRangeProperty =
|
&& !(StartAspectRatioValue > EndAspectRatioValue);
|
||||||
AvaloniaProperty.RegisterDirect<AspectRatioLayoutItem, bool>(
|
|
||||||
nameof(IsUseAspectRatioRange), o => o.IsUseAspectRatioRange);
|
|
||||||
|
|
||||||
public bool IsUseAspectRatioRange
|
|
||||||
{
|
|
||||||
get => _isUseAspectRatioRange;
|
|
||||||
private set => SetAndRaise(IsUseAspectRatioRangeProperty, ref _isUseAspectRatioRange, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AspectRatioMode AcceptAspectRatioMode
|
public AspectRatioMode AcceptAspectRatioMode
|
||||||
{
|
{
|
||||||
get => GetValue(AcceptScaleModeProperty);
|
get => GetValue(AcceptScaleModeProperty);
|
||||||
set => SetValue(AcceptScaleModeProperty, value);
|
set => SetValue(AcceptScaleModeProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(change);
|
|
||||||
if (change.Property == StartAspectRatioValueProperty ||
|
|
||||||
change.Property == EndAspectRatioValueProperty)
|
|
||||||
{
|
|
||||||
UpdataIsUseAspectRatioRange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdataIsUseAspectRatioRange()
|
|
||||||
{
|
|
||||||
if (double.IsNaN(StartAspectRatioValue)
|
|
||||||
|| double.IsNaN(EndAspectRatioValue)
|
|
||||||
|| StartAspectRatioValue > EndAspectRatioValue)
|
|
||||||
IsUseAspectRatioRange = false;
|
|
||||||
else
|
|
||||||
IsUseAspectRatioRange = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user