Module modal_dialog
Expand description
The one modal: a sheet over a scrim that covers the whole window.
ModalDialog is the retained widget: a title, any content widget, and
up to three footer actions. It is always presented in the window’s top
layer (Widget::draw_overlay), after the app and the window’s own
chrome (the History bar, sidebars), so its scrim covers all of them
wherever in the tree the dialog is mounted. Escape or a click on the scrim
dismisses; Enter fires the default action unless the content consumes it.
The default is the primary action, except in a destructive confirmation,
where it is the safe answer (Cancel), as on macOS.
Content taller than the window allows scrolls inside the body.
A painted host that asks a question without a retained tree uses
ModalSheet: it paints the sheet, keeps its layout for hit-testing and
turns input into a SheetResponse. Hosts that need only the chrome
(the identity ceremonies, shell sheets) use layout,
paint_backdrop and paint_actions:
let layout = modal_dialog::layout(window, &spec, text_renderer, theme);
modal_dialog::paint_backdrop(scene, transform, text_renderer, theme, &layout, &spec);
// ... caller draws its own content inside `layout.body` ...
modal_dialog::paint_actions(scene, transform, text_renderer, theme, &layout, &spec);On a roomy viewport the sheet is a floating Panel (super::floating_surface):
panel radius, the blurred material, one soft shadow. On a compact viewport
it is an opaque full-window page with no floating edge. A floating sheet
follows its content height;
its title is a Title; its actions are Regular buttons anchored to the
footer in the platform’s order. Dialog callbacks are host-supplied
closures and do not flow through the document.
Structs§
- Dialog
Action - One footer action of a
ModalDialog. The dialog runs it from its own events, and the action’s focus node runs it when it is operated through the accessibility tree, so both hold the callback. - Modal
Action - One button in the footer.
- Modal
Dialog - A modal dialog: a title, any content widget, and up to three footer
actions, over a scrim that covers the window. Generic over the content
type so callers pass any
Widgetwithout boxing. - Modal
Layout - Where every part of the modal landed. Pure geometry, computed without a GPU, so the layout rules are tested directly.
- Modal
Sheet - The immediate-mode sheet for a painted host that keeps its own state (a
question with three answers, a confirmation over a canvas): it lays the
sheet out, paints it with hover, press and keyboard focus on its
actions, keeps the layout of its last paint for hit-testing, and turns
input into a
SheetResponse. The host paints only its body. - Modal
Spec - What a modal is being asked to frame.
Enums§
- Modal
Emphasis - How an action is weighted in the footer.
- Modal
Hit - What a point landed on.
- Sheet
Response - What an immediate
ModalSheetwas answered with.
Constants§
- MODAL_
MAX_ WIDTH - Widest a modal sheet is drawn, in design pixels (grown with the text scale). Past this a single column of text stops being one column.
- MODAL_
MIN_ WIDTH - Narrowest a modal sheet is drawn, in design pixels, before it elides.
Functions§
- action_
height - Height of one footer action: a Regular control.
- body_
width - Width the caller’s body is laid into: the sheet minus its padding.
Equal to
layout(..).body.width()for the same inputs. - card_
width - Width of the sheet for
max_width(design pixels) insidewindow, knowable before any body row is measured. Widths grow with the text scale, because what fills a sheet is text. A floating sheet keeps the content gutter clear of every window edge; a compact page fills the window and keeps that gutter inside its body. - ink
- Ink that is legible on the sheet, as
(primary, dim): the theme’s own when it clears AA against the panel ground, else the contrast-guaranteed on-content ramp. - layout
- Compute the geometry for
specinsidewindow. - paint_
actions - Paint the footer actions. Call after drawing the body.
- paint_
backdrop - Paint the scrim, the sheet, the title and the close control. Call before drawing the body.
- uses_
full_ window - A small viewport presents a modal as a page instead of a floating card. The sheet-width role grows with the theme’s UI and text scale; checking both axes also keeps phone landscape and short viewports usable.