Skip to content

Commit

Permalink
update README, examples, semver
Browse files Browse the repository at this point in the history
  • Loading branch information
n00kii committed Sep 21, 2022
1 parent df6fb6e commit 4d5f90e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui-modal"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
license = "MIT"
description = "a modal library for egui"
Expand Down
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# egui-modal, a modal library for [`egui`](https://github.com/emilk/egui)
[![crates.io](https://img.shields.io/crates/v/egui-modal)](https://crates.io/crates/egui-modal/0.1.1)
[![docs](https://docs.rs/egui-modal/badge.svg)](https://docs.rs/egui-modal/0.1.1/egui_modal/)
[![crates.io](https://img.shields.io/crates/v/egui-modal)](https://crates.io/crates/egui-modal/0.1.3)
[![docs](https://docs.rs/egui-modal/badge.svg)](https://docs.rs/egui-modal/0.1.3/egui_modal/)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/n00kii/egui-modal/blob/main/README.md)

![modal](https://raw.githubusercontent.com/n00kii/egui-modal/main/media/modal.png?token=GHSAT0AAAAAABVWXBGJBQSFC3PLQP4KKOG6YZJIDCA)

## usage:
## normal usage:
```rust
/* 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, "My modal");
modal.body(ui, "This is a modal");
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("A button").clicked() {
Expand All @@ -25,4 +32,29 @@ if ui.button("Open the modal").clicked() {
// Show the modal
modal.open();
}
```
## dialog usage
in some use cases, it may be more convenient to both open and style the modal as a dialog as a one-time action, like on the single instance of a function's return.
```rust
/* calling every frame */

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

...
...
...

// Show the dialog
dialog.show_dialog();
```
elsewhere,
```rust
/* happens once */
if let Ok(data) = my_function() {
dialog.open_dialog(
Some("my_function's result is..."), // title
Some("my_function was successful!"), // body
Some(Icon::Success) // icon
)
}
```
11 changes: 8 additions & 3 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl eframe::App for ExampleApp {
.with_close_on_outside_click(self.close_on_outside_click || !self.include_buttons);

// the show function defines what is shown in the modal, but the modal
// won't actually show until you do modal.open(ctx)
// won't actually show until you do modal.open()
modal.show(|ui| {
// these helper functions are NOT mandatory to use, they just
// help implement some styling with margins and separators
Expand All @@ -63,7 +63,7 @@ impl eframe::App for ExampleApp {
if modal.button(ui, "close").clicked() {
// all buttons created with the helper functions automatically
// close the modal on click, but you can close it yourself with
// ['modal.close(ctx)']
// ['modal.close()']
println!("hello world!")
}

Expand All @@ -78,7 +78,9 @@ impl eframe::App for ExampleApp {
}
});

// a dialog is useful when you have a one-time occurance and you want to relay information to the user
let mut dialog_modal = Modal::new(ctx, "dialog_modal").with_style(&self.modal_style);
// make sure you don't forget to show the dialog!
dialog_modal.show_dialog();

ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| {
Expand All @@ -87,6 +89,7 @@ impl eframe::App for ExampleApp {
}

if ui.button("open dialog").clicked() {
// [`.open_dialog()`] both sets the visual info for the dialog and opens it at the same time
dialog_modal.open_dialog(
Some("this is a dialog"),
Some("this helps for showing information about one-time events"),
Expand Down Expand Up @@ -223,7 +226,9 @@ impl eframe::App for ExampleApp {
// the modal's [`.show()`] anywhere but we could have put this above
// modal if we wanted
nested_modal.show(|ui| {
nested_modal.body(ui, "hello there!");
nested_modal.frame(ui, |ui| {
nested_modal.body(ui, "hello there!");
});
nested_modal.buttons(ui, |ui| {
nested_modal.button(ui, "close");
})
Expand Down
2 changes: 1 addition & 1 deletion src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Modal {

/// Helper function that should be used when using a body and icon together.
pub fn body_and_icon(&self, ui: &mut Ui, text: impl Into<RichText>, icon: Icon) {
egui::Grid::new("id_source").num_columns(2).show(ui, |ui| {
egui::Grid::new(self.id).num_columns(2).show(ui, |ui| {
self.icon(ui, icon);
self.body(ui, text);
});
Expand Down

0 comments on commit 4d5f90e

Please sign in to comment.