summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-12 02:53:23 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-12 02:53:23 +0200
commit03472dfd4f8a472f38f03d332b4835580eb84489 (patch)
tree4896df3378d255a7f94ff9550e1fcfad9cbb61d2 /core
parent4d849aaf0bded82b728b9470bb41203b49cc4db2 (diff)
downloadiced-03472dfd4f8a472f38f03d332b4835580eb84489.tar.gz
iced-03472dfd4f8a472f38f03d332b4835580eb84489.tar.bz2
iced-03472dfd4f8a472f38f03d332b4835580eb84489.zip
Make `Padding` affect `text_editor` clipping
Diffstat (limited to '')
-rw-r--r--core/src/rectangle.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs
index 1556e072..155cfcbf 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)]
@@ -164,12 +164,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(),
}
}