Fixed clipping of widgets with negative origins

Fixes #183
This commit is contained in:
Jonathan Johnson 2024-10-17 08:54:12 -07:00
parent 02e60e1049
commit 5a5f6c9229
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 17 additions and 1 deletions

View file

@ -111,6 +111,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
display scale is changed.
- `Button`'s colors are now fully reactive. The caching code to prevent color
duplicate change animations has been simplified to fix this.
- Clipping math of widgets with negative origins has been fixed to no longer
allow overdrawing the widget's bounds. This was noticable in the
nested-scroll.rs example when reducing the height of the window below 6
inches.
### Added

View file

@ -88,10 +88,22 @@ impl<'clip, 'gfx, 'pass> Graphics<'clip, 'gfx, 'pass> {
/// operations will be relative to the origin of `clip`.
pub fn clipped_to(&mut self, clip: Rect<Px>) -> Graphics<'_, 'gfx, 'pass> {
let region = clip + self.region.origin;
// If the current region has a negative component, we need to adjust the
// clipped rect before we perform an intersection in unsigned space.
let mut effective_region = region;
if region.origin.x < 0 {
effective_region.size.width += region.origin.x;
effective_region.origin.x = Px::ZERO;
}
if region.origin.y < 0 {
effective_region.size.height += region.origin.y;
effective_region.origin.y = Px::ZERO;
}
let new_clip = self
.renderer
.clip_rect()
.intersection(&region.into_unsigned())
.intersection(&effective_region.into_unsigned())
.map(|intersection| intersection - self.renderer.clip_rect().origin)
.unwrap_or_default();