Browse Source

Added Image.StretchDirection.

But not yet implemented.
pull/3373/head
Steven Kirk 6 years ago
parent
commit
062ec0ccb6
  1. 17
      src/Avalonia.Controls/Image.cs
  2. 25
      src/Avalonia.Visuals/Media/StretchDirection.cs
  3. 13
      tests/Avalonia.Controls.UnitTests/ImageTests.cs

17
src/Avalonia.Controls/Image.cs

@ -23,6 +23,12 @@ namespace Avalonia.Controls
public static readonly StyledProperty<Stretch> StretchProperty = public static readonly StyledProperty<Stretch> StretchProperty =
AvaloniaProperty.Register<Image, Stretch>(nameof(Stretch), Stretch.Uniform); AvaloniaProperty.Register<Image, Stretch>(nameof(Stretch), Stretch.Uniform);
/// <summary>
/// Defines the <see cref="StretchDirection"/> property.
/// </summary>
public static readonly StyledProperty<StretchDirection> StretchDirectionProperty =
AvaloniaProperty.Register<Image, StretchDirection>(nameof(StretchDirection));
static Image() static Image()
{ {
AffectsRender<Image>(SourceProperty, StretchProperty); AffectsRender<Image>(SourceProperty, StretchProperty);
@ -43,10 +49,19 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public Stretch Stretch public Stretch Stretch
{ {
get { return (Stretch)GetValue(StretchProperty); } get { return GetValue(StretchProperty); }
set { SetValue(StretchProperty, value); } set { SetValue(StretchProperty, value); }
} }
/// <summary>
/// Gets or sets a value controlling in what direction the image will be stretched.
/// </summary>
public StretchDirection StretchDirection
{
get { return GetValue(StretchDirectionProperty); }
set { SetValue(StretchDirectionProperty, value); }
}
/// <summary> /// <summary>
/// Renders the control. /// Renders the control.
/// </summary> /// </summary>

25
src/Avalonia.Visuals/Media/StretchDirection.cs

@ -0,0 +1,25 @@
namespace Avalonia.Media
{
/// <summary>
/// Describes the type of scaling that can be used when scaling content.
/// </summary>
public enum StretchDirection
{
/// <summary>
/// Only scales the content upwards when the content is smaller than the available space.
/// If the content is larger, no scaling downwards is done.
/// </summary>
UpOnly,
/// <summary>
/// Only scales the content downwards when the content is larger than the available space.
/// If the content is smaller, no scaling upwards is done.
/// </summary>
DownOnly,
/// <summary>
/// Always stretches to fit the available space according to the stretch mode.
/// </summary>
Both,
}
}

13
tests/Avalonia.Controls.UnitTests/ImageTests.cs

@ -62,6 +62,19 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(50, 50), target.DesiredSize); Assert.Equal(new Size(50, 50), target.DesiredSize);
} }
[Fact]
public void Measure_Should_Return_Correct_Size_With_StretchDirection_DownOnly()
{
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.StretchDirection = StretchDirection.DownOnly;
target.Source = bitmap;
target.Measure(new Size(150, 150));
Assert.Equal(new Size(50, 100), target.DesiredSize);
}
[Fact] [Fact]
public void Measure_Should_Return_Correct_Size_For_Infinite_Height() public void Measure_Should_Return_Correct_Size_For_Infinite_Height()
{ {

Loading…
Cancel
Save