Introduce useful helpers in layout module

This commit is contained in:
Héctor Ramón Jiménez 2024-01-09 06:35:33 +01:00
parent d24e50c1a6
commit d62bb8193c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
26 changed files with 189 additions and 127 deletions

View file

@ -89,19 +89,23 @@ impl Node {
}
/// Moves the [`Node`] to the given position.
pub fn move_to(mut self, position: Point) -> Self {
pub fn move_to(mut self, position: impl Into<Point>) -> Self {
self.move_to_mut(position);
self
}
/// Mutable reference version of [`move_to`].
pub fn move_to_mut(&mut self, position: Point) {
pub fn move_to_mut(&mut self, position: impl Into<Point>) {
let position = position.into();
self.bounds.x = position.x;
self.bounds.y = position.y;
}
/// Translates the [`Node`] by the given translation.
pub fn translate(self, translation: Vector) -> Self {
pub fn translate(self, translation: impl Into<Vector>) -> Self {
let translation = translation.into();
Self {
bounds: self.bounds + translation,
..self