Restore a bunch of random workspace stuff

This commit is contained in:
Mikayla 2023-11-16 23:05:28 -08:00
parent e67c44a562
commit 9a3cd073c7
No known key found for this signature in database
11 changed files with 719 additions and 779 deletions

View file

@ -343,7 +343,7 @@ where
impl<T> Bounds<T>
where
T: Clone + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T> + Default,
T: Clone + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T> + Default + Half,
{
pub fn intersects(&self, other: &Bounds<T>) -> bool {
let my_lower_right = self.lower_right();
@ -362,6 +362,13 @@ where
self.size.width = self.size.width.clone() + double_amount.clone();
self.size.height = self.size.height.clone() + double_amount;
}
pub fn center(&self) -> Point<T> {
Point {
x: self.origin.x.clone() + self.size.width.clone().half(),
y: self.origin.y.clone() + self.size.height.clone().half(),
}
}
}
impl<T: Clone + Default + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T>> Bounds<T> {
@ -1211,6 +1218,46 @@ impl From<()> for Length {
}
}
pub trait Half {
fn half(&self) -> Self;
}
impl Half for f32 {
fn half(&self) -> Self {
self / 2.
}
}
impl Half for DevicePixels {
fn half(&self) -> Self {
Self(self.0 / 2)
}
}
impl Half for ScaledPixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for Pixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for Rems {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for GlobalPixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
pub trait IsZero {
fn is_zero(&self) -> bool;
}