diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-26 16:32:06 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-26 16:32:06 +0100 |
| commit | 3a15922d2ffc041c3523edb479f008a9034fd400 (patch) | |
| tree | 988fe103c0752696c1fade2123142a8db5361ab7 /src/frame.rs | |
| parent | 393d74f9bb0d4c71a69108d5be261103c39f47f3 (diff) | |
X/Y abstractions
Diffstat (limited to 'src/frame.rs')
| -rw-r--r-- | src/frame.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/frame.rs b/src/frame.rs index ec10fe96..4eea0578 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -25,7 +25,7 @@ impl Frame { #[track_caller] pub fn new(size: Size) -> Self { assert!(size.is_finite()); - Self { size, baseline: size.h, elements: vec![] } + Self { size, baseline: size.y, elements: vec![] } } /// Add an element at a position in the background. @@ -58,13 +58,15 @@ impl Frame { /// Resize the frame to a new size, distributing new space according to the /// given alignments. pub fn resize(&mut self, new: Size, aligns: Spec<Align>) { - let offset = Point::new( - aligns.x.resolve(new.w - self.size.w), - aligns.y.resolve(new.h - self.size.h), - ); - self.size = new; - self.baseline += offset.y; - self.translate(offset); + if self.size != new { + let offset = Point::new( + aligns.x.resolve(new.x - self.size.x), + aligns.y.resolve(new.y - self.size.y), + ); + self.size = new; + self.baseline += offset.y; + self.translate(offset); + } } /// Move the contents of the frame by an offset. |
