From 133c3a330c0c706b87d26dde860b785e27391334 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 4 Oct 2023 17:59:29 +0200 Subject: [PATCH] Checkpoint --- crates/gpui3/src/geometry.rs | 32 +++++++++++++++++++++++++++++--- crates/gpui3/src/window.rs | 10 ++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/gpui3/src/geometry.rs b/crates/gpui3/src/geometry.rs index c7af290e61ae039889fde14cea3a1e7ed0c9be54..d60866816d6e3513929f530d2ae9bd50eb97966a 100644 --- a/crates/gpui3/src/geometry.rs +++ b/crates/gpui3/src/geometry.rs @@ -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, S: Clone> Div for Point { } } -impl Point { +impl Point { pub fn max(&self, other: &Self) -> Self { Point { x: if self.x >= other.x { @@ -99,6 +102,21 @@ impl Point { }, } } + + 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 Clone for Point { @@ -239,6 +257,14 @@ impl> Bounds { } } +impl + Sub> Bounds { + 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 Mul for Bounds where T: Mul + Clone + Debug, @@ -537,7 +563,7 @@ impl Mul 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() } } diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index 12bc21d9f0e4eeed271d4b6a0f2082ea4efaba2d..b92edb8ecefee09c1a89934b0ad45eef7b615dcb 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -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(&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();