Refine project panel styling

Antonio Scandurra created

Change summary

gpui/src/elements/container.rs |  5 +++++
zed/assets/themes/_base.toml   | 13 ++++++++++---
zed/src/project_panel.rs       | 14 +++++++++++---
zed/src/theme.rs               |  4 +++-
zed/src/worktree.rs            |  9 +++++----
5 files changed, 34 insertions(+), 11 deletions(-)

Detailed changes

gpui/src/elements/container.rs 🔗

@@ -84,6 +84,11 @@ impl Container {
         self
     }
 
+    pub fn with_padding_left(mut self, padding: f32) -> Self {
+        self.style.padding.left = padding;
+        self
+    }
+
     pub fn with_padding_right(mut self, padding: f32) -> Self {
         self.style.padding.right = padding;
         self

zed/assets/themes/_base.toml 🔗

@@ -161,9 +161,16 @@ corner_radius = 6
 
 [project_panel]
 extends = "$panel"
-entry = "$text.0"
-padding.left = "$panel.padding"
-padding.right = "$panel.padding"
+padding = 0
+entry_base_padding = "$panel.padding"
+
+[project_panel.entry]
+extends = "$text.0"
+padding = { top = 3, bottom = 3 }
+
+[project_panel.hovered_entry]
+extends = "$project_panel.entry"
+background = "$state.hover"
 
 [selector]
 background = "$surface.0"

zed/src/project_panel.rs 🔗

@@ -2,6 +2,7 @@ use crate::{project::Project, theme, Settings};
 use gpui::{
     action,
     elements::{Label, MouseEventHandler, UniformList, UniformListState},
+    platform::CursorStyle,
     Element, ElementBox, Entity, ModelHandle, MutableAppContext, ReadModel, View, ViewContext,
     WeakViewHandle,
 };
@@ -165,10 +166,16 @@ impl ProjectPanel {
         MouseEventHandler::new::<Self, _, _, _>(
             (entry.worktree_ix, entry.entry_id),
             cx,
-            |state, cx| {
-                Label::new(details.filename, theme.entry.clone())
+            |state, _| {
+                let style = if state.hovered {
+                    &theme.hovered_entry
+                } else {
+                    &theme.entry
+                };
+                Label::new(details.filename, style.text.clone())
                     .contained()
-                    .with_margin_left(details.depth as f32 * 20.)
+                    .with_style(style.container)
+                    .with_padding_left(theme.entry_base_padding + details.depth as f32 * 20.)
                     .boxed()
             },
         )
@@ -179,6 +186,7 @@ impl ProjectPanel {
                 cx.dispatch_action(Open(entry))
             }
         })
+        .with_cursor_style(CursorStyle::PointingHand)
         .boxed()
     }
 }

zed/src/theme.rs 🔗

@@ -111,7 +111,9 @@ pub struct ChatPanel {
 pub struct ProjectPanel {
     #[serde(flatten)]
     pub container: ContainerStyle,
-    pub entry: TextStyle,
+    pub entry_base_padding: f32,
+    pub entry: ContainedText,
+    pub hovered_entry: ContainedText,
 }
 
 #[derive(Deserialize)]

zed/src/worktree.rs 🔗

@@ -1592,7 +1592,6 @@ impl Snapshot {
     }
 
     fn insert_entry(&mut self, mut entry: Entry, fs: &dyn Fs) -> Entry {
-        println!("insert entry {:?}", entry.path);
         if !entry.is_dir() && entry.path.file_name() == Some(&GITIGNORE) {
             let abs_path = self.abs_path.join(&entry.path);
             match build_gitignore(&abs_path, fs) {
@@ -1665,10 +1664,8 @@ impl Snapshot {
 
     fn reuse_entry_id(&mut self, entry: &mut Entry) {
         if let Some(removed_entry_id) = self.removed_entry_ids.remove(&entry.inode) {
-            log::info!("reusing removed entry id {}", removed_entry_id);
             entry.id = removed_entry_id;
         } else if let Some(existing_entry) = self.entry_for_path(&entry.path) {
-            log::info!("reusing removed entry id {}", existing_entry.id);
             entry.id = existing_entry.id;
         }
     }
@@ -2234,7 +2231,11 @@ impl BackgroundScanner {
                         new_ignore = Some(ignore);
                     }
                     Err(error) => {
-                        log::error!("error loading .gitignore file {:?} - {:?}", child_name, error);
+                        log::error!(
+                            "error loading .gitignore file {:?} - {:?}",
+                            child_name,
+                            error
+                        );
                     }
                 }