侧边面板
侧边面板:靠着窗口一边的模态面板,默认在右边,在对话框 key 打开时显示。适合放对话框装不下的内容,比如设置或详情。
ui.sheet基本用法
if ui.button("Open sheet").outline().clicked() { ui.open_dialog("profile");}let sheet = ui.sheet("profile").title("Edit profile");let sheet = sheet.description("Changes are saved when you press Save.");sheet.children(|ui| { ui.field("Name").children(|ui| { ui.text_input(&mut self.full_name).placeholder("Jane Doe"); }); ui.field("Username").children(|ui| { ui.text_input(&mut self.username); }); // The buttons go to the bottom of the sheet. ui.spacer(); ui.row().w_fill().gap(8).justify_end().children(|ui| { let cancel = ui.button("Cancel").outline().clicked(); let save = ui.button("Save").primary().clicked(); if cancel || save { ui.close_dialog("profile"); } });});弹出的方向
ui.row().gap(8).children(|ui| { for (name, side) in [ ("Left", Side::Left), ("Right", Side::Right), ("Top", Side::Top), ("Bottom", Side::Bottom), ] { if ui.button(name).outline().clicked() { ui.open_dialog(("sheet", name)); } let sheet = ui.sheet(("sheet", name)).title(name).side(side).size(240); sheet.children(|ui| { ui.text("Press Esc or click outside to close.").muted(); }); }});接口
| 设置 | 说明 |
|---|---|
.title(title: impl Display) | 标题,同时也是辅助技术读到的面板名称。 |
.description(text: impl Display) | 标题下方的文字。 |
.side(side: Side) | 面板贴着窗口的哪一边,并从那一边滑入,默认是右边。 |
.size(size: impl crate::style::Length) | 面板伸进窗口多深:在左右两边时是宽度,默认 384;在上下两边时是高度,默认 320。窗口总会留出一部分不被盖住。 |
.children(f: impl FnOnce(&mut Ui<'a>) | 打开时用 f 声明内容。 |