private IDisposable Start(ILayoutManager layoutManager) { var result = AvaloniaLocator.EnterScope(); AvaloniaLocator.CurrentMutable.Bind <ILayoutManager>().ToConstant(layoutManager); return(result); }
public void Hit_Test_Should_Respect_Stroke() { using (AvaloniaLocator.EnterScope()) { SkiaPlatform.Initialize(); var root = new TestRoot { Width = 100, Height = 100, Child = new Ellipse { Width = 100, Height = 100, Stroke = Brushes.Red, StrokeThickness = 5, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center } }; root.Renderer = new DeferredRenderer(root, null); root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var outsideResult = root.Renderer.HitTest(new Point(50, 50), root, null); var insideResult = root.Renderer.HitTest(new Point(1, 50), root, null); Assert.Empty(outsideResult); Assert.Equal(new[] { root.Child }, insideResult); } }
public void Invalidating_Child_Should_Remeasure_Parent() { var layoutManager = new LayoutManager(); using (AvaloniaLocator.EnterScope()) { AvaloniaLocator.CurrentMutable.Bind <ILayoutManager>().ToConstant(layoutManager); Border border; StackPanel panel; var root = new TestLayoutRoot { Child = panel = new StackPanel { Children = new Controls.Controls { (border = new Border()) } } }; layoutManager.ExecuteInitialLayoutPass(root); Assert.Equal(new Size(0, 0), root.DesiredSize); border.Width = 100; border.Height = 100; layoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(100, 100), panel.DesiredSize); } }
private static IDisposable CreateServices() { var result = AvaloniaLocator.EnterScope(); var styles = new Styles { new Style(x => x.OfType <PopupRoot>()) { Setters = new[] { new Setter(TemplatedControl.TemplateProperty, new FuncControlTemplate <PopupRoot>(PopupRootTemplate)), } }, }; var globalStyles = new Mock <IGlobalStyles>(); globalStyles.Setup(x => x.Styles).Returns(styles); var renderInterface = new Mock <IPlatformRenderInterface>(); AvaloniaLocator.CurrentMutable .Bind <ILayoutManager>().ToTransient <LayoutManager>() .Bind <IGlobalStyles>().ToFunc(() => globalStyles.Object) .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock()) .Bind <IStyler>().ToTransient <Styler>() .Bind <IPlatformRenderInterface>().ToFunc(() => renderInterface.Object); return(result); }
public void LoadsRenderingModuleWithMatchingRenderingSubsystem() { using (AvaloniaLocator.EnterScope()) { ResetModuleLoadStates(); var builder = AppBuilder.Configure <App>() .IgnoreSetupCheck() .UseWindowingSubsystem(() => { }) .UseRenderingSubsystem(() => { }, "Direct2D1"); builder.UseAvaloniaModules().SetupWithoutStarting(); Assert.False(DefaultRenderingModule.IsLoaded); Assert.True(Direct2DModule.IsLoaded); Assert.False(SkiaModule.IsLoaded); ResetModuleLoadStates(); builder = AppBuilder.Configure <App>() .IgnoreSetupCheck() .UseWindowingSubsystem(() => { }) .UseRenderingSubsystem(() => { }, "Skia"); builder.UseAvaloniaModules().SetupWithoutStarting(); Assert.False(DefaultRenderingModule.IsLoaded); Assert.False(Direct2DModule.IsLoaded); Assert.True(SkiaModule.IsLoaded); } }
public void Test_ScrollViewer_With_TextBlock() { using (var context = AvaloniaLocator.EnterScope()) { RegisterServices(); ScrollViewer scrollViewer; TextBlock textBlock; var window = new Window() { Width = 800, Height = 600, SizeToContent = SizeToContent.WidthAndHeight, Content = scrollViewer = new ScrollViewer { Width = 200, Height = 200, HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = textBlock = new TextBlock { Width = 400, Height = 400, Text = "Hello World!", }, } }; window.Resources["ScrollBarThickness"] = 10.0; window.Show(); window.LayoutManager.ExecuteInitialLayoutPass(window); Assert.Equal(new Size(800, 600), window.Bounds.Size); Assert.Equal(new Size(200, 200), scrollViewer.Bounds.Size); Assert.Equal(new Point(300, 200), Position(scrollViewer)); Assert.Equal(new Size(400, 400), textBlock.Bounds.Size); var scrollBars = scrollViewer.GetTemplateChildren().OfType <ScrollBar>().ToList(); var presenters = scrollViewer.GetTemplateChildren().OfType <ScrollContentPresenter>().ToList(); Assert.Equal(2, scrollBars.Count); Assert.Single(presenters); var presenter = presenters[0]; Assert.Equal(new Size(190, 190), presenter.Bounds.Size); var horzScroll = scrollBars.Single(x => x.Orientation == Orientation.Horizontal); var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical); Assert.True(horzScroll.IsVisible); Assert.True(vertScroll.IsVisible); Assert.Equal(new Size(190, 10), horzScroll.Bounds.Size); Assert.Equal(new Size(10, 190), vertScroll.Bounds.Size); Assert.Equal(new Point(0, 190), Position(horzScroll)); Assert.Equal(new Point(190, 0), Position(vertScroll)); } }
private static IDisposable Start() { var scope = AvaloniaLocator.EnterScope(); SkiaPlatform.Initialize(); return(scope); }
public void Should_Measure_Expander_Triangle_With_Stroke_Correctly() { using (AvaloniaLocator.EnterScope()) { Direct2D1Platform.Initialize(); var target = new Path { Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"), Stroke = Brushes.Black, StrokeThickness = 2, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, UseLayoutRounding = false, }; target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); // Measured geometry with stroke of 2px is: // // {-1, -0.414, 6.414, 12.828} (see GeometryTests) // // With origin at 0,0 the bounds should equal: // // Assert.Equal(new Rect(0, 0, 5.414, 12.414), target.Bounds, compare); // // However Path.Measure doesn't correctly handle strokes currently, so testing for // the (incorrect) current output for now... Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, Compare); } }
public static IDisposable Start(TestServices services = null) { var scope = AvaloniaLocator.EnterScope(); var app = new UnitTestApplication(services); AvaloniaLocator.CurrentMutable.BindToSelf <Application>(app); return(scope); }
public void Should_Parse(string pathData) { using (AvaloniaLocator.EnterScope()) { var parser = PrepareParser(); parser.Parse(pathData); Assert.True(true); } }
public void Should_Measure_Expander_Triangle_With_Stroke_Correctly() { using (AvaloniaLocator.EnterScope()) { Direct2D1Platform.Initialize(); var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"); Assert.Equal(new Rect(-1, -0.414, 6.414, 12.828), target.GetRenderBounds(2), Compare); } }
public void Should_Measure_Expander_Triangle_Correctly() { using (AvaloniaLocator.EnterScope()) { Direct2D1Platform.Initialize(); var target = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"); Assert.Equal(new Rect(0, 2, 4, 8), target.Bounds, Compare); } }
public static IDisposable Start(TestServices services = null) { var scope = AvaloniaLocator.EnterScope(); var app = new UnitTestApplication(services); Dispatcher.UIThread.UpdateServices(); return(Disposable.Create(() => { scope.Dispose(); Dispatcher.UIThread.UpdateServices(); })); }
public void Name_Cannot_Be_Set_After_Added_To_Logical_Tree() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); root.Child = child; Assert.Throws <InvalidOperationException>(() => child.Name = "foo"); } }
public void Name_Can_Be_Set_While_Initializing() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); child.BeginInit(); root.Child = child; child.Name = "foo"; child.EndInit(); } }
public void Parses_Line() { using (AvaloniaLocator.EnterScope()) { var result = new Mock <IStreamGeometryContextImpl>(); var parser = PrepareParser(result); parser.Parse("M0 0L10 10"); result.Verify(x => x.LineTo(new Point(10, 10))); } }
public void Parses_Move() { using (AvaloniaLocator.EnterScope()) { var result = new Mock <IStreamGeometryContextImpl>(); var parser = PrepareParser(result); parser.Parse("M10 10"); result.Verify(x => x.BeginFigure(new Point(10, 10), true)); } }
public void Adding_To_Logical_Tree_Should_Register_With_NameScope() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); child.Name = "foo"; root.Child = child; Assert.Same(root.FindControl <Border>("foo"), child); } }
public void Parses_Close() { using (AvaloniaLocator.EnterScope()) { var result = new Mock <IStreamGeometryContextImpl>(); var parser = PrepareParser(result); parser.Parse("M0 0L10 10z"); result.Verify(x => x.EndFigure(true)); } }
public void Should_Create_Single_Instance_Typeface() { using (AvaloniaLocator.EnterScope()) { AvaloniaLocator.CurrentMutable.Bind <IPlatformRenderInterface>().ToConstant(new MockPlatformRenderInterface()); var fontFamily = new FontFamily("MyFont"); var typeface = FontManager.Current.GetOrAddTypeface(fontFamily); Assert.Same(typeface, FontManager.Current.GetOrAddTypeface(fontFamily)); } }
public void LoadsRenderingModuleWithoutDependenciesWhenNoModuleMatches() { using (AvaloniaLocator.EnterScope()) { ResetModuleLoadStates(); var builder = AppBuilder.Configure <App>() .UseWindowingSubsystem(() => { }) .UseRenderingSubsystem(() => { }, "TBD"); builder.UseAvaloniaModules().SetupWithoutStarting(); Assert.True(DefaultRenderingModule.IsLoaded); Assert.False(Direct2DModule.IsLoaded); Assert.False(SkiaModule.IsLoaded); } }
public void LoadsDefaultModule() { using (AvaloniaLocator.EnterScope()) { ResetModuleLoadStates(); AppBuilder.Configure <App>() .UseWindowingSubsystem(() => { }) .UseRenderingSubsystem(() => { }) .UseAvaloniaModules() .SetupWithoutStarting(); Assert.True(DefaultModule.IsLoaded); } }
public void Name_Can_Be_Set_While_Initializing() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); ((ISupportInitialize)child).BeginInit(); root.Child = child; child.Name = "foo"; Assert.Null(root.FindControl <Border>("foo")); ((ISupportInitialize)child).EndInit(); Assert.Same(root.FindControl <Border>("foo"), child); } }
public void StyleDetach_Is_Triggered_When_Control_Removed_From_Logical_Tree() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); root.Child = child; bool styleDetachTriggered = false; ((IStyleable)child).StyleDetach.Subscribe(_ => styleDetachTriggered = true); root.Child = null; Assert.True(styleDetachTriggered); } }
public void StyleInstance_Is_Disposed_When_Control_Removed_From_Logical_Tree() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); root.Child = child; var styleInstance = new Mock <IStyleInstance>(); ((IStyleable)child).StyleApplied(styleInstance.Object); root.Child = null; styleInstance.Verify(x => x.Dispose(), Times.Once); } }
public void HotKeyManager_Should_Register_And_Unregister_Key_Binding() { using (AvaloniaLocator.EnterScope()) { var styler = new Mock <Styler>(); AvaloniaLocator.CurrentMutable .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock()) .Bind <IStyler>().ToConstant(styler.Object); var gesture1 = new KeyGesture { Key = Key.A, Modifiers = InputModifiers.Control }; var gesture2 = new KeyGesture { Key = Key.B, Modifiers = InputModifiers.Control }; var tl = new Window(); var button = new Button(); tl.Content = button; tl.Template = CreateWindowTemplate(); tl.ApplyTemplate(); tl.Presenter.ApplyTemplate(); HotKeyManager.SetHotKey(button, gesture1); Assert.Equal(gesture1, tl.KeyBindings[0].Gesture); HotKeyManager.SetHotKey(button, gesture2); Assert.Equal(gesture2, tl.KeyBindings[0].Gesture); tl.Content = null; tl.Presenter.ApplyTemplate(); Assert.Empty(tl.KeyBindings); tl.Content = button; tl.Presenter.ApplyTemplate(); Assert.Equal(gesture2, tl.KeyBindings[0].Gesture); HotKeyManager.SetHotKey(button, null); Assert.Empty(tl.KeyBindings); } }
public void Styles_Not_Applied_Until_Initialization_Finished() { using (AvaloniaLocator.EnterScope()) { var root = new TestRoot(); var child = new Border(); var styler = new Mock <IStyler>(); AvaloniaLocator.CurrentMutable.Bind <IStyler>().ToConstant(styler.Object); ((ISupportInitialize)child).BeginInit(); root.Child = child; styler.Verify(x => x.ApplyStyles(It.IsAny <IStyleable>()), Times.Never()); ((ISupportInitialize)child).EndInit(); styler.Verify(x => x.ApplyStyles(child), Times.Once()); } }
public void Should_Load_Nearest_Matching_Font() { using (AvaloniaLocator.EnterScope()) { var assetLoaderType = typeof(TestRoot).Assembly.GetType("Avalonia.Shared.PlatformSupport.AssetLoader"); var assetLoader = (IAssetLoader)Activator.CreateInstance(assetLoaderType, (Assembly)null); AvaloniaLocator.CurrentMutable.Bind <IAssetLoader>().ToConstant(assetLoader); var fontManager = new FontManagerImpl(); var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface( new Typeface(new FontFamily(s_fontUri), FontWeight.Black, FontStyle.Italic)); var skTypeface = glyphTypeface.Typeface; Assert.Equal("Noto Mono", skTypeface.FamilyName); } }
public void HotKeyManager_Should_Invoke_Event_Click_When_Command_Is_Null(string factoryName, Factory factory) { using (AvaloniaLocator.EnterScope()) { var styler = new Mock <Styler>(); var target = new KeyboardDevice(); var clickExecutedCount = 0; AvaloniaLocator.CurrentMutable .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock()) .Bind <IStyler>().ToConstant(styler.Object); var gesture = new KeyGesture(Key.A, KeyModifiers.Control); void Clickable_Click(object sender, Interactivity.RoutedEventArgs e) { clickExecutedCount++; } var root = new Window(); var element = factory(0, default, root) as InputElement;
public void Should_Create_Typeface_From_Fallback_Bold() { using (AvaloniaLocator.EnterScope()) { Direct2D1Platform.Initialize(); var fontManager = new FontManagerImpl(); var glyphTypeface = (GlyphTypefaceImpl)fontManager.CreateGlyphTypeface( new Typeface(new FontFamily("A, B, Arial"), weight: FontWeight.Bold)); var font = glyphTypeface.DWFont; Assert.Equal("Arial", font.FontFamily.FamilyNames.GetString(0)); Assert.Equal(SharpDX.DirectWrite.FontWeight.Bold, font.Weight); Assert.Equal(SharpDX.DirectWrite.FontStyle.Normal, font.Style); } }