Popover
A popover below trigger, toggled by clicking it. side and align place it elsewhere around the trigger.
ui.popoverBasic
let more = ui.button("Open popover").outline().response();ui.popover(&more).children(|ui| { ui.text("Popover").font_bold(); ui.text("Click outside the panel or press Esc to close.").text_sm().muted();});Alignment
// Apart, so that where each panel sits under its button shows.ui.row().gap(56).children(|ui| { for (name, align) in [ ("Start", Align::Start), ("Center", Align::Center), ("End", Align::End), ] { let button = ui.button(name).outline().response(); ui.popover(&button).align(align).w(200).children(|ui| { ui.text(format_args!("Aligned to the {}", name.to_lowercase())).text_sm(); }); }});Side
ui.row().gap(8).children(|ui| { for (name, side) in [ ("Left", Side::Left), ("Bottom", Side::Bottom), ("Right", Side::Right), ] { let button = ui.button(name).outline().response(); ui.popover(&button).side(side).children(|ui| { ui.text(format_args!("On the {}", name.to_lowercase())).text_sm(); }); }});With a form
let size = ui.button("Dimensions").outline().response();ui.popover(&size).w(280).children(|ui| { // The heading and what it is about, close together. ui.column().gap(2).children(|ui| { ui.text("Dimensions").font_medium(); ui.text("Set the size of the layer.").text_sm().muted(); }); // Labels beside their inputs, in one column. ui.form().children(|ui| { ui.field("Width").children(|ui| { ui.text_input(&mut self.width).w_fill(); }); ui.field("Height").children(|ui| { ui.text_input(&mut self.height).w_fill(); }); }); ui.row().w_fill().gap(8).justify_end().children(|ui| { let cancel = ui.button("Cancel").outline().clicked(); let apply = ui.button("Apply").primary().clicked(); if cancel || apply { ui.close_popover(); } });});API reference
| Setting | Description |
|---|---|
.side(side: Side) | The side of the trigger to appear on, below it by default. Without room there, it appears on the opposite side. |
.align(align: Align) | Where along that side: Align::Start lines it up with the start of the trigger, the default, Align::Center centers it on the trigger and Align::End lines up the ends. |
.w(width: impl Into<Sizing>) | The width; a plain length is a fixed width. By default it is as wide as its content, so set one for content that fills the width, such as a form. |
.children(f: impl FnOnce(&mut Ui<'a>) | Declares the content with f while open. |