1 module new_io.input_node;
2 
3 import fluid;
4 
5 @safe:
6 
7 alias plainInput = nodeBuilder!PlainInput;
8 
9 class PlainInput : InputNode!Node {
10 
11     override void resizeImpl(Vector2 space) {
12         super.resizeImpl(space);
13     }
14 
15     override void drawImpl(Rectangle outer, Rectangle inner) {
16     }
17 
18 }
19 
20 @("InputNode.focus() sets focus in FocusIO")
21 unittest {
22 
23     auto input = plainInput();
24     auto root = focusChain(input);
25 
26     root.draw();
27     input.focus();
28 
29     assert(root.currentFocus.opEquals(input));
30 
31 }
32 
33 @("Disabling a node causes it to block inputs")
34 unittest {
35 
36     int submitted;
37 
38     auto btn = button("Hello!", delegate { submitted++; });
39     auto root = focusChain(btn);
40     root.currentFocus = btn;
41 
42     // Press the button
43     root.runInputAction!(FluidInputAction.press);
44     assert(submitted == 1);
45 
46     // Press the button while disabled
47     btn.disable();
48     root.draw();
49     root.runInputAction!(FluidInputAction.press);
50     assert(btn.isDisabled);
51     assert(btn.blocksInput);
52     assert(submitted == 1, "btn shouldn't trigger again");
53 
54     // Enable the button and hit it again
55     btn.enable();
56     root.draw();
57     root.runInputAction!(FluidInputAction.press);
58 
59     assert(!btn.isDisabledInherited);
60     assert(submitted == 2);
61 
62 }
63 
64 @("[TODO] Disabled nodes cannot accept text input")
65 version (none)
66 unittest {
67 
68     // TODO use a dedicated node instead of text input
69 
70     auto input = textInput("Placeholder", delegate { });
71     auto root = focusChain(input);
72     root.currentFocus = input;
73 
74     // Try typing into the input box
75     root.type("Hello, ");
76     assert(input.value == "Hello, ");
77 
78     // Disable the box and try typing again
79     input.disable();
80     root.type("World!");
81 
82     assert(input.value == "Hello, ", "Input should remain unchanged");
83 
84 }