diff options
author | 2025-01-26 14:26:07 +0100 | |
---|---|---|
committer | 2025-01-26 14:26:07 +0100 | |
commit | 8e23592c5c97df2ccbee5d52c48698fdb78ae6db (patch) | |
tree | d7fb16cac96707cf499b2915e9fbe562e5a166ee /core/src | |
parent | d034bd73d8fb176ef9edfc76a6198711354a97f1 (diff) | |
parent | e90ff41edbf00c77be3762586a8ca93be1b17d59 (diff) | |
download | iced-8e23592c5c97df2ccbee5d52c48698fdb78ae6db.tar.gz iced-8e23592c5c97df2ccbee5d52c48698fdb78ae6db.tar.bz2 iced-8e23592c5c97df2ccbee5d52c48698fdb78ae6db.zip |
Merge pull request #2751 from iced-rs/feature/pop-widget
`pop` widget
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/rectangle.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index cff33991..14d2a2e8 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -143,6 +143,20 @@ impl Rectangle<f32> { && point.y < self.y + self.height } + /// Returns the minimum distance from the given [`Point`] to any of the edges + /// of the [`Rectangle`]. + pub fn distance(&self, point: Point) -> f32 { + let center = self.center(); + + let distance_x = + ((point.x - center.x).abs() - self.width / 2.0).max(0.0); + + let distance_y = + ((point.y - center.y).abs() - self.height / 2.0).max(0.0); + + distance_x.hypot(distance_y) + } + /// Returns true if the current [`Rectangle`] is completely within the given /// `container`. pub fn is_within(&self, container: &Rectangle) -> bool { |