diff options
author | 2024-08-12 03:07:36 +0200 | |
---|---|---|
committer | 2024-08-12 03:07:36 +0200 | |
commit | 6d6f354b425def8b4ab269cdd22cfb2328ce8591 (patch) | |
tree | b02e2f09733454b0c7917ae238824bb4b318a00e /core/src/rectangle.rs | |
parent | 1c8850023f2bdeae02ec061a49aa76dbb91262ad (diff) | |
parent | 3e59d824f8be029720f4064b49099e6aabc11179 (diff) | |
download | iced-6d6f354b425def8b4ab269cdd22cfb2328ce8591.tar.gz iced-6d6f354b425def8b4ab269cdd22cfb2328ce8591.tar.bz2 iced-6d6f354b425def8b4ab269cdd22cfb2328ce8591.zip |
Merge pull request #2536 from meithecatte/editor-clipping
text_editor: Avoid rendering text outside the border
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r-- | core/src/rectangle.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index 99c8d55d..cff33991 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -1,4 +1,4 @@ -use crate::{Point, Radians, Size, Vector}; +use crate::{Padding, Point, Radians, Size, Vector}; /// An axis-aligned rectangle. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] @@ -220,12 +220,26 @@ impl Rectangle<f32> { } /// Expands the [`Rectangle`] a given amount. - pub fn expand(self, amount: f32) -> Self { + pub fn expand(self, padding: impl Into<Padding>) -> Self { + let padding = padding.into(); + + Self { + x: self.x - padding.left, + y: self.y - padding.top, + width: self.width + padding.horizontal(), + height: self.height + padding.vertical(), + } + } + + /// Shrinks the [`Rectangle`] a given amount. + pub fn shrink(self, padding: impl Into<Padding>) -> Self { + let padding = padding.into(); + Self { - x: self.x - amount, - y: self.y - amount, - width: self.width + amount * 2.0, - height: self.height + amount * 2.0, + x: self.x + padding.left, + y: self.y + padding.top, + width: self.width - padding.horizontal(), + height: self.height - padding.vertical(), } } |