| 34 | using namespace rack::widget; |
| 35 | |
| 36 | struct AsyncDialog : OpaqueWidget |
| 37 | { |
| 38 | static const constexpr float margin = 10; |
| 39 | static const constexpr float buttonWidth = 100; |
| 40 | |
| 41 | SequentialLayout* layout; |
| 42 | SequentialLayout* contentLayout; |
| 43 | SequentialLayout* buttonLayout; |
| 44 | Label* label; |
| 45 | |
| 46 | AsyncDialog(const char* const message) |
| 47 | { |
| 48 | setup(message); |
| 49 | |
| 50 | struct AsyncDismissButton : Button { |
| 51 | AsyncDialog* dialog; |
| 52 | void onAction(const ActionEvent& e) override { |
| 53 | dialog->getParent()->requestDelete(); |
| 54 | } |
| 55 | }; |
| 56 | AsyncDismissButton* const dismissButton = new AsyncDismissButton; |
| 57 | dismissButton->box.size.x = buttonWidth; |
| 58 | dismissButton->text = "Dismiss"; |
| 59 | dismissButton->dialog = this; |
| 60 | buttonLayout->addChild(dismissButton); |
| 61 | } |
| 62 | |
| 63 | AsyncDialog(const char* const message, const std::function<void()> action) |
| 64 | { |
| 65 | setup(message); |
| 66 | |
| 67 | struct AsyncCancelButton : Button { |
| 68 | AsyncDialog* dialog; |
| 69 | void onAction(const ActionEvent& e) override { |
| 70 | dialog->getParent()->requestDelete(); |
| 71 | } |
| 72 | }; |
| 73 | AsyncCancelButton* const cancelButton = new AsyncCancelButton; |
| 74 | cancelButton->box.size.x = buttonWidth; |
| 75 | cancelButton->text = "Cancel"; |
| 76 | cancelButton->dialog = this; |
| 77 | buttonLayout->addChild(cancelButton); |
| 78 | |
| 79 | struct AsyncOkButton : Button { |
| 80 | AsyncDialog* dialog; |
| 81 | std::function<void()> action; |
| 82 | void onAction(const ActionEvent& e) override { |
| 83 | action(); |
| 84 | dialog->getParent()->requestDelete(); |
| 85 | } |
| 86 | }; |
| 87 | AsyncOkButton* const okButton = new AsyncOkButton; |
| 88 | okButton->box.size.x = buttonWidth; |
| 89 | okButton->text = "Ok"; |
| 90 | okButton->dialog = this; |
| 91 | okButton->action = action; |
| 92 | buttonLayout->addChild(okButton); |
| 93 | } |
nothing calls this directly
no outgoing calls
no test coverage detected