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, always presented in the window’s top layer
(Widget::draw_overlay) after the app and the window’s chrome, so its scrim
covers all of them. Escape or a click on the scrim dismisses; Enter fires the
default action unless the content consumes it (the primary action, except in a
destructive confirmation, which takes the safe answer, as on macOS). Content
taller than the window scrolls inside the body.
A painted host that asks a question without a retained tree uses ModalSheet,
which 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);
on a compact one an opaque full-window page. Dismissal (ModalDialog::on_dismiss)
is the dialog’s close control, published as a view action so agents and scripts
close the dialog as a person does.
Structs§
- Dialog
Action - One footer action of a
ModalDialog: the dialog runs it from its own events, the action’s focus node when operated through the accessibility tree. - 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 that layout 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, since what fills a sheet is text. - 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
specinsidewindowfor a person with a pointing device. - layout_
for - Compute the geometry for
specinsidewindowfor a person reaching it throughenvironment: on a coarse pointer the sheet’s own controls take a finger’s target. - 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.
- paint_
scrim - Paint the scrim behind a floating sheet drawn in
drawn_card, which differs fromlayout.cardwhile it arrives or leaves; a full-window page has none. - paint_
sheet - Paint the sheet, its title and its close control, without the scrim.
- rise_
from_ foot - Raise
layout, a compact window’s full-window page, as a sheet from the window’s foot that is as tall as what it holds:content_hof body, the title above it, the footer below it and a gripgriptall along its top. A form of a few fields asks from the foot, where the thumb is; one too tall for most of the window stays the whole page. Whether it rose. - title_
icon_ rect - Where a title icon is drawn: before the title, centred on its first row.
- uses_
full_ window - A small viewport presents a modal as a page instead of a floating card, so phone landscape and short viewports stay usable.
- within_
window - Place a window’s content (
placeruns itsapply_layout) knowing which window it is: a host laying several windows out in one tree (the desktop’s strip) calls this so a dialog centres on its own window rather than the shared tree’s root.