|
| 1 | +import { makeScene2D, Code, LezerHighlighter, lines } from '@motion-canvas/2d'; |
| 2 | +import { all, createRef, waitFor } from '@motion-canvas/core'; |
| 3 | +import { MyStyle } from '../../styles'; |
| 4 | +import { parser as parser_cpp } from '@lezer/cpp'; |
| 5 | +import { DEFAULT } from '@motion-canvas/core/lib/signals'; |
| 6 | +import { centerOn } from '../../utils'; |
| 7 | + |
| 8 | +import templateCode from '@lectures/std_function.md?snippet=std_function/template_button.cpp'; |
| 9 | +import stdFunctionCode from '@lectures/std_function.md?snippet=std_function/std_function_button.cpp'; |
| 10 | +import multiButtonCode from '@lectures/std_function.md?snippet=std_function/multi_button.cpp'; |
| 11 | +import typeErasureCode from '@lectures/std_function.md?snippet=std_function/type_erasure.cpp'; |
| 12 | + |
| 13 | +const CppHighlighter = new LezerHighlighter(parser_cpp, MyStyle); |
| 14 | + |
| 15 | +export default makeScene2D(function* (view) { |
| 16 | + const codeRef = createRef<Code>(); |
| 17 | + |
| 18 | + view.add( |
| 19 | + <Code |
| 20 | + ref={codeRef} |
| 21 | + fontSize={26} |
| 22 | + fontFamily={'Fira Mono'} |
| 23 | + highlighter={CppHighlighter} |
| 24 | + code={templateCode} |
| 25 | + /> |
| 26 | + ); |
| 27 | + |
| 28 | + // Initial delay |
| 29 | + yield* waitFor(1); |
| 30 | + |
| 31 | + // 1. Template Button |
| 32 | + yield* centerOn(codeRef(), lines(4, 5), 1, 40); // template <typename Callback> |
| 33 | + yield* waitFor(3); |
| 34 | + |
| 35 | + yield* centerOn(codeRef(), lines(17, 17), 1, 40); // Callback on_click_; |
| 36 | + yield* waitFor(3); |
| 37 | + |
| 38 | + yield* centerOn(codeRef(), DEFAULT, 1, 28); |
| 39 | + yield* waitFor(2); |
| 40 | + |
| 41 | + // 3. std::function Button |
| 42 | + yield* codeRef().code(templateCode, 0); |
| 43 | + yield* centerOn(codeRef(), DEFAULT, 0, 24); |
| 44 | + yield* waitFor(1); |
| 45 | + yield* codeRef().code(stdFunctionCode, 1); |
| 46 | + yield* waitFor(1); |
| 47 | + |
| 48 | + yield* centerOn(codeRef(), lines(8, 9), 1, 40); // explicit Button(std::string name, std::function<void()> callback) |
| 49 | + yield* waitFor(3); |
| 50 | + |
| 51 | + yield* centerOn(codeRef(), lines(18, 18), 1, 40); // std::function<void()> on_click_; |
| 52 | + yield* waitFor(3); |
| 53 | + |
| 54 | + yield* centerOn(codeRef(), lines(30, 30), 1, 40); // std::vector<Button> buttons{play_button, quit_button}; |
| 55 | + yield* waitFor(3); |
| 56 | + |
| 57 | + yield* centerOn(codeRef(), DEFAULT, 1, 28); |
| 58 | + yield* waitFor(2); |
| 59 | + |
| 60 | + // 4. MultiButton |
| 61 | + yield* codeRef().code(multiButtonCode, 1); |
| 62 | + yield* waitFor(1); |
| 63 | + |
| 64 | + yield* centerOn(codeRef(), lines(23, 23), 1, 40); // std::vector<std::function<void()>> on_click_callbacks_; |
| 65 | + yield* waitFor(3); |
| 66 | + |
| 67 | + yield* centerOn(codeRef(), DEFAULT, 1, 28); |
| 68 | + yield* waitFor(2); |
| 69 | + |
| 70 | + // 5. Type Erasure |
| 71 | + yield* codeRef().code(typeErasureCode, 1); |
| 72 | + yield* waitFor(1); |
| 73 | + |
| 74 | + yield* centerOn(codeRef(), lines(21, 24), 1, 36); // CallableBase |
| 75 | + yield* waitFor(3); |
| 76 | + |
| 77 | + yield* centerOn(codeRef(), lines(29, 36), 1, 36); // CallableImpl |
| 78 | + yield* waitFor(3); |
| 79 | + |
| 80 | + yield* centerOn(codeRef(), lines(6, 11), 1, 36); // MyFunction constructor |
| 81 | + yield* waitFor(3); |
| 82 | + |
| 83 | + yield* centerOn(codeRef(), lines(41, 41), 1, 36); // std::unique_ptr<CallableBase> callable_; |
| 84 | + yield* waitFor(3); |
| 85 | + |
| 86 | + yield* centerOn(codeRef(), DEFAULT, 1, 28); |
| 87 | + yield* waitFor(3); |
| 88 | +}); |
0 commit comments