-
Notifications
You must be signed in to change notification settings - Fork 1
Modals
Modals are the base class for dialogs, that are overlayed over the form.
To create a custom modal, derive from abstract class Modal
and set its properties.
var modal = new CustomModal();
await modal.ShowAsync();
// ...
class CustomModal : Modal
{
public CustomModal()
{
Caption = "Title";
Content = new Label("Content");
Size = new Size(SizeValue.Relative(.2f), SizeValue.Relative(.1f));
Result = DialogResult.Cancel;
}
}
-
Caption
: The localizable text in the header of the dialog -
Content
: The content component of the dialog -
BlockFormClosing
: If the dialog cancels closing the application and has to be closed first -
OkAction
: TheKeyCommand
to setResult
toDialogResult.Ok
and closes the dialog -
CancelAction
: TheKeyCommand
to setResult
toDialogResult.Cancel
and closes the dialog -
Result
: Protected; Is theDialogResult
returned by methodShowAsync
, when the dialog was closed -
Size
: The size of the dialog
-
ShowAsync
: Opens and renders the dialog asynchronously and returns theResult
when it was closed; Can setBlockFormClosing
directly -
Close
: Closes the dialog programmatically; Optionally sets a differentResult
-
ShowInternal
: Virtual; Protected; Is called directly after the dialog was opened -
CloseInternal
: Virtual; Protected; Is called directly after the dialog was closed -
ShouldCancelClose
: Virtual; Protected; Is called directly before the dialog closes; Can cancel the operation
A messagebox with a caption, text, type, and selectable buttons.
Show an error messagebox:
await MessageBox.ShowErrorAsync("Error", "An error occurred.");
Show an information messagebox:
await MessageBox.ShowInformationAsync("Info", "This is an information.");
Show a messagebox with Yes and No buttons:
await MessageBox.ShowYesNoAsync("Question", "Do you want to continue?");
Show a messagebox with Yes, No, and Cancel buttons:
await MessageBox.ShowYesNoCancelAsync("Question", "Do you want to continue?");
Show a custom messagebox:
var messagebox = new MessageBox("Custom", "A messagebox appeared.",
MessageBoxType.Warning, MessageBoxButton.No | MessageBoxButton.Cancel);
await messagebox.ShowAsync();
The button captions are localizable with localization IDs:
-
ImGui.Button.Ok
: The localization ID for theOk
button; Falls back to english localization "Ok" -
ImGui.Button.Yes
: The localization ID for theYes
button; Falls back to english localization "Yes" -
ImGui.Button.No
: The localization ID for theNo
button; Falls back to english localization "No" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel"
A simple modal with a combobox to select an item.
To show a combobox input:
await ComboInputBox.ShowAsync("Choice", "Choose an item from the list below.",
new LocalizedString[] { "Item1", "Item2" }, "Item1");
-
ImGui.Button.Ok
: The localization ID for theOk
button; Falls back to english localization "Ok" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel"
A simple modal with a textbox.
To show an inputbox:
await InputBox.ShowAsync("Input", "Input your text:", "Preset", "No value");
-
ImGui.Button.Ok
: The localization ID for theOk
button; Falls back to english localization "Ok" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel"
A modal to select a file on the host's filesystem to open.
The native Windows OpenFileDialog can be accessed with WindowsOpenFileDialog
.
If the host does not run Windows, it falls back to OpenFileDialog
.
To retrieve a file selected by the user:
var ofd = new OpenFileDialog();
var result = await ofd.ShowAsync();
if (result != DialogResult.Ok)
return;
var selectedPath = ofd.SelectedPath;
-
InitialDirectory
: The initial directory, from which the user starts navigating -
InitialFileName
: The pre-selected file inInitialDirectory
to allow for selection shortcuts -
FileFilters
: A list of file filters to filter the file view by extensions; See "FileFilter" for more information -
SelectedPath
: The path selected by the user, after they successfully closed the modal
-
ImGui.Button.Ok
: The localization ID for theOk
button; Falls back to english localization "Ok" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel" -
ImGui.FileDialog.Search
: The localization ID for the search bar placeholder; Falls back to english localization "Search..." -
ImGui.FileDialog.Name
: The localization ID for file name table header; Falls back to english localization "Name" -
ImGui.FileDialog.Type
: The localization ID for file type table header; Falls back to english localization "Type" -
ImGui.FileDialog.DateModified
: The localization ID for modified date table header; Falls back to english localization "Date Modified" -
ImGui.FileDialog.SelectedFile
: The localization ID for selected file label; Falls back to english localization "File Name:"
A single file filter use in file dialogs.
To create single file filter:
var filter = new FileFilter("Image Files", "png", "jpg", "bin.image");
-
Name
: The localizable name of the filter -
Extensions
: A list of extensions for this filter
A modal to select a file on the host's filesystem to save.
The native Windows SaveFileDialog can be accessed with WindowsSaveFileDialog
.
If the host does not run Windows, it falls back to SaveFileDialog
.
To retrieve a file selected by the user:
var sfd = new SaveFileDialog();
var result = await sfd.ShowAsync();
if (result != DialogResult.Ok)
return;
var selectedPath = sfd.SelectedPath;
-
InitialDirectory
: The initial directory, from which the user starts navigating -
SelectedPath
: The path selected by the user, after they successfully closed the modal
-
ImGui.Button.Save
: The localization ID for theSave
button; Falls back to english localization "Save" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel" -
ImGui.FileDialog.Search
: The localization ID for the search bar placeholder; Falls back to english localization "Search..." -
ImGui.FileDialog.Name
: The localization ID for file name table header; Falls back to english localization "Name" -
ImGui.FileDialog.Type
: The localization ID for file type table header; Falls back to english localization "Type" -
ImGui.FileDialog.DateModified
: The localization ID for modified date table header; Falls back to english localization "Date Modified" -
ImGui.FileDialog.SelectedFile
: The localization ID for selected file label; Falls back to english localization "File Name:" -
ImGui.FileDialog.ReplaceFile.Caption
: The localization ID for the replace file caption; Falls back to english localization "File exists" -
ImGui.FileDialog.ReplaceFile.Text
: The localization ID for the replace file text; Falls back to english localization "Do you want to overwrite file {0}?"
A modal to select a folder on the host's filesystem.
To retrieve a folder selected by the user:
var sfd = new SelectFolderDialog();
var result = await sfd.ShowAsync();
if (result != DialogResult.Ok)
return;
var selectedDirectory = sfd.Directory;
-
ImGui.Button.Ok
: The localization ID for theOk
button; Falls back to english localization "Ok" -
ImGui.Button.Cancel
: The localization ID for theCancel
button; Falls back to english localization "Cancel" -
ImGui.FileDialog.CreateFolder.Caption
: The localization ID for create folder button and inputbox caption; Falls back to english localization "Create folder" -
ImGui.FileDialog.CreateFolder.Text
: The localization ID for create folder inputbox text; Falls back to english localization "New folder name:"