Render a titlebar you can barely see

Nathan Sobo and Mikayla Maki created

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>

Change summary

crates/gpui/playground/src/playground.rs | 14 ++++++++++++--
crates/gpui/playground/src/style.rs      | 21 +++++++++++++++++++--
crates/gpui/src/app/window.rs            |  4 ++++
crates/gpui/src/geometry.rs              |  6 ++++++
4 files changed, 41 insertions(+), 4 deletions(-)

Detailed changes

crates/gpui/playground/src/playground.rs 🔗

@@ -4,8 +4,9 @@ use crate::{
 };
 use element::Element;
 use gpui::{
-    geometry::{rect::RectF, vector::vec2f},
+    geometry::{pixels, rect::RectF, vector::vec2f},
     platform::WindowOptions,
+    ViewContext,
 };
 use log::LevelFilter;
 use simplelog::SimpleLogger;
@@ -40,7 +41,7 @@ fn main() {
                 center: true,
                 ..Default::default()
             },
-            |_| view(|_| playground(&rose_pine::moon())),
+            |_| view(|cx| workspace(&rose_pine::moon(), cx)),
         );
         cx.platform().activate(true);
     });
@@ -58,3 +59,12 @@ fn playground<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
         .child(div().fill(p.pine).child(div().fill(p.love).w_6().h_3()))
         .child(div().fill(p.gold).child(div().fill(p.iris).w_3().h_3()))
 }
+
+fn workspace<V: 'static>(theme: &ThemeColors, cx: &mut ViewContext<V>) -> impl Element<V> {
+    use div::div;
+    // one line change1!
+    div()
+        .full()
+        .fill(theme.base(0.5))
+        .child(div().h(pixels(cx.titlebar_height())).fill(theme.base(0.)))
+}

crates/gpui/playground/src/style.rs 🔗

@@ -11,8 +11,8 @@ pub use gpui::taffy::style::{
 use gpui::{
     fonts::TextStyleRefinement,
     geometry::{
-        rect::RectF, AbsoluteLength, DefiniteLength, Edges, EdgesRefinement, Length, Point,
-        PointRefinement, Size, SizeRefinement,
+        rect::RectF, relative, AbsoluteLength, DefiniteLength, Edges, EdgesRefinement, Length,
+        Point, PointRefinement, Size, SizeRefinement,
     },
     taffy,
 };
@@ -286,6 +286,23 @@ pub trait Styleable {
 pub trait StyleHelpers: Styleable<Style = Style> {
     styleable_helpers!();
 
+    fn h(mut self, height: Length) -> Self
+    where
+        Self: Sized,
+    {
+        self.declared_style().size.height = Some(height);
+        self
+    }
+
+    fn full(mut self) -> Self
+    where
+        Self: Sized,
+    {
+        self.declared_style().size.width = Some(relative(1.));
+        self.declared_style().size.height = Some(relative(1.));
+        self
+    }
+
     fn relative(mut self) -> Self
     where
         Self: Sized,

crates/gpui/src/app/window.rs 🔗

@@ -1190,6 +1190,10 @@ impl<'a> WindowContext<'a> {
         self.window.platform_window.bounds()
     }
 
+    pub fn titlebar_height(&self) -> f32 {
+        self.window.titlebar_height
+    }
+
     pub fn window_appearance(&self) -> Appearance {
         self.window.appearance
     }

crates/gpui/src/geometry.rs 🔗

@@ -387,3 +387,9 @@ impl Default for Length {
         Self::Definite(DefiniteLength::default())
     }
 }
+
+impl From<()> for Length {
+    fn from(_: ()) -> Self {
+        Self::Definite(DefiniteLength::default())
+    }
+}