Repository navigation
Expand file tree
/
Copy pathQueryBox.cs
More file actions
61 lines (48 loc) · 1.67 KB
/
Copy pathQueryBox.cs
File metadata and controls
61 lines (48 loc) · 1.67 KB
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
using Source.Common.Input;
namespace Source.GUI.Controls;
public class QueryBox : MessageBox
{
static QueryBox() => ChainToAnimationMap<QueryBox>();
public QueryBox(ReadOnlySpan<char> title, ReadOnlySpan<char> queryText, Panel? parent = null) : base(title, queryText, parent) {
CancelButton?.DeletePanel();
CancelButton = new Button(this, "CancelButton", "#QueryBox_Cancel");
CancelButton.SetCommand("Cancel");
CancelButton.AddActionSignalTarget(this);
OkButton.SetCommand("OK");
CancelCommand = null;
OkCommand = null;
OkButton.SetTabPosition(1);
CancelButton.SetTabPosition(2);
}
public override void PerformLayout() {
base.PerformLayout();
GetClientArea(out int x, out int y, out int wide, out int tall);
wide += x;
tall += y;
CancelButton.GetSize(out int oldWide, out int oldTall);
CancelButton.GetContentSize(out int btnWide, out int btnTall);
btnWide = Math.Max(oldWide, btnWide + 10);
btnTall = Math.Max(oldTall, btnTall + 10);
CancelButton.SetSize(btnWide, btnTall);
OkButton.SetPos((wide / 2) - (OkButton.GetWide()) - 1 + x, tall - OkButton.GetTall() - 15);
CancelButton.SetPos((wide / 2) + x + 16, tall - CancelButton.GetTall() - 15);
}
[UiCommand("OK")]
private void OnOK() {
DoCommand("Close");
if (OkCommand != null) PostActionSignal(OkCommand.MakeCopy());
base.OnCommand("OK");
}
[UiCommand("Cancel")]
private void OnCancelCommand() {
DoCommand("Close");
if (CancelCommand != null) PostActionSignal(CancelCommand.MakeCopy());
base.OnCommand("Cancel");
}
public override void OnKeyCodeTyped(ButtonCode code) {
if (code == ButtonCode.KeyEscape)
DoCommand("Cancel");
else
base.OnKeyCodeTyped(code);
}
}