This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaseButtonDriver.cs
62 lines (53 loc) · 1.85 KB
/
BaseButtonDriver.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Threading.Tasks;
using Godot;
using GodotTestDriver.Util;
using JetBrains.Annotations;
namespace GodotTestDriver.Drivers
{
/// <summary>
/// Driver for <see cref="BaseButton"/> controls.
/// </summary>
[PublicAPI]
public partial class BaseButtonDriver<T> : ControlDriver<T> where T:BaseButton
{
public BaseButtonDriver(Func<T> producer, string description = "") : base(producer, description)
{
}
/// <summary>
/// Whether the button is currently disabled.
/// </summary>
public bool Disabled => PresentRoot.Disabled;
/// <summary>
/// Whether the button is currently enabled. Inversed from <see cref="Disabled"/>.
/// </summary>
public bool Enabled => !Disabled;
/// <summary>
/// Whether the button is currently pressed.
/// </summary>
public bool Pressed => PresentRoot.ButtonPressed;
/// <summary>
/// Simulates a button press by simply sending the press event.
/// </summary>
public async Task Press()
{
var button = VisibleRoot;
if (button.Disabled)
{
throw new InvalidOperationException(ErrorMessage($"Button is disabled and cannot be pressed."));
}
// make sure we run on main thread
await button.GetTree().NextFrame();
button.EmitSignal(BaseButton.SignalName.Pressed);
await button.GetTree().WaitForEvents();
}
public override async Task ClickCenter(MouseButton button = MouseButton.Left)
{
if (Disabled)
{
throw new InvalidOperationException(ErrorMessage("Button is disabled and cannot be pressed."));
}
await base.ClickCenter(button);
}
}
}