Skip to main content

servoshell/desktop/
dialog.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::path::PathBuf;
6use std::pin::Pin;
7use std::sync::Arc;
8use std::task::{Context, Poll, Waker};
9
10use egui::{Area, Button, CornerRadius, Frame, Id, Modal, Order, RichText, Sense, Stroke, Vec2};
11use itertools::Either;
12use log::{error, warn};
13use rfd::AsyncFileDialog;
14use servo::{
15    AlertDialog, AuthenticationRequest, BluetoothDeviceSelectionRequest, ColorPicker,
16    ConfirmDialog, ContextMenu, ContextMenuItem, DeviceIntRect, EmbedderControlId, FilePicker,
17    PermissionRequest, PromptDialog, RgbColor, SelectElement, SelectElementOption,
18    SelectElementOptionOrOptgroup, SimpleDialog,
19};
20use winit::window::Window as WinitWindow;
21
22use crate::desktop::event_loop::RepaintEventLoopWaker;
23
24/// The minimum width of many UI elements including dialog boxes and menus,
25/// for the sake of consistency.
26const MINIMUM_UI_ELEMENT_WIDTH: f32 = 150.0;
27
28pub enum Dialog {
29    File {
30        future: Pin<Box<dyn Future<Output = Option<Vec<PathBuf>>>>>,
31        waker: Waker,
32        maybe_picker: Option<FilePicker>,
33    },
34    Alert(Option<AlertDialog>),
35    Confirm(Option<ConfirmDialog>),
36    Prompt(Option<PromptDialog>),
37    Authentication {
38        username: String,
39        password: String,
40        request: Option<AuthenticationRequest>,
41    },
42    Permission {
43        message: String,
44        request: Option<PermissionRequest>,
45    },
46    SelectDevice {
47        request: Option<BluetoothDeviceSelectionRequest>,
48        selected_device_index: usize,
49    },
50    SelectElement {
51        maybe_prompt: Option<SelectElement>,
52    },
53    ColorPicker {
54        current_color: egui::Color32,
55        maybe_prompt: Option<ColorPicker>,
56    },
57    ContextMenu {
58        menu: Option<ContextMenu>,
59    },
60}
61
62impl Dialog {
63    pub fn new_file_dialog(
64        file_picker: FilePicker,
65        window: &WinitWindow,
66        waker: RepaintEventLoopWaker,
67    ) -> Self {
68        let mut dialog = AsyncFileDialog::new().set_parent(&window);
69        if !file_picker.filter_patterns().is_empty() {
70            let filters: Vec<_> = file_picker
71                .filter_patterns()
72                .iter()
73                .map(|pattern| pattern.0.clone())
74                .collect();
75            dialog = dialog.add_filter("All Supported Types", &filters);
76        }
77
78        // We need to call `pick_files` / pick_file` outside of the closure here
79        // in order to ensure they are called at least one time to trigger the
80        // dialog properly.
81        // `webkitdirectory` only allows selecting one folder.
82        let future = if file_picker.select_directory() {
83            Either::Right(Either::Left(dialog.pick_folder()))
84        } else if file_picker.allow_select_multiple() {
85            Either::Left(dialog.pick_files())
86        } else {
87            Either::Right(Either::Right(dialog.pick_file()))
88        };
89
90        let future = Box::pin(async move {
91            let handles = match future {
92                Either::Left(future) => future.await,
93                Either::Right(Either::Left(folder)) => folder.await.map(|handle| vec![handle]),
94                Either::Right(Either::Right(file)) => file.await.map(|handle| vec![handle]),
95            };
96            handles.map(|handles| {
97                handles
98                    .iter()
99                    .map(|handle| handle.path().to_owned())
100                    .collect::<Vec<_>>()
101            })
102        });
103
104        Dialog::File {
105            future,
106            waker: Waker::from(Arc::new(waker)),
107            maybe_picker: Some(file_picker),
108        }
109    }
110
111    pub fn new_simple_dialog(dialog: SimpleDialog) -> Self {
112        match dialog {
113            SimpleDialog::Alert(alert_dialog) => Self::Alert(Some(alert_dialog)),
114            SimpleDialog::Confirm(confirm_dialog) => Self::Confirm(Some(confirm_dialog)),
115            SimpleDialog::Prompt(prompt_dialog) => Self::Prompt(Some(prompt_dialog)),
116        }
117    }
118
119    pub fn new_authentication_dialog(authentication_request: AuthenticationRequest) -> Self {
120        Dialog::Authentication {
121            username: String::new(),
122            password: String::new(),
123            request: Some(authentication_request),
124        }
125    }
126
127    pub fn new_permission_request_dialog(permission_request: PermissionRequest) -> Self {
128        let message = format!(
129            "Do you want to grant permission for {:?}?",
130            permission_request.feature()
131        );
132        Dialog::Permission {
133            message,
134            request: Some(permission_request),
135        }
136    }
137
138    pub fn new_device_selection_dialog(request: BluetoothDeviceSelectionRequest) -> Self {
139        Dialog::SelectDevice {
140            request: Some(request),
141            selected_device_index: 0,
142        }
143    }
144
145    pub fn new_select_element_dialog(prompt: SelectElement) -> Self {
146        Dialog::SelectElement {
147            maybe_prompt: Some(prompt),
148        }
149    }
150
151    pub fn new_color_picker_dialog(prompt: ColorPicker) -> Self {
152        let current_color = prompt
153            .current_color()
154            .map(|color| egui::Color32::from_rgb(color.red, color.green, color.blue))
155            .unwrap_or_default();
156        Dialog::ColorPicker {
157            current_color,
158            maybe_prompt: Some(prompt),
159        }
160    }
161
162    /// Returns false if the dialog has been closed, or true otherwise.
163    pub fn update(&mut self, ctx: &egui::Context, webview_rect: egui::Rect) -> bool {
164        enum DialogAction {
165            Dismiss,
166            Submit,
167            Continue,
168        }
169
170        match self {
171            Dialog::File {
172                future,
173                waker,
174                maybe_picker,
175            } => {
176                let action = match maybe_picker.as_mut() {
177                    Some(picker) => {
178                        let mut context = Context::from_waker(waker);
179                        match future.as_mut().poll(&mut context) {
180                            Poll::Ready(Some(file_paths)) => {
181                                picker.select(&file_paths);
182                                DialogAction::Submit
183                            },
184                            Poll::Ready(None) => DialogAction::Dismiss,
185                            Poll::Pending => DialogAction::Continue,
186                        }
187                    },
188                    None => DialogAction::Dismiss,
189                };
190
191                match action {
192                    DialogAction::Dismiss => {
193                        if let Some(picker) = maybe_picker.take() {
194                            picker.dismiss();
195                        }
196                    },
197                    DialogAction::Submit => {
198                        if let Some(picker) = maybe_picker.take() {
199                            picker.submit();
200                        }
201                    },
202                    DialogAction::Continue => {},
203                }
204                matches!(action, DialogAction::Continue)
205            },
206            Dialog::Alert(maybe_alert_dialog) => {
207                let Some(alert_dialog) = maybe_alert_dialog else {
208                    return false;
209                };
210
211                let mut is_open = true;
212                Modal::new("Alert".into()).show(ctx, |ui| {
213                    make_dialog_label(alert_dialog.message(), ui, None);
214                    egui::Sides::new().show(
215                        ui,
216                        |_ui| {},
217                        |ui| {
218                            if ui.button("Close").clicked() ||
219                                ui.input(|i| i.key_pressed(egui::Key::Escape))
220                            {
221                                is_open = false;
222                            }
223                        },
224                    );
225                });
226
227                if !is_open && let Some(alert_dialog) = maybe_alert_dialog.take() {
228                    alert_dialog.confirm();
229                }
230                is_open
231            },
232            Dialog::Confirm(maybe_confirm_dialog) => {
233                let Some(confirm_dialog) = maybe_confirm_dialog else {
234                    return false;
235                };
236
237                let mut dialog_action = DialogAction::Continue;
238                Modal::new("Confirm".into()).show(ctx, |ui| {
239                    make_dialog_label(confirm_dialog.message(), ui, None);
240                    egui::Sides::new().show(
241                        ui,
242                        |_ui| {},
243                        |ui| {
244                            if ui.button("Ok").clicked() ||
245                                ui.input(|i| i.key_pressed(egui::Key::Enter))
246                            {
247                                dialog_action = DialogAction::Submit;
248                            }
249                            if ui.button("Cancel").clicked() ||
250                                ui.input(|i| i.key_pressed(egui::Key::Escape))
251                            {
252                                dialog_action = DialogAction::Dismiss;
253                            }
254                        },
255                    );
256                });
257
258                match dialog_action {
259                    DialogAction::Dismiss => {
260                        if let Some(confirm_dialog) = maybe_confirm_dialog.take() {
261                            confirm_dialog.dismiss();
262                        }
263                        false
264                    },
265                    DialogAction::Submit => {
266                        if let Some(confirm_dialog) = maybe_confirm_dialog.take() {
267                            confirm_dialog.confirm();
268                        }
269                        false
270                    },
271                    DialogAction::Continue => true,
272                }
273            },
274            Dialog::Prompt(maybe_prompt_dialog) => {
275                let Some(prompt_dialog) = maybe_prompt_dialog else {
276                    return false;
277                };
278
279                let mut dialog_action = DialogAction::Continue;
280                Modal::new("Prompt".into()).show(ctx, |ui| {
281                    let mut prompt_text = prompt_dialog.current_value().to_owned();
282                    make_dialog_label(prompt_dialog.message(), ui, Some(&mut prompt_text));
283                    egui::Sides::new().show(
284                        ui,
285                        |_ui| {},
286                        |ui| {
287                            if ui.button("Ok").clicked() ||
288                                ui.input(|i| i.key_pressed(egui::Key::Enter))
289                            {
290                                prompt_dialog.set_current_value(&prompt_text);
291                                dialog_action = DialogAction::Submit;
292                            }
293                            if ui.button("Cancel").clicked() ||
294                                ui.input(|i| i.key_pressed(egui::Key::Escape))
295                            {
296                                dialog_action = DialogAction::Dismiss;
297                            }
298                        },
299                    );
300                    prompt_dialog.set_current_value(&prompt_text);
301                });
302                match dialog_action {
303                    DialogAction::Dismiss => {
304                        if let Some(prompt_dialog) = maybe_prompt_dialog.take() {
305                            prompt_dialog.dismiss();
306                        }
307                        false
308                    },
309                    DialogAction::Submit => {
310                        if let Some(prompt_dialog) = maybe_prompt_dialog.take() {
311                            prompt_dialog.confirm();
312                        }
313                        false
314                    },
315                    DialogAction::Continue => true,
316                }
317            },
318            Dialog::Authentication {
319                username,
320                password,
321                request,
322            } => {
323                let mut is_open = true;
324                Modal::new("authentication".into()).show(ctx, |ui| {
325                    let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
326                    frame.content_ui.set_min_width(MINIMUM_UI_ELEMENT_WIDTH);
327
328                    if let Some(request) = request {
329                        let url =
330                            egui::RichText::new(request.url().origin().unicode_serialization());
331                        frame.content_ui.heading(url);
332                    }
333
334                    frame.content_ui.add_space(10.0);
335
336                    frame
337                        .content_ui
338                        .label("This site is asking you to sign in.");
339                    frame.content_ui.add_space(10.0);
340
341                    frame.content_ui.label("Username:");
342                    frame.content_ui.text_edit_singleline(username);
343                    frame.content_ui.add_space(10.0);
344
345                    frame.content_ui.label("Password:");
346                    frame
347                        .content_ui
348                        .add(egui::TextEdit::singleline(password).password(true));
349
350                    frame.end(ui);
351
352                    egui::Sides::new().show(
353                        ui,
354                        |_ui| {},
355                        |ui| {
356                            if ui.button("Sign in").clicked() ||
357                                ui.input(|i| i.key_pressed(egui::Key::Enter))
358                            {
359                                let request =
360                                    request.take().expect("non-None until dialog is closed");
361                                request.authenticate(username.clone(), password.clone());
362                                is_open = false;
363                            }
364                            if ui.button("Cancel").clicked() ||
365                                ui.input(|i| i.key_pressed(egui::Key::Escape))
366                            {
367                                is_open = false;
368                            }
369                        },
370                    );
371                });
372                is_open
373            },
374            Dialog::Permission { message, request } => {
375                let mut is_open = true;
376                let modal = Modal::new("permission".into());
377                modal.show(ctx, |ui| {
378                    make_dialog_label(message, ui, None);
379                    egui::Sides::new().show(
380                        ui,
381                        |_ui| {},
382                        |ui| {
383                            if ui.button("Allow").clicked() ||
384                                ui.input(|i| i.key_pressed(egui::Key::Enter))
385                            {
386                                let request =
387                                    request.take().expect("non-None until dialog is closed");
388                                request.allow();
389                                is_open = false;
390                            }
391                            if ui.button("Deny").clicked() ||
392                                ui.input(|i| i.key_pressed(egui::Key::Escape))
393                            {
394                                let request =
395                                    request.take().expect("non-None until dialog is closed");
396                                request.deny();
397                                is_open = false;
398                            }
399                        },
400                    );
401                });
402                is_open
403            },
404            Dialog::SelectDevice {
405                request,
406                selected_device_index,
407            } => {
408                let mut is_open = true;
409                let modal = Modal::new("device_picker".into());
410                modal.show(ctx, |ui| {
411                    if let Some(request) = request {
412                        let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
413                        frame.content_ui.set_min_width(MINIMUM_UI_ELEMENT_WIDTH);
414
415                        frame.content_ui.heading("Choose a Device");
416                        frame.content_ui.add_space(10.0);
417
418                        let devices = request.devices();
419                        let combo_box =
420                            if let Some(selected_device) = devices.get(*selected_device_index) {
421                                egui::ComboBox::from_label("")
422                                    .selected_text(selected_device.name.clone())
423                            } else {
424                                egui::ComboBox::from_label("")
425                            };
426
427                        combo_box.show_ui(&mut frame.content_ui, |ui| {
428                            for (i, device) in devices.iter().enumerate() {
429                                ui.selectable_value(selected_device_index, i, device.name.clone());
430                            }
431                        });
432
433                        frame.end(ui);
434                    } else {
435                        error!("Unexpected: None SelectDevice while the dialog is open");
436                    }
437
438                    egui::Sides::new().show(
439                        ui,
440                        |_ui| {},
441                        |ui| {
442                            let ok_button = egui::Button::new("Ok");
443                            let has_selected_device = request.as_ref().is_some_and(|request| {
444                                request.devices().get(*selected_device_index).is_some()
445                            });
446                            if ui.add_enabled(has_selected_device, ok_button).clicked() ||
447                                (has_selected_device &&
448                                    ui.input(|i| i.key_pressed(egui::Key::Enter)))
449                            {
450                                let request =
451                                    request.take().expect("non-None until dialog is closed");
452                                let choice = &request.devices()[*selected_device_index].clone();
453                                if let Err(error) = request.pick_device(choice) {
454                                    warn!("Failed to send device selection: {error}");
455                                }
456                                is_open = false;
457                            }
458                            if ui.button("Cancel").clicked() ||
459                                ui.input(|i| i.key_pressed(egui::Key::Escape))
460                            {
461                                let request =
462                                    request.take().expect("non-None until dialog is closed");
463                                if let Err(error) = request.cancel() {
464                                    warn!("Failed to send cancellation: {error}");
465                                }
466                                is_open = false;
467                            }
468                        },
469                    );
470                });
471                is_open
472            },
473            Dialog::SelectElement { maybe_prompt } => {
474                let Some(prompt) = maybe_prompt else {
475                    // Prompt was dismissed, so the dialog should be closed too.
476                    return false;
477                };
478                let mut is_open = true;
479
480                let rect = Self::webview_rect_to_egui_rect(ctx, webview_rect, prompt.position());
481                let area =
482                    egui::Area::new(egui::Id::new("select-window")).fixed_pos(rect.left_bottom());
483
484                let mut selected_options = prompt.selected_options();
485
486                fn display_option(
487                    ui: &mut egui::Ui,
488                    option: &SelectElementOption,
489                    selected_options: &mut Vec<usize>,
490                    is_open: &mut bool,
491                    in_group: bool,
492                    allow_multiple: bool,
493                ) {
494                    let is_checked = selected_options.contains(&option.id);
495
496                    // TODO: Surely there's a better way to align text in a selectable label in egui.
497                    let label_text = if in_group {
498                        format!("   {}", option.label)
499                    } else {
500                        option.label.to_owned()
501                    };
502                    let label = if option.is_disabled {
503                        egui::RichText::new(&label_text).strikethrough()
504                    } else {
505                        egui::RichText::new(&label_text)
506                    };
507                    let clickable_area = ui
508                        .allocate_ui_with_layout(
509                            [ui.available_width(), 0.0].into(),
510                            egui::Layout::top_down_justified(egui::Align::LEFT),
511                            |ui| ui.selectable_label(is_checked, label),
512                        )
513                        .inner;
514
515                    if clickable_area.clicked() && !option.is_disabled {
516                        if allow_multiple {
517                            if let Some(position) =
518                                selected_options.iter().position(|id| *id == option.id)
519                            {
520                                selected_options.remove(position);
521                            } else {
522                                selected_options.push(option.id);
523                            }
524                        } else {
525                            selected_options.clear();
526                            selected_options.push(option.id);
527                        }
528                        if !allow_multiple {
529                            *is_open = false;
530                        }
531                    }
532
533                    if clickable_area.hovered() && option.is_disabled {
534                        ui.ctx().set_cursor_icon(egui::CursorIcon::NotAllowed);
535                    }
536
537                    if ui.ctx().input(|i| i.key_pressed(egui::Key::Escape)) {
538                        *is_open = false;
539                    }
540                }
541
542                let modal = Modal::new("select_element_picker".into()).area(area);
543                let backdrop_response = modal
544                    .show(ctx, |ui| {
545                        egui::ScrollArea::vertical().show(ui, |ui| {
546                            for option_or_optgroup in prompt.options() {
547                                match &option_or_optgroup {
548                                    SelectElementOptionOrOptgroup::Option(option) => {
549                                        display_option(
550                                            ui,
551                                            option,
552                                            &mut selected_options,
553                                            &mut is_open,
554                                            false,
555                                            prompt.allow_select_multiple(),
556                                        );
557                                    },
558                                    SelectElementOptionOrOptgroup::Optgroup { label, options } => {
559                                        ui.label(RichText::new(label).strong());
560
561                                        for option in options {
562                                            display_option(
563                                                ui,
564                                                option,
565                                                &mut selected_options,
566                                                &mut is_open,
567                                                true,
568                                                prompt.allow_select_multiple(),
569                                            );
570                                        }
571                                    },
572                                }
573                            }
574                        });
575                    })
576                    .backdrop_response;
577
578                // FIXME: Doesn't update until you move your mouse or press a key - why?
579                if backdrop_response.clicked() {
580                    is_open = false;
581                }
582
583                prompt.select(selected_options);
584
585                if !is_open {
586                    maybe_prompt.take().unwrap().submit();
587                }
588
589                is_open
590            },
591            Dialog::ColorPicker {
592                current_color,
593                maybe_prompt,
594            } => {
595                let Some(prompt) = maybe_prompt else {
596                    // Prompt was dismissed, so the dialog should be closed too.
597                    return false;
598                };
599                let mut is_open = true;
600
601                let rect = Self::webview_rect_to_egui_rect(ctx, webview_rect, prompt.position());
602                let area =
603                    egui::Area::new(egui::Id::new("select-window")).fixed_pos(rect.left_bottom());
604
605                let modal = Modal::new("select_element_picker".into()).area(area);
606                let backdrop_response = modal
607                    .show(ctx, |ui| {
608                        egui::widgets::color_picker::color_picker_color32(
609                            ui,
610                            current_color,
611                            egui::widgets::color_picker::Alpha::Opaque,
612                        );
613
614                        ui.add_space(10.);
615
616                        if ui.button("Dismiss").clicked() ||
617                            ui.input(|i| i.key_pressed(egui::Key::Escape))
618                        {
619                            is_open = false;
620                            prompt.select(None);
621                        }
622                        if ui.button("Select").clicked() {
623                            is_open = false;
624                            let selected_color = RgbColor {
625                                red: current_color.r(),
626                                green: current_color.g(),
627                                blue: current_color.b(),
628                            };
629                            prompt.select(Some(selected_color));
630                        }
631                    })
632                    .backdrop_response;
633
634                // FIXME: Doesn't update until you move your mouse or press a key - why?
635                if backdrop_response.clicked() {
636                    is_open = false;
637                }
638
639                is_open
640            },
641            Dialog::ContextMenu { menu } => {
642                let mut is_open = true;
643                if let Some(context_menu) = menu {
644                    let mut selected_action = None;
645                    let rect =
646                        Self::webview_rect_to_egui_rect(ctx, webview_rect, context_menu.position());
647
648                    let response = Area::new(Id::new("context_menu"))
649                        .fixed_pos(rect.left_bottom())
650                        .order(Order::Foreground)
651                        .show(ctx, |ui| {
652                            Frame::popup(ui.style()).show(ui, |ui| {
653                                ui.set_min_width(MINIMUM_UI_ELEMENT_WIDTH);
654                                for item in context_menu.items() {
655                                    match item {
656                                        ContextMenuItem::Item {
657                                            label,
658                                            action,
659                                            enabled,
660                                        } => {
661                                            let (color, sense) = match enabled {
662                                                true => (
663                                                    ui.visuals().strong_text_color(),
664                                                    Sense::click(),
665                                                ),
666                                                false => {
667                                                    (ui.visuals().weak_text_color(), Sense::empty())
668                                                },
669                                            };
670
671                                            {
672                                                let panel_fill = ui.visuals().panel_fill;
673                                                let style = ui.style_mut();
674                                                let widgets = &mut style.visuals.widgets;
675
676                                                widgets.inactive.weak_bg_fill = panel_fill;
677                                                widgets.inactive.bg_fill = panel_fill;
678
679                                                // Disable stroke for all button types in the menu.
680                                                widgets.active.bg_stroke = Stroke::NONE;
681                                                widgets.inactive.bg_stroke = Stroke::NONE;
682                                                widgets.hovered.bg_stroke = Stroke::NONE;
683                                                widgets.noninteractive.bg_stroke = Stroke::NONE;
684                                            }
685
686                                            let button =
687                                                Button::new(RichText::new(label).color(color))
688                                                    .sense(sense)
689                                                    .corner_radius(CornerRadius::ZERO)
690                                                    .wrap_mode(egui::TextWrapMode::Extend)
691                                                    .min_size(Vec2 {
692                                                        x: MINIMUM_UI_ELEMENT_WIDTH,
693                                                        y: 0.0,
694                                                    });
695
696                                            if ui.add(button).clicked() {
697                                                selected_action = Some(*action);
698                                                ui.close();
699                                            }
700                                        },
701                                        ContextMenuItem::Separator => {
702                                            ui.separator();
703                                        },
704                                    }
705                                }
706                            })
707                        });
708
709                    if response.response.clicked_elsewhere() {
710                        is_open = false;
711                    }
712
713                    if let Some(action) = selected_action &&
714                        let Some(context_menu) = menu.take()
715                    {
716                        context_menu.select(action);
717                        return false;
718                    }
719                }
720                is_open
721            },
722        }
723    }
724
725    pub(crate) fn embedder_control_id(&self) -> Option<EmbedderControlId> {
726        match self {
727            Dialog::SelectElement { maybe_prompt, .. } => {
728                maybe_prompt.as_ref().map(|element| element.id())
729            },
730            Dialog::ColorPicker { maybe_prompt, .. } => {
731                maybe_prompt.as_ref().map(|element| element.id())
732            },
733            Dialog::ContextMenu { menu, .. } => menu.as_ref().map(|menu| menu.id()),
734            _ => None,
735        }
736    }
737
738    pub(crate) fn new_context_menu(menu: ContextMenu) -> Dialog {
739        Dialog::ContextMenu { menu: Some(menu) }
740    }
741
742    fn webview_rect_to_egui_rect(
743        context: &egui::Context,
744        webview_rect: egui::Rect,
745        rect: DeviceIntRect,
746    ) -> egui::Rect {
747        let rect = rect.to_f32() / context.pixels_per_point();
748        egui::Rect::from_min_max(
749            egui::Pos2::new(rect.min.x, rect.min.y),
750            egui::Pos2::new(rect.max.x, rect.max.y),
751        )
752        .translate(webview_rect.min.to_vec2())
753    }
754}
755
756fn make_dialog_label(message: &str, ui: &mut egui::Ui, input_text: Option<&mut String>) {
757    let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
758    frame.content_ui.set_min_width(MINIMUM_UI_ELEMENT_WIDTH);
759    frame.content_ui.label(message);
760    if let Some(input_text) = input_text {
761        frame.content_ui.text_edit_singleline(input_text);
762    }
763    frame.end(ui);
764}