Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper authored Oct 1, 2024
2 parents 890b28c + 9024627 commit 68cb71e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Unreleased

* (breaking) Updated to egui `0.29`.
* (breaking) Renamed functions, removed `set_` prefix to fit egui style. [#29]
* Accept either `None` or `Some(duration)` in `set_duration`. [#31]

[#29]: https://github.com/ItsEthra/egui-notify/pull/29
[#31]: https://github.com/ItsEthra/egui-notify/pull/31
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ unsafe_code = "forbid"

[lints.clippy]
all = { level = "deny", priority = 0 }
unwrap_used = { level = "deny", priority = 1 }
expect_used = { level = "deny", priority = 1 }
enum_glob_use = { level = "deny", priority = 2 }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let mut toasts = Toasts::default();

```rust
// somewhere within [egui::App::update]...
toasts.info("Hello world!").set_duration(Duration::from_secs(5));
toasts.info("Hello world!").duration(Duration::from_secs(5));
// ...
toasts.show(ctx);
```
Expand Down
8 changes: 4 additions & 4 deletions examples/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ impl App for ExampleApp {
} else {
None
};
t.set_closable(self.closable)
.set_duration(duration)
.set_show_progress_bar(self.show_progress_bar)
.set_font(FontId::proportional(self.font_size));
t.closable(self.closable)
.duration(duration)
.show_progress_bar(self.show_progress_bar)
.font(FontId::proportional(self.font_size));
};

ui.horizontal(|ui| {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SUCCESS_COLOR: Color32 = Color32::from_rgb(140, 230, 140);
///
/// # egui_notify::__run_test_ctx(|ctx| {
/// let mut t = Toasts::default();
/// t.info("Hello, World!").set_duration(Duration::from_secs(5)).set_closable(true);
/// t.info("Hello, World!").duration(Some(Duration::from_secs(5))).closable(true);
/// // More app code
/// t.show(ctx);
/// # });
Expand Down Expand Up @@ -69,6 +69,7 @@ impl Toasts {

/// Adds new toast to the collection.
/// By default adds toast at the end of the list, can be changed with `self.reverse`.
#[allow(clippy::unwrap_used)] // We know that the index is valid
pub fn add(&mut self, toast: Toast) -> &mut Toast {
if self.reverse {
self.toasts.insert(0, toast);
Expand Down
26 changes: 13 additions & 13 deletions src/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,41 +172,41 @@ impl Toast {
}

/// Set the options with a [`ToastOptions`]
pub fn set_options(&mut self, options: ToastOptions) -> &mut Self {
self.set_closable(options.closable);
self.set_duration(options.duration);
self.set_level(options.level);
pub fn options(&mut self, options: ToastOptions) -> &mut Self {
self.closable(options.closable);
self.duration(options.duration);
self.level(options.level);
self
}

/// Change the level of the toast
pub fn set_level(&mut self, level: ToastLevel) -> &mut Self {
pub fn level(&mut self, level: ToastLevel) -> &mut Self {
self.level = level;
self
}

/// Changes the font used to draw the caption, it takes precedence over the value from
/// [`Toasts`].
pub fn set_font(&mut self, font: FontId) -> &mut Self {
pub fn font(&mut self, font: FontId) -> &mut Self {
self.font = Some(font);
self
}

/// Can use close the toast?
pub fn set_closable(&mut self, closable: bool) -> &mut Self {
/// Can the user close the toast?
pub fn closable(&mut self, closable: bool) -> &mut Self {
self.closable = closable;
self
}

/// Should a progress bar be shown?
pub fn set_show_progress_bar(&mut self, show_progress_bar: bool) -> &mut Self {
pub fn show_progress_bar(&mut self, show_progress_bar: bool) -> &mut Self {
self.show_progress_bar = show_progress_bar;
self
}

/// In what time should the toast expire? Set to `None` for no expiry.
pub fn set_duration(&mut self, duration: impl Into<Option<Duration>>) -> &mut Self {
if let Some(duration) = duration.into() {
pub fn duration(&mut self, duration: Option<Duration>) -> &mut Self {
if let Some(duration) = duration {
let max_dur = duration_to_seconds_f32(duration);
self.duration = Some((max_dur, max_dur));
} else {
Expand All @@ -216,13 +216,13 @@ impl Toast {
}

/// Toast's box height
pub fn set_height(&mut self, height: f32) -> &mut Self {
pub fn height(&mut self, height: f32) -> &mut Self {
self.height = height;
self
}

/// Toast's box width
pub fn set_width(&mut self, width: f32) -> &mut Self {
pub fn width(&mut self, width: f32) -> &mut Self {
self.width = width;
self
}
Expand Down

0 comments on commit 68cb71e

Please sign in to comment.