From 177306d494e75292ef2169b66d0c4a4f390fe542 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 30 Sep 2021 13:29:26 -0700 Subject: [PATCH] Add 'overlay' property to border For containers, this causes the border to be drawn on top of the child element. Co-Authored-By: Nathan Sobo --- gpui/src/elements/container.rs | 54 +++++++++++++++++++++++++--------- gpui/src/scene.rs | 6 ++++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/gpui/src/elements/container.rs b/gpui/src/elements/container.rs index 02d4cece951781115ca3820fe258bbfc05e4e747..026542989e45e25cdaad0acc8a01086cdbf966b2 100644 --- a/gpui/src/elements/container.rs +++ b/gpui/src/elements/container.rs @@ -167,7 +167,10 @@ impl Element for Container { constraint: SizeConstraint, cx: &mut LayoutContext, ) -> (Vector2F, Self::LayoutState) { - let size_buffer = self.margin_size() + self.padding_size() + self.border_size(); + let mut size_buffer = self.margin_size() + self.padding_size(); + if !self.style.border.overlay { + size_buffer += self.border_size(); + } let child_constraint = SizeConstraint { min: (constraint.min - size_buffer).max(Vector2F::zero()), max: (constraint.max - size_buffer).max(Vector2F::zero()), @@ -196,20 +199,43 @@ impl Element for Container { color: shadow.color, }); } - cx.scene.push_quad(Quad { - bounds: quad_bounds, - background: self.style.background_color, - border: self.style.border, - corner_radius: self.style.corner_radius, - }); - let child_origin = quad_bounds.origin() - + vec2f(self.style.padding.left, self.style.padding.top) - + vec2f( - self.style.border.left_width(), - self.style.border.top_width(), - ); - self.child.paint(child_origin, visible_bounds, cx); + let child_origin = + quad_bounds.origin() + vec2f(self.style.padding.left, self.style.padding.top); + + if self.style.border.overlay { + cx.scene.push_quad(Quad { + bounds: quad_bounds, + background: self.style.background_color, + border: Default::default(), + corner_radius: self.style.corner_radius, + }); + + self.child.paint(child_origin, visible_bounds, cx); + + cx.scene.push_layer(None); + cx.scene.push_quad(Quad { + bounds: quad_bounds, + background: Default::default(), + border: self.style.border, + corner_radius: self.style.corner_radius, + }); + cx.scene.pop_layer(); + } else { + cx.scene.push_quad(Quad { + bounds: quad_bounds, + background: self.style.background_color, + border: self.style.border, + corner_radius: self.style.corner_radius, + }); + + let child_origin = child_origin + + vec2f( + self.style.border.left_width(), + self.style.border.top_width(), + ); + self.child.paint(child_origin, visible_bounds, cx); + } } fn dispatch_event( diff --git a/gpui/src/scene.rs b/gpui/src/scene.rs index 1b9c863647205a09fcafde18c2abdda1aa36e922..b833ffe627d07be3ef255eef9072f4a704d56825 100644 --- a/gpui/src/scene.rs +++ b/gpui/src/scene.rs @@ -69,6 +69,7 @@ pub struct Icon { pub struct Border { pub width: f32, pub color: Color, + pub overlay: bool, pub top: bool, pub right: bool, pub bottom: bool, @@ -85,6 +86,8 @@ impl<'de> Deserialize<'de> for Border { pub width: f32, pub color: Color, #[serde(default)] + pub overlay: bool, + #[serde(default)] pub top: bool, #[serde(default)] pub right: bool, @@ -98,6 +101,7 @@ impl<'de> Deserialize<'de> for Border { let mut border = Border { width: data.width, color: data.color, + overlay: data.overlay, top: data.top, bottom: data.bottom, left: data.left, @@ -329,6 +333,7 @@ impl Border { Self { width, color, + overlay: false, top: false, left: false, bottom: false, @@ -340,6 +345,7 @@ impl Border { Self { width, color, + overlay: false, top: true, left: true, bottom: true,