Make Padding affect text_editor clipping

This commit is contained in:
Héctor Ramón Jiménez 2024-08-12 02:53:23 +02:00
parent 4d849aaf0b
commit 03472dfd4f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 30 additions and 23 deletions

View file

@ -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 - 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(),
}
}
/// Shrinks the [`Rectangle`] a given amount.
pub fn shrink(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(),
}
}