TestRoot.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia.Controls;
  5. using Avalonia.Input;
  6. using Avalonia.Layout;
  7. using Avalonia.Platform;
  8. using Avalonia.Rendering;
  9. using Avalonia.Styling;
  10. namespace Avalonia.UnitTests
  11. {
  12. public class TestRoot : Decorator, IFocusScope, ILayoutRoot, INameScope, IRenderRoot, IStyleRoot
  13. {
  14. private readonly NameScope _nameScope = new NameScope();
  15. public TestRoot()
  16. {
  17. var rendererFactory = AvaloniaLocator.Current.GetService<IRendererFactory>();
  18. var renderLoop = AvaloniaLocator.Current.GetService<IRenderLoop>();
  19. Renderer = rendererFactory?.CreateRenderer(this, renderLoop);
  20. }
  21. event EventHandler<NameScopeEventArgs> INameScope.Registered
  22. {
  23. add { _nameScope.Registered += value; ++NameScopeRegisteredSubscribers; }
  24. remove { _nameScope.Registered -= value; --NameScopeRegisteredSubscribers; }
  25. }
  26. public event EventHandler<NameScopeEventArgs> Unregistered
  27. {
  28. add { _nameScope.Unregistered += value; ++NameScopeUnregisteredSubscribers; }
  29. remove { _nameScope.Unregistered -= value; --NameScopeUnregisteredSubscribers; }
  30. }
  31. public int NameScopeRegisteredSubscribers { get; private set; }
  32. public int NameScopeUnregisteredSubscribers { get; private set; }
  33. public Size ClientSize => new Size(100, 100);
  34. public Size MaxClientSize => Size.Infinity;
  35. public double LayoutScaling => 1;
  36. public ILayoutManager LayoutManager => AvaloniaLocator.Current.GetService<ILayoutManager>();
  37. public IRenderTarget RenderTarget => null;
  38. public IRenderer Renderer { get; }
  39. public IRenderTarget CreateRenderTarget()
  40. {
  41. throw new NotImplementedException();
  42. }
  43. public void Invalidate(Rect rect)
  44. {
  45. }
  46. public Point PointToClient(Point p) => p;
  47. public Point PointToScreen(Point p) => p;
  48. void INameScope.Register(string name, object element)
  49. {
  50. _nameScope.Register(name, element);
  51. }
  52. object INameScope.Find(string name)
  53. {
  54. return _nameScope.Find(name);
  55. }
  56. void INameScope.Unregister(string name)
  57. {
  58. _nameScope.Unregister(name);
  59. }
  60. }
  61. }