1 module actions.scheduling; 2 3 import fluid; 4 5 @safe: 6 7 class CountNodesAction : TreeAction { 8 9 int runs; 10 int nodesDrawn; 11 12 override void beforeTree(Node, Rectangle) { 13 runs++; 14 nodesDrawn = 0; 15 } 16 17 override void beforeDraw(Node, Rectangle) { 18 nodesDrawn++; 19 } 20 21 } 22 23 @("Actions can be scheduled using the new system") 24 unittest { 25 26 auto root = vspace( 27 vspace(), 28 vspace(), 29 ); 30 auto action = new CountNodesAction; 31 32 root.startAction(action); 33 root.draw(); 34 assert(action.nodesDrawn == 3); 35 36 } 37 38 @("TreeAction.stop will stop the action from running") 39 unittest { 40 41 auto action = new CountNodesAction; 42 auto root = vspace(); 43 44 root.startAction(action); 45 root.draw(); 46 assert(action.runs == 1); 47 root.draw(); 48 assert(action.runs == 1); 49 50 } 51 52 @("TreeActions are reusable") 53 unittest { 54 55 auto action = new CountNodesAction; 56 auto root = vspace(); 57 58 root.startAction(action); 59 root.draw(); 60 assert(action.runs == 1); 61 62 root.startAction(action); 63 root.draw(); 64 assert(action.runs == 2); 65 66 root.startAction(action); 67 root.draw(); 68 assert(action.runs == 3); 69 70 } 71 72 @("TreeActions can be chained") 73 unittest { 74 75 IntInput input; 76 ScrollFrame scrollFrame; 77 Space innerSpace; 78 79 auto root = testSpace( 80 scrollFrame = vscrollFrame( 81 vspace(), 82 innerSpace = vspace( 83 input = intInput(), 84 ), 85 ), 86 ); 87 88 const frames = root.focusChild() 89 .then((Node a) @trusted => assert(a == scrollFrame.scrollBar)) 90 .then(() => scrollFrame.focusChild()) 91 .then((Node a) @trusted => assert(a == scrollFrame.scrollBar)) 92 .then(() => innerSpace.focusChild()) 93 .then((Node a) @trusted => assert(a == input)) 94 .runWhileDrawing(root); 95 96 assert(frames == 3); 97 98 }