MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / AsyncTextInput

Class AsyncTextInput

src/AsyncDialog.cpp:162–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162struct AsyncTextInput : OpaqueWidget
163{
164 static const constexpr float margin = 10;
165 static const constexpr float buttonWidth = 100;
166
167 AsyncTextInput(const char* const message, const char* const text, const std::function<void(char* newText)> action)
168 {
169 box.size = math::Vec(400, 80);
170
171 SequentialLayout* const layout = new SequentialLayout;
172 layout->box.pos = math::Vec(0, 0);
173 layout->box.size = box.size;
174 layout->orientation = SequentialLayout::VERTICAL_ORIENTATION;
175 layout->margin = math::Vec(margin, margin);
176 layout->spacing = math::Vec(margin, margin);
177 layout->wrap = false;
178 addChild(layout);
179
180 SequentialLayout* const contentLayout = new SequentialLayout;
181 contentLayout->box.size.x = box.size.x - 2*margin;
182 contentLayout->box.size.y = box.size.y / 2 - margin;
183 contentLayout->spacing = math::Vec(margin, margin);
184 layout->addChild(contentLayout);
185
186 SequentialLayout* const buttonLayout = new SequentialLayout;
187 buttonLayout->alignment = SequentialLayout::CENTER_ALIGNMENT;
188 buttonLayout->box.size.x = box.size.x - 2*margin;
189 buttonLayout->box.size.y = box.size.y / 2 - margin;
190 buttonLayout->spacing = math::Vec(margin, margin);
191 layout->addChild(buttonLayout);
192
193 Label* label;
194 if (message != nullptr)
195 {
196 label = new Label;
197 nvgFontSize(APP->window->vg, 14);
198 label->box.size.x = std::min(bndLabelWidth(APP->window->vg, -1, message) + margin,
199 box.size.x / 2 - margin);
200 label->box.size.y = contentLayout->box.size.y;
201 label->fontSize = 14;
202 label->text = message;
203 contentLayout->addChild(label);
204 }
205 else
206 {
207 label = nullptr;
208 }
209
210 struct AsyncTextField : TextField {
211 AsyncTextInput* dialog;
212 std::function<void(char*)> action;
213 void onSelectKey(const SelectKeyEvent& e) override {
214 if (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)
215 {
216 e.consume(this);
217 action(strdup(text.c_str()));
218 dialog->getParent()->requestDelete();
219 return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected