-
Notifications
You must be signed in to change notification settings - Fork 1
/
CanvasItemDriver.cs
47 lines (42 loc) · 1.4 KB
/
CanvasItemDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace Chickensoft.GodotTestDriver.Drivers;
using System;
using Godot;
using JetBrains.Annotations;
/// <summary>
/// Driver for <see cref="CanvasItem"/> nodes.
/// </summary>
/// <typeparam name="T">CanvasItem type.</typeparam>
[PublicAPI]
public class CanvasItemDriver<T> : NodeDriver<T> where T : CanvasItem
{
/// <summary>
/// Creates a new generic CanvasItemDriver.
/// </summary>
/// <param name="producer">Producer that creates a CanvasItem subclass.</param>
/// <param name="description">Driver description.</param>
public CanvasItemDriver(Func<T> producer, string description = "") : base(producer, description)
{
}
/// <summary>
/// Is the CanvasItem currently visible?
/// </summary>
public bool IsVisible => PresentRoot.IsVisibleInTree();
/// <summary>
/// The viewport that this canvas item is rendering to.
/// </summary>
public Viewport Viewport => PresentRoot.GetViewport();
/// <summary>
/// Returns the root node but ensures it is visible.
/// </summary>
/// <exception cref="InvalidOperationException"/>
protected T VisibleRoot
{
get
{
var root = PresentRoot;
return !root.IsVisibleInTree()
? throw new InvalidOperationException(ErrorMessage("Cannot interact with CanvasItem because it is not visible."))
: root;
}
}
}