Dialogs, forms and files
Dialogs and toasts, settings forms, switches, and the pure-Go file dialog.
Dialogs and toasts#
Window-owned hosts on Ctx. BuildFrame lays them out — do not put them in Body:
c.Toasts().Show("Saved", ui.ToastInfo, 3*time.Second)
c.Dialogs().ShowInfo("Info", "helpful note", nil)
c.Dialogs().ShowWarning("Warning", "check before continuing", nil)
c.Dialogs().ShowError("Error", "request failed", nil)
c.Dialogs().ShowAction("Delete?", "This cannot be undone.", onYes, onNo)
c.Dialogs().ShowDanger("Remove?", "This cannot be undone.", "Remove", onRemove)
c.Dialogs().ShowInput("Name", "placeholder", onOK, onCancel)
c.Dialogs().Show(ui.DialogOpts{
Title: "Settings",
Width: 720,
Height: 520,
Body: func(c *ui.Ctx) ui.View {
return ui.Row(
ui.Nav("cats", ui.NavVertical, ui.NavIconLeft, items...).Width(200),
ui.VLine(th.Stroke.Thin, th.Border),
ui.Scroll("form", ui.Form("settings", rows...)).Grow(1),
).Align(ui.AlignStretch).Grow(1)
},
Actions: []ui.DialogAction{{Label: "Close", Primary: true}},
})Custom dialogs use the same overlay/modal behavior as the file picker. Escape runs OnDismiss. Footer actions close the dialog before OnClick.
Form and Switch#
ui.Form renders labeled settings rows (icon, title, description, control):
ui.Form("prefs",
ui.FormSwitch("notify", "Notifications", "Show alerts", on, func(v bool) { on = v }),
ui.FormSelect("theme", "Theme", "Color scheme", opts, idx, onChange),
ui.FormNumber("size", "Font size", "Editor size in pt", 14, 10, 24, 1, onSize),
ui.FormText("file", "Default file", "Open on startup", name, onName),
ui.FormFile("cert", "Certificate", "PEM for TLS", path, filters, onPath),
)FormFile opens the window's file dialog (c.Files()) in the current file's folder; the button shows the file name, and a clear button passes "" to the callback. Descriptions wrap to the width the control leaves.
ui.FormHeading(title, desc) opens a group of rows. Set Optional on an item to tag its label "Optional", and Placeholder to say what an empty text or file row means (the file button shows it instead of "Choose file…").
ui.Switch(id).Check(on).OnToggle(fn) is an unlabeled pill toggle for compact rows.
File dialog#
Pure-Go file/folder picker (ui.FileDialog) — no native OS dialogs. Call c.Files().Show with options:
c.Files().Show(ui.FileDialogOpts{
Mode: ui.FileDialogOpenFile, // FileDialogOpenFolder | FileDialogSaveFile
Title: "Open File",
Dir: "/path/to/start", // optional; defaults to home
Multiple: false,
Filters: []ui.FileFilter{
{Label: "Go files", Exts: []string{".go"}},
{Label: "All files", Exts: nil},
},
ShowHidden: false,
ShowSaveFilter: true, // file-type filter in save mode (default off)
AllowCreateFolder: true, // New Folder button in the footer
OnConfirm: func(paths []string) { … },
OnCancel: func() { … },
})Modes. FileDialogOpenFile lists files (double-click or Open confirms). FileDialogOpenFolder selects folders only. FileDialogSaveFile adds a filename field; Save confirms the path and applies the selected filter extension when the name has none.
Layout. Places sidebar, breadcrumb + searchable file table in the main pane, and a footer with filename (save mode), file-type filter, optional New Folder (next to Cancel/Save), and Cancel + Open/Select/Save. When creating a folder, an inline name field with Create/Cancel appears in the footer.
Keyboard. Escape cancels. Enter confirms when valid. Tab cycles within the modal dialog.
See example/gallery/gallery.go in yogaui/editor for open file, multi-select, folder pick, save, and a settings dialog demo.