iced-cube

Overlays

Popover

A floating panel of any content, anchored to the button that opens it.

use iced_cube::popover;
use iced_cube::overlay::popover::{Align, Side};
API reference
Settings form: A small form in a popover that closes on Escape or a click outside.Settings form: A small form in a popover that closes on Escape or a click outside.
Static preview
Settings form. A small form in a popover that closes on Escape or a click outside.

Usage

A popover holds a small piece of UI that belongs to one button, such as a settings form, a colour picker or a short explanation. It is not modal: the rest of the window stays usable, and clicking elsewhere closes it through on_dismiss while the click still reaches what it landed on. Menus, comboboxes and command lists inside a popover close first: Escape or a click outside closes the inner layer and leaves the popover open. For choosing one action from a list, use a dropdown menu instead, and for a label that appears on hover, a tooltip.

While a text field in the panel has focus, Tab and Shift+Tab move between the panel’s fields and wrap at either end, so a form in a popover works from the keyboard. Tab anywhere else is left alone.

Your app owns whether the popover is open. Toggle a flag from the trigger’s message, clear it on dismiss and pass it to .open. Clicks on the trigger are left to the trigger, so it can close the popover as well as open it.

The panel moves to the opposite side when there is no room on the one you asked for, and slides along its side to stay inside the window. A panel on the left or right that fits on neither moves below or above the trigger instead of covering it. Clicks inside it never reach the widgets underneath.

Examples

Side and alignment

A popover on each side of its trigger, aligned to the start, centre or end.

Side and alignment: A popover on each side of its trigger, aligned to the start, centre or end.Side and alignment: A popover on each side of its trigger, aligned to the start, centre or end.
Static preview

Keyboard shortcuts

Escape closes the popover, and an added binding toggles it with I.

Keyboard shortcuts: Escape closes the popover, and an added binding toggles it with I.Keyboard shortcuts: Escape closes the popover, and an added binding toggles it with I.
Static preview

API

ItemDescription
popover(trigger, content)Shows the content in a panel next to the trigger while it is open. The trigger opens it itself, usually a button that sets a flag in your state.
.open(bool)Whether the panel is showing. Defaults to false.
.on_dismiss(message)Sent on Escape and on a press outside the panel and the trigger. Without it, only your app closes the popover.
.side(Side) / .align(Align)Top, Bottom, Left or Right, and Start, Center or End. Defaults to below the trigger, centred.
.gap(f32)Space between the trigger and the panel. Defaults to 4.
.width(length) / .padding(f32)The panel is 288 wide with 16 of padding by default. Length::Shrink fits the content.
.keymap(keymap)Replaces the default keymap. The open popover closes on the chords bound to Action::Close, after its content has had the key.
style(tokens)The panel style, the floating surface shared with menus and dialogs.
popover::default_keymap()The default shortcuts as a Keymap<Action>. Bind a chord to Action::Toggle to give a popover an app-wide shortcut.
action.apply(open)Whether the popover should be open after a resolved Action (Toggle or Close), or None when nothing changes.

Keyboard

Default shortcuts. Every one can be changed or removed with a keymap; see Keyboard shortcuts.

KeysAction
EscapeClose Closes the popover.
TabFocusNext Moves from a field in the popover to its next field, wrapping at the end.
Shift+TabFocusPrevious Moves from a field in the popover to its previous field, wrapping at the start.
Esc