Browse Source

Merge branch 'master' into cleanup-win32-framebuffer-manager

pull/4922/head
Dariusz Komosiński 5 years ago
committed by GitHub
parent
commit
25ac318839
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
  2. 20
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  3. 23
      src/Avalonia.Controls/TextBlock.cs
  4. 54
      tests/Avalonia.RenderTests/Controls/TextBlockTests.cs
  5. BIN
      tests/TestFiles/Direct2D1/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png
  6. BIN
      tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png

2
src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs

@ -438,7 +438,7 @@ namespace Avalonia.Controls
_lastMousePositionHeaders = mousePositionHeaders;
if (args.Pointer.Captured != this)
if (args.Pointer.Captured != this && _dragMode == DragMode.Drag)
args.Pointer.Capture(this);
SetDragCursor(mousePosition);

20
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -4,6 +4,7 @@ using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.Threading;
using Avalonia.VisualTree;
using Avalonia.Layout;
namespace Avalonia.Controls.Presenters
{
@ -312,7 +313,24 @@ namespace Avalonia.Controls.Presenters
context.FillRectangle(background, new Rect(Bounds.Size));
}
context.DrawText(Foreground, new Point(), FormattedText);
double top = 0;
var textSize = FormattedText.Bounds.Size;
if (Bounds.Height < textSize.Height)
{
switch (VerticalAlignment)
{
case VerticalAlignment.Center:
top += (Bounds.Height - textSize.Height) / 2;
break;
case VerticalAlignment.Bottom:
top += (Bounds.Height - textSize.Height);
break;
}
}
context.DrawText(Foreground, new Point(0, top), FormattedText);
}
public override void Render(DrawingContext context)

23
src/Avalonia.Controls/TextBlock.cs

@ -3,6 +3,7 @@ using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Avalonia.Metadata;
using Avalonia.Layout;
namespace Avalonia.Controls
{
@ -427,14 +428,32 @@ namespace Avalonia.Controls
case TextAlignment.Center:
offsetX = (width - TextLayout.Size.Width) / 2;
break;
case TextAlignment.Right:
offsetX = width - TextLayout.Size.Width;
offsetX = width - TextLayout.Size.Width;
break;
}
var padding = Padding;
using (context.PushPostTransform(Matrix.CreateTranslation(padding.Left + offsetX, padding.Top)))
var top = padding.Top;
var textSize = TextLayout.Size;
if (Bounds.Height < textSize.Height)
{
switch (VerticalAlignment)
{
case VerticalAlignment.Center:
top += (Bounds.Height - textSize.Height) / 2;
break;
case VerticalAlignment.Bottom:
top += (Bounds.Height - textSize.Height);
break;
}
}
using (context.PushPostTransform(Matrix.CreateTranslation(padding.Left + offsetX, top)))
{
TextLayout.Draw(context);
}

54
tests/Avalonia.RenderTests/Controls/TextBlockTests.cs

@ -40,5 +40,59 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
await RenderToFile(target);
CompareImages();
}
[Win32Fact("Has text")]
public async Task RestrictedHeight_VerticalAlign()
{
IControl text(VerticalAlignment verticalAlingnment, bool clip = true, bool restrictHeight = true)
{
return new Border()
{
BorderBrush = Brushes.Blue,
BorderThickness = new Thickness(1),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
Height = restrictHeight ? 20 : double.NaN,
Margin = new Thickness(1),
Child = new TextBlock
{
FontFamily = new FontFamily("Courier New"),
Background = Brushes.Red,
FontSize = 24,
Foreground = Brushes.Black,
Text = "L",
VerticalAlignment = verticalAlingnment,
ClipToBounds = clip
}
};
}
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 180,
Height = 80,
Child = new StackPanel()
{
Orientation = Orientation.Horizontal,
Children =
{
text(VerticalAlignment.Stretch, restrictHeight: false),
text(VerticalAlignment.Center),
text(VerticalAlignment.Stretch),
text(VerticalAlignment.Top),
text(VerticalAlignment.Bottom),
text(VerticalAlignment.Center, clip:false),
text(VerticalAlignment.Stretch, clip:false),
text(VerticalAlignment.Top, clip:false),
text(VerticalAlignment.Bottom, clip:false),
}
}
};
await RenderToFile(target);
CompareImages();
}
}
}

BIN
tests/TestFiles/Direct2D1/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

BIN
tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Loading…
Cancel
Save