Skip to content

Commit

Permalink
Added opacity function to DrawableExt
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Dec 13, 2023
1 parent 90d2035 commit 73a5936
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,8 @@ pub trait DrawableExt<Source, Unit> {
fn rotate_by(self, angle: Angle) -> Drawable<Source, Unit>;
/// Scales `self` by `factor`.
fn scale(self, factor: f32) -> Drawable<Source, Unit>;
/// Renders this drawable with `opacity`, ranged from 0.- to 1.0.
fn opacity(self, opacity: f32) -> Drawable<Source, Unit>;
}

impl<T, Unit> DrawableExt<T, Unit> for Drawable<T, Unit> {
Expand All @@ -1954,6 +1956,11 @@ impl<T, Unit> DrawableExt<T, Unit> for Drawable<T, Unit> {
self.scale = Some(factor);
self
}

fn opacity(mut self, opacity: f32) -> Drawable<T, Unit> {
self.opacity = Some(opacity.clamp(0., 1.));
self
}
}

impl<T, Unit> DrawableExt<T, Unit> for T
Expand All @@ -1972,4 +1979,8 @@ where
fn scale(self, factor: f32) -> Drawable<T, Unit> {
Drawable::from(self).scale(factor)
}

fn opacity(self, opacity: f32) -> Drawable<T, Unit> {
Drawable::from(self).opacity(opacity)
}
}

0 comments on commit 73a5936

Please sign in to comment.