From d5e713698a1819ce1b37392df885c7dc51ca5682 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 2 Aug 2024 22:46:57 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 37f28a2..3f3c2da 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # egui-notify + Simple notifications library for [`egui`](https://github.com/emilk/egui) ![example_image](media/toasts_type.png) ![example_video](media/toasts_example_video.gif) + # Usage + ```rust use egui_notify::Toasts; use std::time::Duration; @@ -12,6 +15,7 @@ use std::time::Duration; // initialize once let mut toasts = Toasts::default(); ``` + ```rust // somewhere within [egui::App::update]... toasts.info("Hello world!").set_duration(Duration::from_secs(5)); @@ -20,16 +24,19 @@ toasts.show(ctx); ``` # Installation + ```toml [dependencies] egui-notify = "0.15.0" ``` # Difference to [`egui-toast`](https://github.com/urholaukkarinen/egui-toast) -### `egui-notify` has - - Animations for appearing/disappearing toasts - - Duration meter for expiring toasts - - Toast positioning not influenced by which `Context` you pass to it (like if for example, you passed in a `Context` already altered for an `egui::Window`) - - Differing methodology (create `Toasts` instance once, save save somewhere in application state) - - Threadsafe `Toasts` instance, implements `Send`, `Sync`. - - No support for custom toasts + +### `egui-notify` has + +- Animations for appearing/disappearing toasts +- Duration meter for expiring toasts +- Toast positioning not influenced by which `Context` you pass to it (like if for example, you passed in a `Context` already altered for an `egui::Window`) +- Differing methodology (create `Toasts` instance once, save save somewhere in application state) +- Threadsafe `Toasts` instance, implements `Send`, `Sync`. +- No support for custom toasts From 182b212fa76a2ba1d5e8f7ce0e305a0a910404b4 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 2 Aug 2024 22:47:17 +0200 Subject: [PATCH 2/3] Implement hold on hover #24 --- src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7537ec0..11e574f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -212,9 +212,16 @@ impl Toasts { let mut update = false; for (i, toast) in toasts.iter_mut().enumerate() { - // Decrease duration if idling + let anim_offset = toast.width * (1. - ease_in_cubic(toast.value)); + pos.x += anim_offset * anchor.anim_side(); + let rect = toast.calc_anchored_rect(pos, *anchor); + if let Some((_, d)) = toast.duration.as_mut() { - if toast.state.idling() { + // Check if we hover over the toast and if true don't decrease the duration + let hover_pos = ctx.input(|i| i.pointer.hover_pos()); + let is_outside_rect = hover_pos.map_or(true, |pos| !rect.contains(pos)); + + if is_outside_rect && toast.state.idling() { *d -= ctx.input(|i| i.stable_dt); update = true; } @@ -310,10 +317,6 @@ impl Toasts { toast.width = icon_width_padded + caption_width + cross_width_padded + (padding.x * 2.); toast.height = action_height.max(caption_height).max(cross_height) + padding.y * 2.; - let anim_offset = toast.width * (1. - ease_in_cubic(toast.value)); - pos.x += anim_offset * anchor.anim_side(); - let rect = toast.calc_anchored_rect(pos, *anchor); - // Required due to positioning of the next toast pos.x -= anim_offset * anchor.anim_side(); From 344b9b03f14a7f4fb5bbf8c630a6eb3290452cea Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 2 Aug 2024 22:48:23 +0200 Subject: [PATCH 3/3] Fix README --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f3c2da..cc70573 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Simple notifications library for [`egui`](https://github.com/emilk/egui) ![example_video](media/toasts_example_video.gif) -# Usage +## Usage ```rust use egui_notify::Toasts; @@ -23,14 +23,18 @@ toasts.info("Hello world!").set_duration(Duration::from_secs(5)); toasts.show(ctx); ``` -# Installation +## Installation + +```sh +cargo add egui-notify +``` ```toml [dependencies] egui-notify = "0.15.0" ``` -# Difference to [`egui-toast`](https://github.com/urholaukkarinen/egui-toast) +## Difference to [`egui-toast`](https://github.com/urholaukkarinen/egui-toast) ### `egui-notify` has