From 8085e74b989da09fc8214af12778f9df516b7dfe Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 7 Sep 2021 13:02:43 -0600 Subject: [PATCH] Style the left and right sidebars independently in the theme Co-Authored-By: Max Brunsfeld --- zed/assets/themes/_base.toml | 10 +++++++++- zed/src/theme.rs | 6 ++++-- zed/src/workspace/sidebar.rs | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/zed/assets/themes/_base.toml b/zed/assets/themes/_base.toml index 115f8399d4633cfb598eb743123d35a93b3e3117..dac10bfbd9bec72451f2741ee003122cea4b77f1 100644 --- a/zed/assets/themes/_base.toml +++ b/zed/assets/themes/_base.toml @@ -19,7 +19,7 @@ extends = "$workspace.tab" background = "$surface.1" text = "$text.0" -[workspace.sidebar.icons] +[workspace.sidebar] padding = { left = 10, right = 10 } [workspace.sidebar.resize_handle] @@ -33,6 +33,14 @@ height = 18 extends = "$workspace.sidebar.icon" color = "$text.0.color" +[workspace.left_sidebar] +extends = "$workspace.sidebar" +border = { width = 1, color = "$surface.1", right = true } + +[workspace.right_sidebar] +extends = "$workspace.sidebar" +border = { width = 1, color = "$surface.1", left = true } + [chat_panel] channel_name = { extends = "$text.0", weight = "bold" } channel_name_hash = { text = "$text.2", padding.right = 5 } diff --git a/zed/src/theme.rs b/zed/src/theme.rs index c9943e2a4ba096e77872e9b68a00269308814ae5..3743120ef19e80e41ca72446c23ff866ef3a1233 100644 --- a/zed/src/theme.rs +++ b/zed/src/theme.rs @@ -36,7 +36,8 @@ pub struct Workspace { pub titlebar: ContainerStyle, pub tab: Tab, pub active_tab: Tab, - pub sidebar: Sidebar, + pub left_sidebar: Sidebar, + pub right_sidebar: Sidebar, } #[derive(Deserialize)] @@ -52,7 +53,8 @@ pub struct Tab { #[derive(Deserialize)] pub struct Sidebar { - pub icons: ContainerStyle, + #[serde(flatten)] + pub container: ContainerStyle, pub icon: SidebarIcon, pub active_icon: SidebarIcon, pub resize_handle: ContainerStyle, diff --git a/zed/src/workspace/sidebar.rs b/zed/src/workspace/sidebar.rs index e900e8c10246dcd1b56dc0a5ae3dfec15d474ff0..909d5be33b471e494b39473b5b227b2aa6251840 100644 --- a/zed/src/workspace/sidebar.rs +++ b/zed/src/workspace/sidebar.rs @@ -1,5 +1,5 @@ use super::Workspace; -use crate::Settings; +use crate::{theme, Settings}; use gpui::{ action, elements::*, platform::CursorStyle, AnyViewHandle, MutableAppContext, RenderContext, }; @@ -59,6 +59,13 @@ impl Sidebar { .map(|item| &item.view) } + fn theme<'a>(&self, settings: &'a Settings) -> &'a theme::Sidebar { + match self.side { + Side::Left => &settings.theme.workspace.left_sidebar, + Side::Right => &settings.theme.workspace.right_sidebar, + } + } + pub fn render(&self, settings: &Settings, cx: &mut RenderContext) -> ElementBox { let side = self.side; let theme = &settings.theme; @@ -66,14 +73,15 @@ impl Sidebar { theme.workspace.tab.label.text.font_id, theme.workspace.tab.label.text.font_size, ); + let theme = self.theme(settings); Container::new( Flex::column() .with_children(self.items.iter().enumerate().map(|(item_index, item)| { let theme = if Some(item_index) == self.active_item_ix { - &settings.theme.workspace.sidebar.active_icon + &theme.active_icon } else { - &settings.theme.workspace.sidebar.icon + &theme.icon }; enum SidebarButton {} MouseEventHandler::new::(item.view.id(), cx, |_, _| { @@ -98,7 +106,7 @@ impl Sidebar { })) .boxed(), ) - .with_style(&settings.theme.workspace.sidebar.icons) + .with_style(&theme.container) .boxed() } @@ -147,7 +155,7 @@ impl Sidebar { let side = self.side; MouseEventHandler::new::(self.side.id(), &mut cx, |_, _| { Container::new(Empty::new().boxed()) - .with_style(&settings.theme.workspace.sidebar.resize_handle) + .with_style(&self.theme(settings).resize_handle) .boxed() }) .with_cursor_style(CursorStyle::ResizeLeftRight)