Flatten theme styles by eliminating top-level ui key

Nathan Sobo , Max Brunsfeld , and Antonio Scandurra created

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>

Change summary

zed/assets/themes/_base.toml | 16 ++++++++--------
zed/src/file_finder.rs       |  8 ++++----
zed/src/theme.rs             | 13 ++++++-------
zed/src/theme_selector.rs    |  6 +++---
zed/src/workspace.rs         |  2 +-
zed/src/workspace/pane.rs    |  4 ++--
6 files changed, 24 insertions(+), 25 deletions(-)

Detailed changes

zed/assets/themes/_base.toml 🔗

@@ -1,7 +1,7 @@
-[ui]
+[workspace]
 background = "$surface.0"
 
-[ui.tab]
+[tab]
 background = "$surface.1"
 text = "$text_color.dull"
 border = { color = "#000000", width = 1.0 }
@@ -10,12 +10,12 @@ icon_close = "#383839"
 icon_dirty = "#556de8"
 icon_conflict = "#e45349"
 
-[ui.active_tab]
-extends = "$ui.tab"
+[active_tab]
+extends = "$tab"
 background = "$surface.2"
 text = "$text_color.bright"
 
-[ui.selector]
+[selector]
 background = "$surface.3"
 text = "$text_color.bright"
 padding = { top = 6.0, bottom = 6.0, left = 6.0, right = 6.0 }
@@ -23,15 +23,15 @@ margin.top = 12.0
 corner_radius = 6.0
 shadow = { offset = [0.0, 0.0], blur = 12.0, color = "#00000088" }
 
-[ui.selector.item]
+[selector.item]
 background = "#424344"
 text = "#cccccc"
 highlight_text = { color = "#18a3ff", weight = "bold" }
 border = { color = "#000000", width = 1.0 }
 padding = { top = 6.0, bottom = 6.0, left = 6.0, right = 6.0 }
 
-[ui.selector.active_item]
-extends = "$ui.selector.item"
+[selector.active_item]
+extends = "$selector.item"
 background = "#094771"
 
 [editor]

zed/src/file_finder.rs 🔗

@@ -75,7 +75,7 @@ impl View for FileFinder {
                         .with_child(Expanded::new(1.0, self.render_matches()).boxed())
                         .boxed(),
                 )
-                .with_style(&settings.theme.ui.selector.container)
+                .with_style(&settings.theme.selector.container)
                 .boxed(),
             )
             .with_max_width(600.0)
@@ -107,7 +107,7 @@ impl FileFinder {
                     settings.ui_font_family,
                     settings.ui_font_size,
                 )
-                .with_style(&settings.theme.ui.selector.label)
+                .with_style(&settings.theme.selector.label)
                 .boxed(),
             )
             .with_margin_top(6.0)
@@ -142,9 +142,9 @@ impl FileFinder {
         let selected_index = self.selected_index();
         let settings = self.settings.borrow();
         let style = if index == selected_index {
-            &settings.theme.ui.selector.active_item
+            &settings.theme.selector.active_item
         } else {
-            &settings.theme.ui.selector.item
+            &settings.theme.selector.item
         };
         let (file_name, file_name_positions, full_path, full_path_positions) =
             self.labels_for_match(path_match);

zed/src/theme.rs 🔗

@@ -30,18 +30,18 @@ pub struct HighlightId(u32);
 pub struct Theme {
     #[serde(default)]
     pub name: String,
-    pub ui: Ui,
+    pub workspace: Workspace,
+    pub tab: Tab,
+    pub active_tab: Tab,
+    pub selector: Selector,
     pub editor: Editor,
     #[serde(deserialize_with = "deserialize_syntax_theme")]
     pub syntax: Vec<(String, TextStyle)>,
 }
 
 #[derive(Debug, Default, Deserialize)]
-pub struct Ui {
+pub struct Workspace {
     pub background: Color,
-    pub tab: Tab,
-    pub active_tab: Tab,
-    pub selector: Selector,
 }
 
 #[derive(Debug, Deserialize)]
@@ -800,8 +800,6 @@ mod tests {
     fn test_highlight_map() {
         let theme = Theme {
             name: "test".into(),
-            ui: Default::default(),
-            editor: Default::default(),
             syntax: [
                 ("function", Color::from_u32(0x100000ff)),
                 ("function.method", Color::from_u32(0x200000ff)),
@@ -813,6 +811,7 @@ mod tests {
             .iter()
             .map(|(name, color)| (name.to_string(), (*color).into()))
             .collect(),
+            ..Default::default()
         };
 
         let capture_names = &[

zed/src/theme_selector.rs 🔗

@@ -207,7 +207,7 @@ impl ThemeSelector {
                     settings.ui_font_family,
                     settings.ui_font_size,
                 )
-                .with_style(&settings.theme.ui.selector.label)
+                .with_style(&settings.theme.selector.label)
                 .boxed(),
             )
             .with_margin_top(6.0)
@@ -240,7 +240,7 @@ impl ThemeSelector {
 
     fn render_match(&self, theme_match: &StringMatch, index: usize) -> ElementBox {
         let settings = self.settings.borrow();
-        let theme = &settings.theme.ui;
+        let theme = &settings.theme;
 
         let container = Container::new(
             Label::new(
@@ -286,7 +286,7 @@ impl View for ThemeSelector {
                         .with_child(Expanded::new(1.0, self.render_matches(cx)).boxed())
                         .boxed(),
                 )
-                .with_style(&settings.theme.ui.selector.container)
+                .with_style(&settings.theme.selector.container)
                 .boxed(),
             )
             .with_max_width(600.0)

zed/src/workspace.rs 🔗

@@ -885,7 +885,7 @@ impl View for Workspace {
                 .with_children(self.modal.as_ref().map(|m| ChildView::new(m.id()).boxed()))
                 .boxed(),
         )
-        .with_background_color(settings.theme.ui.background)
+        .with_background_color(settings.theme.workspace.background)
         .named("workspace")
     }
 

zed/src/workspace/pane.rs 🔗

@@ -181,7 +181,7 @@ impl Pane {
 
     fn render_tabs(&self, cx: &AppContext) -> ElementBox {
         let settings = self.settings.borrow();
-        let theme = &settings.theme.ui;
+        let theme = &settings.theme;
         let line_height = cx.font_cache().line_height(
             cx.font_cache().default_font(settings.ui_font_family),
             settings.ui_font_size,
@@ -304,7 +304,7 @@ impl Pane {
         tab_hovered: bool,
         is_dirty: bool,
         has_conflict: bool,
-        theme: &theme::Ui,
+        theme: &theme::Theme,
         cx: &AppContext,
     ) -> ElementBox {
         enum TabCloseButton {}