Skip to content

Commit

Permalink
fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
bircni committed Aug 3, 2024
1 parent 714c99a commit bf09e83
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ egui-phosphor = { git = "https://github.com/ItsEthra/egui-phosphor", branch = "m
unsafe_code = "forbid"

[lints.clippy]
nursery = { level = "deny", priority = 0 }
pedantic = { level = "deny", priority = 1 }
all = { level = "deny", priority = 0 }
enum_glob_use = { level = "deny", priority = 2 }
module_name_repetitions = { level = "allow", priority = 3 }
cast_precision_loss = { level = "allow", priority = 4 }
6 changes: 3 additions & 3 deletions src/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Anchor {

impl Anchor {
#[inline]
pub(crate) const fn anim_side(self) -> f32 {
pub(crate) const fn anim_side(&self) -> f32 {
match self {
Self::TopRight | Self::BottomRight => 1.,
Self::TopLeft | Self::BottomLeft => -1.,
Expand All @@ -24,7 +24,7 @@ impl Anchor {
}

impl Anchor {
pub(crate) fn screen_corner(self, sc: Pos2, margin: Vec2) -> Pos2 {
pub(crate) fn screen_corner(&self, sc: Pos2, margin: Vec2) -> Pos2 {
let mut out = match self {
Self::TopRight => pos2(sc.x, 0.),
Self::TopLeft => pos2(0., 0.),
Expand All @@ -35,7 +35,7 @@ impl Anchor {
out
}

pub(crate) fn apply_margin(self, pos: &mut Pos2, margin: Vec2) {
pub(crate) fn apply_margin(&self, pos: &mut Pos2, margin: Vec2) {
match self {
Self::TopRight => {
pos.x -= margin.x;
Expand Down
16 changes: 1 addition & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ impl Toasts {
/// # Panics
///
/// Will panic if after adding a toast the list is empty.
#[must_use]
pub fn add(&mut self, toast: Toast) -> &mut Toast {
if self.reverse {
self.toasts.insert(0, toast);
return self.toasts.get_mut(0).unwrap();
}
self.toasts.push(toast);
let l = self.toasts.len() - 1;
return self.toasts.get_mut(l).unwrap();
self.toasts.get_mut(l).unwrap()
}

/// Dismisses the oldest toast
Expand All @@ -102,37 +101,31 @@ impl Toasts {
}

/// Shortcut for adding a toast with info `success`.
#[must_use]
pub fn success(&mut self, caption: impl Into<String>) -> &mut Toast {
self.add(Toast::success(caption))
}

/// Shortcut for adding a toast with info `level`.
#[must_use]
pub fn info(&mut self, caption: impl Into<String>) -> &mut Toast {
self.add(Toast::info(caption))
}

/// Shortcut for adding a toast with warning `level`.
#[must_use]
pub fn warning(&mut self, caption: impl Into<String>) -> &mut Toast {
self.add(Toast::warning(caption))
}

/// Shortcut for adding a toast with error `level`.
#[must_use]
pub fn error(&mut self, caption: impl Into<String>) -> &mut Toast {
self.add(Toast::error(caption))
}

/// Shortcut for adding a toast with no level.
#[must_use]
pub fn basic(&mut self, caption: impl Into<String>) -> &mut Toast {
self.add(Toast::basic(caption))
}

/// Shortcut for adding a toast with custom `level`.
#[must_use]
pub fn custom(
&mut self,
caption: impl Into<String>,
Expand All @@ -146,50 +139,43 @@ impl Toasts {
}

/// Should toasts be added in reverse order?
#[must_use]
pub const fn reverse(mut self, reverse: bool) -> Self {
self.reverse = reverse;
self
}

/// Where toasts should appear.
#[must_use]
pub const fn with_anchor(mut self, anchor: Anchor) -> Self {
self.anchor = anchor;
self
}

/// Sets spacing between adjacent toasts.
#[must_use]
pub const fn with_spacing(mut self, spacing: f32) -> Self {
self.spacing = spacing;
self
}

/// Margin or distance from screen to toasts' bounding boxes
#[must_use]
pub const fn with_margin(mut self, margin: Vec2) -> Self {
self.margin = margin;
self
}

/// Padding or distance from toasts' bounding boxes to inner contents.
#[must_use]
pub const fn with_padding(mut self, padding: Vec2) -> Self {
self.padding = padding;
self
}

/// Changes the default font used for all toasts.
#[must_use]
pub fn with_default_font(mut self, font: FontId) -> Self {
self.font = Some(font);
self
}
}

impl Toasts {
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
/// Displays toast queue
pub fn show(&mut self, ctx: &Context) {
let Self {
Expand Down
6 changes: 1 addition & 5 deletions src/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,21 @@ pub enum ToastState {

impl ToastState {
/// Returns `true` if the toast is appearing
#[must_use]
pub const fn appearing(&self) -> bool {
matches!(self, Self::Appear)
}

/// Returns `true` if the toast is disappearing
#[must_use]
pub const fn disappearing(&self) -> bool {
matches!(self, Self::Disappear)
}

/// Returns `true` if the toast has disappeared
#[must_use]
pub const fn disappeared(&self) -> bool {
matches!(self, Self::Disappeared)
}

/// Returns `true` if the toast is idling
#[must_use]
pub const fn idling(&self) -> bool {
matches!(self, Self::Idle)
}
Expand Down Expand Up @@ -175,7 +171,7 @@ impl Toast {
)
}

/// Set the options with a `ToastOptions`
/// 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);
Expand Down

0 comments on commit bf09e83

Please sign in to comment.