Skip to main content

Module overlay

Module overlay 

Source
Expand description

The overlay stack: dialogs, popovers and menus above the interface.

OverlayStack is the model, pure and tested by its invariants:

  • Escape dismisses the top overlay only (if it allows it);
  • a click outside dismisses the dismissable overlays above the one clicked (or all of them), stopping at a modal: nothing below a modal receives the click;
  • closing an overlay closes every overlay opened above it;
  • each overlay remembers the widget focused when it opened; when it closes, the focus goes back there (see Focus below).

show is the egui side: it keeps the stack in the context, draws an overlay (a modal with a backdrop, or an area placed next to an anchor with crate::placement) and restores the focus. hold keeps in the stack an overlay its owner lays out and draws itself (a side area’s flyout), so it closes by the same rules.

Keys held. A modal coming up reads no key that was already down: the press in that very pass goes, and so does each repeat until the key is released. Else the key that opened it would answer it, unseen: egui clicks a focused widget on Enter or Space, the press and every repeat, and the modal’s first focus is such a widget. A modal closing does the same for what is behind it: the Enter that accepts it does not click the button the focus goes back to, which would open it again.

Focus. While a modal’s layer is on top, egui takes the focus off any widget below it as that widget is drawn, and it stays on top for the pass after the last one drawing it. So the focus goes back once the widget can hold it, a pass or two after the closing, unless something else took the focus meanwhile (the command a dialog ran). An overlay opening in that gap (the next dialog of a queue) inherits the place, and gives it back in its turn. A widget gone by then takes nothing.

egui popups. A combo box’s list, a context menu or an egui menu opened from inside an overlay is an egui area of its own, drawn while the overlay is drawn but outside its rect. Both show and hold note the layers first drawn while the overlay draws: a press on one of them is inside the overlay, not a click away, and while one is open Escape is left to it (it closes first, the overlay at the next press).

Tab. A Kind::Popover on top of the stack keeps Tab, cycling through its stops (crate::focus::keep_tab), with the focus plugin installed. A menu’s keys are its own, and an overlay held by its owner (hold, a flyout) lets the focus leave.

Windows. Each window has its own stack: an overlay belongs to the window it is shown in (a detached panel’s window, egui’s viewport), and Escape and outside clicks there close only its overlays. A modal open in one window blocks the others (block_window), and modal_open says whether one is open anywhere; stack and rects are the current window’s.

Resizable modals. A modal declared with OverlaySpec::resizable is dragged by its edges and corners, down to a least size and within the window; it keeps the size asked when the window gets too small for it, and takes it back when the window grows again. Its bottom right corner is a handle (the kit’s dialog-grip) for the keyboard too: it takes the focus, the arrows resize (with Shift, by bigger steps), and it is a splitter named “Resize” and the overlay’s label, the size its value. modal_size reads the size, modal_resizing says whether a drag is going on. Every other modal is as wide as it is declared and as high as its content, as before.

egui’s Window has such edges, but it is not a modal (no backdrop, no stack) and names nothing for assistive technology; Resize only has a corner. So the grips are here, on the modal’s own area.

use egui_pop_core::overlay::{self, Kind, OverlaySpec};

let ctx = egui::Context::default();
let spec = OverlaySpec::new("big", "Big dialog", Kind::Modal)
    .resizable(egui::vec2(500.0, 300.0), egui::vec2(200.0, 100.0));
let mut open = true;
let mut out = ctx.run_ui(Default::default(), |ui| {
    overlay::show(ui.ctx(), &spec, &mut open, None, |ui| {
        ui.label("Whatever the size, this fills it.");
    });
});
out.textures_delta.clear();
assert_eq!(overlay::modal_size(&ctx, spec.id), Some(egui::vec2(500.0, 300.0)));

Structs§

Anchor
Where a floating overlay goes.
Change
An overlay or a followed egui popup that opened or closed, in a window.
Closed
An overlay that closed, and where the focus goes.
DialogLayout
A dialog’s content laid out footer first: the footer (its buttons, a status line) always gets its whole height, at the bottom of the room, and the body takes what is left above it, scrolled when it needs more.
ModalSize
How a modal may be resized (OverlaySpec::resizable): sizes of its content, in points, as OverlaySpec::width is.
OverlaySpec
An overlay as declared.
OverlayStack
The stack, bottom first.

Enums§

Closing
How an overlay or a followed egui popup closed, as its watcher hears it (watch).
Kind
What kind of overlay.
Opened
What opening did.
Reason
Why an overlay closed.

Functions§

begin_pass
Once per pass, before anything reads the keyboard: Escape and outside clicks close overlays; overlays no longer shown are closed. Returns whether Escape was used (and consumed).
block_window
While a modal overlay is open in another window, blocks the window being drawn: its keys and typed text are dropped this pass (nothing below reads them: neither the key dispatcher nor a widget), and a backdrop over it (the theme’s backdrop, as under a dialog) takes the pointer; a click there brings the window of the modal to the front. Call it at the start of each window’s pass, before the keys are read. Returns the window holding the modal, when this one is blocked.
block_window_among
As block_window, blocked only by a modal open in a window of the same group (same says which windows are): an application window almost a separate application blocks only itself, and is blocked by none of the others.
block_window_raising
As block_window_among, a click on the backdrop asking raise to bring the window of the modal to the front (an application asks its bus’s pop.window.activate).
close
Closes an overlay (and those above it) from code.
close_anywhere
Closes an overlay, with those above it, or a followed popup, in whichever window it is open: what an application’s bus does when a popup is closed by a request (its window closing under it). The overlays above it are told closed (Closing::Below); it is not (the caller is closing it). Whether it was open.
close_in_window
As close_anywhere, in window first (an overlay may be open in several windows: the palette of each), else in whichever holds it.
closing_seen
How a popup egui closed by itself this pass closed: Escape, a press in it (an item chosen) or outside it, else its owner.
dialog_chrome
What a dialog’s frame takes around its content, both sides summed: the kit dialog’s padding (padding-x, padding-y) and the room it keeps for its widest border of any state, on whole physical pixels (Component::border_room, what Component::show keeps). A dialog’s outer size is its content’s plus this; every modal is sized with it.
follow_menu
Follows the menu egui opens from a widget (follow_popup): the popup of ui.menu_button, Response::context_menu or egui::Popup::menu(response) without an id of its own. Call it after the menu is drawn, each pass its widget is.
follow_popup
Follows an egui popup that is not in the stack (a context menu, a menu bar’s menu, a popover of egui’s, a hover card) for the watcher (watch): call it each pass its widget is drawn, open saying whether the popup is open after the widget drew it. Its opening and its closing are told once each; how says how it closed when the caller knows, else it is told from the pass’s input (Escape, a press in it or outside it). One no longer followed (its widget not drawn) is told closed (Closing::Gone) at the window’s next pass.
group_of
The group a window belongs to: itself for a separate window, the main window (ViewportId::ROOT) for every other.
hit_at
The overlay of the window being drawn that a press at pos lands in, layer being the egui layer on top there: the topmost one drawn or anchored there, or whose egui popup (a combo box’s list, a context menu) is that layer. None for the interface below the overlays.
hold
Holds an overlay its owner draws itself (a flyout laid out against the workbench rather than placed by crate::placement) in the stack, under the stack’s rules: Escape and a click outside rect and anchor close it, the focus going back where it was. Call it each pass while *open, with where the overlay is drawn this pass and draw drawing it (egui popups opened from inside are part of it); it sets *open to false and returns None, without drawing, once the overlay closed.
modal_max_size
The largest size a modal’s content can have in the window being drawn: a size above it is held back.
modal_open
Whether a modal overlay is open in the group of the window being drawn: the main window and its detached panels wait for one another’s modals (see block_window); an application’s own window waits only for its own (set_separate_windows).
modal_open_anywhere
Whether a modal overlay is open in any window.
modal_open_in
Whether a modal overlay is open in a group of windows (see group_of).
modal_resizing
Whether the person is dragging a grip of this resizable modal: a size worth keeping comes once the drag is over.
modal_size
A resizable modal’s size as asked, of its content, in points, while it is open: what it opened at or what the person last left it at (the window may hold it smaller for now). None before it is first shown.
modal_windows
The windows where a modal overlay is open, the main window first.
recently_closed
The overlays closed lately, oldest first.
rect
Where an open overlay was last drawn.
rects
The open overlays with where they were last drawn, bottom first (an overlay not drawn yet is left out).
retain_windows
Forgets the overlays of the windows other than the main one that are not in live (closed windows): what they showed is gone with them.
set_separate_windows
Says which windows are groups of their own (an application’s own windows): a modal open in one blocks it alone, and counts for modal_open there only. Replaces the earlier list.
show
Shows an overlay while *open; sets *open to false when it closes (Escape, a click outside, or close), restoring the focus. A modal is centred (moved by its offset) over a backdrop (dim); other kinds are placed next to anchor (or at the pointer).
stack
The open overlays of the window being drawn, bottom first.
stacks
Every window’s open overlays, bottom first, the main window first (windows without any left out): what the debug bridge shows of the windows.
watch
Has watcher hear every overlay of every window opening and closing, and every egui popup follow_popup follows, in the call that opened or closed it, once the stack’s lock is let go (it may close another overlay from there, close_anywhere). An application puts them on its bus this way (ADR 0029). None stops it.
window_of
The window an overlay is open in, if it is open in any.

Type Aliases§

Watcher
What hears every overlay and followed popup opening and closing.