Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-04 17:59:29 +02:00
parent f9646208e9
commit 133c3a330c
2 changed files with 39 additions and 3 deletions
+29 -3
View File
@@ -1,7 +1,10 @@
use core::fmt::Debug;
use derive_more::{Add, AddAssign, Div, Mul, Sub, SubAssign};
use refineable::Refineable;
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Sub, SubAssign};
use std::{
cmp,
ops::{Add, AddAssign, Div, Mul, MulAssign, Sub, SubAssign},
};
#[derive(Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash)]
#[refineable(debug)]
@@ -84,7 +87,7 @@ impl<T: Clone + Debug + Div<S, Output = T>, S: Clone> Div<S> for Point<T> {
}
}
impl<T: Clone + Debug + std::cmp::PartialOrd> Point<T> {
impl<T: Clone + Debug + cmp::PartialOrd> Point<T> {
pub fn max(&self, other: &Self) -> Self {
Point {
x: if self.x >= other.x {
@@ -99,6 +102,21 @@ impl<T: Clone + Debug + std::cmp::PartialOrd> Point<T> {
},
}
}
pub fn min(&self, other: &Self) -> Self {
Point {
x: if self.x <= other.x {
self.x.clone()
} else {
other.x.clone()
},
y: if self.y <= other.y {
self.y.clone()
} else {
other.y.clone()
},
}
}
}
impl<T: Clone + Debug> Clone for Point<T> {
@@ -239,6 +257,14 @@ impl<T: Clone + Debug + Sub<Output = T>> Bounds<T> {
}
}
impl<T: Clone + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T>> Bounds<T> {
pub fn intersect(&self, other: &Self) -> Self {
let upper_left = self.origin.max(&other.origin);
let lower_right = self.lower_right().min(&other.lower_right());
Self::from_corners(upper_left, lower_right)
}
}
impl<T, Rhs> Mul<Rhs> for Bounds<T>
where
T: Mul<Rhs, Output = Rhs> + Clone + Debug,
@@ -537,7 +563,7 @@ impl Mul<Pixels> for Pixels {
impl Eq for Pixels {}
impl Ord for Pixels {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
}
}
+10
View File
@@ -86,6 +86,15 @@ impl ContentMask {
corner_radii: self.corner_radii.scale(factor),
}
}
pub fn intersect(&self, other: &Self) -> Self {
let bounds = self.bounds.intersect(&other.bounds);
// todo!("intersect corner radii")
ContentMask {
bounds,
corner_radii: self.corner_radii,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -479,6 +488,7 @@ pub trait BorrowWindow: BorrowAppContext {
fn window_mut(&mut self) -> &mut Window;
fn with_content_mask<R>(&mut self, mask: ContentMask, f: impl FnOnce(&mut Self) -> R) -> R {
let mask = mask.intersect(&self.content_mask());
self.window_mut().content_mask_stack.push(mask);
let result = f(self);
self.window_mut().content_mask_stack.pop();