Skip to main content

Module modal_dialog

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§

DialogAction
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.
ModalAction
One button in the footer.
ModalDialog
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 Widget without boxing.
ModalLayout
Where every part of the modal landed. Pure geometry, computed without a GPU, so the layout rules are tested directly.
ModalSheet
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.
ModalSpec
What a modal is being asked to frame.

Enums§

ModalEmphasis
How an action is weighted in the footer.
ModalHit
What a point landed on.
SheetResponse
What an immediate ModalSheet was 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) inside window, 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 spec inside window for a person with a pointing device.
layout_for
Compute the geometry for spec inside window for a person reaching it through environment: 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 from layout.card while 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_h of body, the title above it, the footer below it and a grip grip tall 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 (place runs its apply_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.