From bc1801fb03ae8be11a8d57cc7828edcb35ba1093 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 4 Oct 2023 16:42:28 +0200 Subject: [PATCH] Checkpoint --- crates/gpui3/src/elements/img.rs | 20 ++++++++++++++++---- crates/gpui3/src/geometry.rs | 22 ++++++++++++++++------ crates/gpui3/src/style.rs | 7 +++++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 1d2a7bd1d44a363bd0e186231a1a2f33b5fe71f0..81164f1bdc17a1fd78dd3ec304826feeea6d700a 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,5 +1,6 @@ use crate::{ - Element, Layout, LayoutId, Result, SharedString, Style, StyleHelpers, Styled, ViewContext, + BorrowWindow, ContentMask, Element, IsZero, Layout, LayoutId, Result, SharedString, Style, + StyleHelpers, Styled, ViewContext, }; use futures::FutureExt; use refineable::RefinementCascade; @@ -64,14 +65,25 @@ impl Element for Img { style.paint(order, bounds, cx); - if let Some(uri) = &self.uri { - let image_future = cx.image_cache.get(uri.clone()); + if let Some(uri) = self.uri.clone() { + let image_future = cx.image_cache.get(uri); if let Some(data) = image_future .clone() .now_or_never() .and_then(ResultExt::log_err) { - cx.paint_image(bounds, order, data, self.grayscale)?; + let corner_radii = style.corner_radii.to_pixels(bounds, cx.rem_size()); + if corner_radii.is_zero() { + cx.paint_image(bounds, order, data, self.grayscale)?; + } else { + cx.with_content_mask( + ContentMask { + bounds, + corner_radii, + }, + |cx| cx.paint_image(bounds, order, data, self.grayscale), + )?; + } } else { log::warn!("image not loaded yet"); // cx.spawn(|this, mut cx| async move { diff --git a/crates/gpui3/src/geometry.rs b/crates/gpui3/src/geometry.rs index 19d1c262b1b57010e0d394130b09de01bbf4159c..c7af290e61ae039889fde14cea3a1e7ed0c9be54 100644 --- a/crates/gpui3/src/geometry.rs +++ b/crates/gpui3/src/geometry.rs @@ -433,12 +433,13 @@ pub struct Corners { } impl Corners { - pub fn to_pixels(&self, rem_size: Pixels) -> Corners { + pub fn to_pixels(&self, bounds: Bounds, rem_size: Pixels) -> Corners { + let max = bounds.size.width.max(bounds.size.height) / 2.; Corners { - top_left: self.top_left.to_pixels(rem_size), - top_right: self.top_right.to_pixels(rem_size), - bottom_right: self.bottom_right.to_pixels(rem_size), - bottom_left: self.bottom_left.to_pixels(rem_size), + top_left: self.top_left.to_pixels(rem_size).min(max), + top_right: self.top_right.to_pixels(rem_size).min(max), + bottom_right: self.bottom_right.to_pixels(rem_size).min(max), + bottom_left: self.bottom_left.to_pixels(rem_size).min(max), } } } @@ -925,6 +926,15 @@ impl IsZero for Size { impl IsZero for Bounds { fn is_zero(&self) -> bool { - self.origin.is_zero() && self.size.is_zero() + self.size.is_zero() + } +} + +impl IsZero for Corners { + fn is_zero(&self) -> bool { + self.top_left.is_zero() + && self.top_right.is_zero() + && self.bottom_right.is_zero() + && self.bottom_left.is_zero() } } diff --git a/crates/gpui3/src/style.rs b/crates/gpui3/src/style.rs index c4ce8250c0bbde2c7298698116bc912f8dc2bc9e..33da5e3602a945f8873b973ae8e1ee4a57d0e603 100644 --- a/crates/gpui3/src/style.rs +++ b/crates/gpui3/src/style.rs @@ -202,7 +202,7 @@ impl Style { let min = current_mask.bounds.origin; let max = current_mask.bounds.lower_right(); - let mask_corner_radii = Corners::default(); + let mut mask_corner_radii = Corners::default(); let mask_bounds = match ( self.overflow.x == Overflow::Visible, self.overflow.y == Overflow::Visible, @@ -220,7 +220,10 @@ impl Style { point(bounds.lower_right().x, max.y), ), // both hidden - (false, false) => bounds, + (false, false) => { + mask_corner_radii = self.corner_radii.to_pixels(bounds, cx.rem_size()); + bounds + } }; let mask = ContentMask { bounds: mask_bounds,