19 个版本

0.4.0 2024 年 7 月 15 日
0.3.6 2024 年 3 月 29 日
0.3.4 2024 年 2 月 12 日
0.3.1 2023 年 12 月 1 日
0.1.7 2022 年 11 月 3 日

#87 in GUI

Download history 238/week @ 2024-05-04 161/week @ 2024-05-11 193/week @ 2024-05-18 265/week @ 2024-05-25 292/week @ 2024-06-01 246/week @ 2024-06-08 172/week @ 2024-06-15 351/week @ 2024-06-22 508/week @ 2024-06-29 219/week @ 2024-07-06 384/week @ 2024-07-13 311/week @ 2024-07-20 432/week @ 2024-07-27 208/week @ 2024-08-03 467/week @ 2024-08-10 1051/week @ 2024-08-17

2,196 个月下载量
4 个 Crates 使用

MIT 许可证

48KB
403 行代码

egui-modal,egui 的模态库 egui

crates.io docs license

modal

常规使用

/* calling every frame */

let modal = Modal::new(ctx, "my_modal");

// What goes inside the modal
modal.show(|ui| {
    // these helper functions help set the ui based on the modal's
    // set style, but they are not required and you can put whatever
    // ui you want inside [`.show()`]
    modal.title(ui, "Hello world!");
    modal.frame(ui, |ui| {
        modal.body(ui, "This is a modal.");
    });
    modal.buttons(ui, |ui| {
        // After clicking, the modal is automatically closed
        if modal.button(ui, "close").clicked() {
            println!("Hello world!")
        };
    }); 
});

if ui.button("Open the modal").clicked() {
    // Show the modal
    modal.open();
}

对话框使用

dialog

在某些用例中,可能更方便一次性地将模态作为对话框打开和样式化,例如在函数返回的单例中。

/* calling every frame */

let modal = Modal::new(ctx, "my_dialog");

...
...
...

// Show the dialog
modal.show_dialog();

其他地方,

/* happens once */
if let Ok(data) = my_function() {
    modal.dialog()
        .with_title("my_function's result is...")
        .with_body("my_function was successful!")
        .with_icon(Icon::Success)
        .open()
}

依赖项

~4.5–9.5MB
~82K SLoC