|
|
@ -1,11 +1,13 @@ |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Controls.Presenters; |
|
|
|
|
|
using Avalonia.Controls.Shapes; |
|
|
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
|
|
using Avalonia.Data; |
|
|
using Avalonia.Layout; |
|
|
using Avalonia.Layout; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Media.Imaging; |
|
|
using Avalonia.Styling; |
|
|
using Avalonia.Platform; |
|
|
using Avalonia.Threading; |
|
|
using Avalonia.Themes.Simple; |
|
|
|
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
#if AVALONIA_SKIA
|
|
|
#if AVALONIA_SKIA
|
|
|
@ -21,37 +23,118 @@ namespace Avalonia.Direct2D1.RenderTests.Controls |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Decorator CreateTarget(int selectedPageIndex) |
|
|
private static IControlTemplate CreatePipsPagerTemplate() |
|
|
{ |
|
|
{ |
|
|
var pipsPager = new PipsPager |
|
|
return new FuncControlTemplate<PipsPager>((control, scope) => |
|
|
{ |
|
|
{ |
|
|
NumberOfPages = 5, |
|
|
var stackPanel = new StackPanel |
|
|
SelectedPageIndex = selectedPageIndex, |
|
|
{ |
|
|
HorizontalAlignment = HorizontalAlignment.Center, |
|
|
Name = "PART_RootPanel", |
|
|
VerticalAlignment = VerticalAlignment.Center |
|
|
Spacing = 4, |
|
|
}; |
|
|
[!StackPanel.OrientationProperty] = control[!PipsPager.OrientationProperty], |
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center, |
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Center |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
var target = new Decorator |
|
|
var buttonTemplate = new FuncControlTemplate<Button>((b, s) => |
|
|
{ |
|
|
new Border |
|
|
Width = 400, |
|
|
{ |
|
|
Height = 150, |
|
|
Background = Brushes.LightGray, |
|
|
Child = new Border |
|
|
Child = new TextBlock |
|
|
|
|
|
{ |
|
|
|
|
|
[!TextBlock.TextProperty] = b[!Button.ContentProperty], |
|
|
|
|
|
FontFamily = TestFontFamily, |
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Center, |
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var prevButton = new Button |
|
|
{ |
|
|
{ |
|
|
Background = Brushes.White, |
|
|
Name = "PART_PreviousButton", |
|
|
Child = pipsPager |
|
|
Content = "<", |
|
|
} |
|
|
Template = buttonTemplate, |
|
|
}; |
|
|
Width = 20, |
|
|
|
|
|
Height = 20, |
|
|
|
|
|
[!Button.IsVisibleProperty] = control[!PipsPager.IsPreviousButtonVisibleProperty] |
|
|
|
|
|
}.RegisterInNameScope(scope); |
|
|
|
|
|
|
|
|
AvaloniaLocator.CurrentMutable.Bind<ICursorFactory>().ToConstant(new CursorFactoryStub()); |
|
|
var nextButton = new Button |
|
|
target.Styles.Add(new SimpleTheme()); |
|
|
{ |
|
|
|
|
|
Name = "PART_NextButton", |
|
|
|
|
|
Content = ">", |
|
|
|
|
|
Template = buttonTemplate, |
|
|
|
|
|
Width = 20, |
|
|
|
|
|
Height = 20, |
|
|
|
|
|
[!Button.IsVisibleProperty] = control[!PipsPager.IsNextButtonVisibleProperty] |
|
|
|
|
|
}.RegisterInNameScope(scope); |
|
|
|
|
|
|
|
|
return target; |
|
|
var listBoxTemplate = new FuncControlTemplate<ListBox>((lb, s) => |
|
|
|
|
|
new ItemsPresenter |
|
|
|
|
|
{ |
|
|
|
|
|
Name = "PART_ItemsPresenter", |
|
|
|
|
|
[~ItemsPresenter.ItemsPanelProperty] = lb[~ListBox.ItemsPanelProperty], |
|
|
|
|
|
}.RegisterInNameScope(s)); |
|
|
|
|
|
|
|
|
|
|
|
var pipsList = new ListBox |
|
|
|
|
|
{ |
|
|
|
|
|
Name = "PART_PipsPagerList", |
|
|
|
|
|
Template = listBoxTemplate, |
|
|
|
|
|
[!ListBox.ItemsSourceProperty] = new Binding("TemplateSettings.Pips") { Source = control }, |
|
|
|
|
|
[!ListBox.SelectedIndexProperty] = control[!PipsPager.SelectedPageIndexProperty], |
|
|
|
|
|
ItemsPanel = new FuncTemplate<Panel?>(() => new StackPanel |
|
|
|
|
|
{ |
|
|
|
|
|
Spacing = 2, |
|
|
|
|
|
[!StackPanel.OrientationProperty] = control[!PipsPager.OrientationProperty] |
|
|
|
|
|
}) |
|
|
|
|
|
}.RegisterInNameScope(scope); |
|
|
|
|
|
|
|
|
|
|
|
var itemStyle = new Style(x => x.OfType<ListBoxItem>()); |
|
|
|
|
|
itemStyle.Setters.Add(new Setter(ListBoxItem.TemplateProperty, |
|
|
|
|
|
new FuncControlTemplate<ListBoxItem>((item, s) => |
|
|
|
|
|
new Rectangle { Name = "Pip", Width = 10, Height = 10 }.RegisterInNameScope(s)))); |
|
|
|
|
|
|
|
|
|
|
|
var defaultPipStyle = new Style(x => x.OfType<ListBoxItem>().Template().Name("Pip")); |
|
|
|
|
|
defaultPipStyle.Setters.Add(new Setter(Rectangle.FillProperty, Brushes.Gray)); |
|
|
|
|
|
|
|
|
|
|
|
var selectedStyle = new Style(x => x.OfType<ListBoxItem>().Class(":selected").Template().Name("Pip")); |
|
|
|
|
|
selectedStyle.Setters.Add(new Setter(Rectangle.FillProperty, Brushes.Red)); |
|
|
|
|
|
|
|
|
|
|
|
pipsList.Styles.Add(itemStyle); |
|
|
|
|
|
pipsList.Styles.Add(defaultPipStyle); |
|
|
|
|
|
pipsList.Styles.Add(selectedStyle); |
|
|
|
|
|
|
|
|
|
|
|
stackPanel.Children.Add(prevButton); |
|
|
|
|
|
stackPanel.Children.Add(pipsList); |
|
|
|
|
|
stackPanel.Children.Add(nextButton); |
|
|
|
|
|
|
|
|
|
|
|
return stackPanel; |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task PipsPager_Default() |
|
|
public async Task PipsPager_Default() |
|
|
{ |
|
|
{ |
|
|
var target = CreateTarget(1); |
|
|
var pipsPager = new PipsPager |
|
|
|
|
|
{ |
|
|
|
|
|
Template = CreatePipsPagerTemplate(), |
|
|
|
|
|
NumberOfPages = 5, |
|
|
|
|
|
SelectedPageIndex = 1 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var target = new Border |
|
|
|
|
|
{ |
|
|
|
|
|
Padding = new Thickness(20), |
|
|
|
|
|
Background = Brushes.White, |
|
|
|
|
|
Child = pipsPager, |
|
|
|
|
|
Width = 400, |
|
|
|
|
|
Height = 150 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
target.Measure(new Size(400, 150)); |
|
|
|
|
|
target.Arrange(new Rect(0, 0, 400, 150)); |
|
|
|
|
|
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken); |
|
|
|
|
|
|
|
|
await RenderToFile(target); |
|
|
await RenderToFile(target); |
|
|
CompareImages(skipImmediate: true); |
|
|
CompareImages(skipImmediate: true); |
|
|
} |
|
|
} |
|
|
@ -59,23 +142,28 @@ namespace Avalonia.Direct2D1.RenderTests.Controls |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task PipsPager_Preselected_Index() |
|
|
public async Task PipsPager_Preselected_Index() |
|
|
{ |
|
|
{ |
|
|
var target = CreateTarget(3); |
|
|
var pipsPager = new PipsPager |
|
|
await RenderToFile(target); |
|
|
{ |
|
|
CompareImages(skipImmediate: true); |
|
|
Template = CreatePipsPagerTemplate(), |
|
|
} |
|
|
NumberOfPages = 5, |
|
|
|
|
|
SelectedPageIndex = 3 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
private sealed class CursorFactoryStub : ICursorFactory |
|
|
var target = new Border |
|
|
{ |
|
|
{ |
|
|
public ICursorImpl GetCursor(StandardCursorType cursorType) => new CursorStub(); |
|
|
Padding = new Thickness(20), |
|
|
|
|
|
Background = Brushes.White, |
|
|
|
|
|
Child = pipsPager, |
|
|
|
|
|
Width = 400, |
|
|
|
|
|
Height = 150 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
public ICursorImpl CreateCursor(Bitmap cursor, PixelPoint hotSpot) => new CursorStub(); |
|
|
target.Measure(new Size(400, 150)); |
|
|
|
|
|
target.Arrange(new Rect(0, 0, 400, 150)); |
|
|
|
|
|
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken); |
|
|
|
|
|
|
|
|
private sealed class CursorStub : ICursorImpl |
|
|
await RenderToFile(target); |
|
|
{ |
|
|
CompareImages(skipImmediate: true); |
|
|
public void Dispose() |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|