dialog

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dialog ships the modal Dialog view: a Window dressed in the gray dialog palette, with helpers for laying out a row of buttons along the bottom edge.

A Dialog is just a Window with FlagClose|FlagMove (no zoom, no grow) and the frame swapped to the dialog palette slots. Insert child widgets the same way you would with a Window. Phase 3 wires Enter and Esc shortcuts; the modal sub-loop arrives with Application.ExecView.

Index

Constants

View Source
const (
	MbOK          = KindInformation | BtnOK
	MbOKCancel    = KindConfirmation | BtnOK | BtnCancel
	MbYesNo       = KindConfirmation | BtnYes | BtnNo
	MbYesNoCancel = KindConfirmation | BtnYes | BtnNo | BtnCancel
)

Stock button combinations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialog

type Dialog struct {
	*window.Window
	// contains filtered or unexported fields
}

Dialog is a modal Window themed for forms and prompts. Embed *window.Window so all the framing, drag, and event-dispatch logic is inherited; Dialog only customizes palette slots and adds a button placement helper.

func MessageBox

func MessageBox(text string, flags Flags) *Dialog

MessageBox returns a Dialog that displays text with the title and buttons selected by flags. The dialog is not yet inserted anywhere; pass it to Application.ExecView (or similar) to show it modally.

Lines in text are split on '\n'. Long lines are clipped at mbMaxW; the helper does not word-wrap. The first present button in (OK, Yes, No, Cancel) becomes the default; Cancel (or No when no Cancel exists) becomes the cancel button.

func New

func New(bounds vio.Rect, title string) *Dialog

New returns a Dialog sized to bounds. The frame uses dialog slots (15 inactive, 16 active), the body fills with dialog text color, and FlagClose|FlagMove are enabled so the user can drag and dismiss.

func (*Dialog) CancelButton

func (d *Dialog) CancelButton() *widget.Button

CancelButton returns the button registered via SetCancelButton, or nil.

func (*Dialog) DefaultButton

func (d *Dialog) DefaultButton() *widget.Button

DefaultButton returns the button registered via SetDefaultButton, or nil.

func (*Dialog) EndModal

func (d *Dialog) EndModal(cmd event.CommandID)

EndModal records cmd as the dialog's close result. Hosts call this when they want to dismiss the dialog programmatically; the modal sub-loop exits on the next iteration.

func (*Dialog) HandleEvent

func (d *Dialog) HandleEvent(e *event.Event)

HandleEvent intercepts dialog-level shortcuts before falling back to the Window dispatch. Enter fires the registered default button; Esc fires the registered cancel button. A disabled button is skipped so the rest of the dispatch chain still gets the keystroke. Command events that close the dialog (CmdOk, CmdCancel, CmdYes, CmdNo, CmdClose) are also captured here and stashed as the close result.

func (*Dialog) PlaceButtons

func (d *Dialog) PlaceButtons(buttons ...*widget.Button)

PlaceButtons inserts the given buttons in a centered row along the bottom of the client rectangle. Buttons keep the size set by the caller; PlaceButtons only repositions them. Useful for the common OK/Cancel cluster a host doesn't want to lay out by hand.

func (*Dialog) Reset

func (d *Dialog) Reset()

Reset clears the close result so the same Dialog instance can be shown a second time.

func (*Dialog) Result

func (d *Dialog) Result() event.CommandID

Result returns the command that closed the dialog, or 0 if the dialog has not been closed yet. ExecView reads this to decide when the modal sub-loop should exit.

func (*Dialog) SetCancelButton

func (d *Dialog) SetCancelButton(b *widget.Button)

SetCancelButton remembers b as the dialog's cancel action so pressing Esc anywhere in the dialog fires it. Pass nil to clear.

func (*Dialog) SetDefaultButton

func (d *Dialog) SetDefaultButton(b *widget.Button)

SetDefaultButton remembers b as the dialog's default action so pressing Enter anywhere in the dialog fires it. Pass nil to clear.

type Flags

type Flags uint16

Flags selects the title and the buttons of a MessageBox. Combine one kind bit with one or more button bits, or pass a stock combo such as MbOK or MbYesNo.

const (
	KindInformation Flags = 1 << iota
	KindWarning
	KindError
	KindConfirmation
)

Kind bits.

const (
	BtnOK Flags = 1 << (iota + 8)
	BtnCancel
	BtnYes
	BtnNo
)

Button bits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL