Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique toast and show inside Ui supports #19

Closed
wants to merge 0 commits into from

Conversation

varphone
Copy link

New features:

  • Add an optional id to Toast, could be use a unique id to update an exists toast.
  • Add show_inside() to Toasts, could be limit the display rect to Ui.
  • Add some builder pattern api and setters to Toast and Toasts.

@ItsEthra
Copy link
Owner

Could describe some use cases for a show_inside function?

@varphone
Copy link
Author

Could describe some use cases for a show_inside function?

For example: show and clip the notify in a window or panel.

@ItsEthra
Copy link
Owner

ItsEthra commented Oct 24, 2023

image
It seems like there is a small margin on the x axis that probably shouldn't be there.

EDIT: or it actually could be that top margin is missing for some reason.

src/toast.rs Outdated
@@ -61,6 +94,7 @@ pub struct Toast {

pub(crate) state: ToastState,
pub(crate) value: f32,
pub(crate) id: Option<String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's great idea to use String as Id type as it requires allocation. It's probably better to use egui::Id that already uses a hash function.

src/lib.rs Outdated
if let Some(ref id) = toast.id {
if let Some(i) = self.toasts.iter().position(|t| t.id.as_ref() == Some(id)) {
let exist = self.toasts.get_mut(i).unwrap();
exist.level = toast.level;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why assign fields individually instead of just assigning the whole struct? Like *exist = toast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants