Inset container contents to account for container border

Nathan Sobo created

Change summary

gpui/src/elements/container.rs |  4 +++-
gpui/src/scene.rs              | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)

Detailed changes

gpui/src/elements/container.rs 🔗

@@ -168,7 +168,9 @@ impl Element for Container {
             corner_radius: self.corner_radius,
         });
 
-        let child_origin = quad_bounds.origin() + vec2f(self.padding.left, self.padding.top);
+        let child_origin = quad_bounds.origin()
+            + vec2f(self.padding.left, self.padding.top)
+            + vec2f(self.border.left_width(), self.border.top_width());
         self.child.paint(child_origin, ctx);
     }
 

gpui/src/scene.rs 🔗

@@ -222,4 +222,20 @@ impl Border {
     fn all_sides(&self) -> bool {
         self.top && self.left && self.bottom && self.right
     }
+
+    pub fn top_width(&self) -> f32 {
+        if self.top {
+            self.width
+        } else {
+            0.0
+        }
+    }
+
+    pub fn left_width(&self) -> f32 {
+        if self.left {
+            self.width
+        } else {
+            0.0
+        }
+    }
 }