diff --git a/crates/data/src/sidebar.rs b/crates/data/src/sidebar.rs index 8e79b92..f0d0814 100644 --- a/crates/data/src/sidebar.rs +++ b/crates/data/src/sidebar.rs @@ -371,7 +371,13 @@ impl RenderOnce for Sidebar { .w(width) .flex() .flex_col() - .when(material, |sidebar| sidebar.bg(theme.material.background)) + .map(|sidebar| { + if material { + sidebar.bg(theme.material.background) + } else { + sidebar.bg(theme.colors.sidebar) + } + }) .text_size(theme.sizes.medium.text_size) .when(border_right, |sidebar| { sidebar diff --git a/crates/theme/src/colors.rs b/crates/theme/src/colors.rs index 14a9174..e7caafb 100644 --- a/crates/theme/src/colors.rs +++ b/crates/theme/src/colors.rs @@ -21,6 +21,8 @@ pub struct ColorTokens { pub foreground: Hsla, pub surface: Hsla, pub surface_foreground: Hsla, + /// The docked sidebar's backdrop, matching the platform's window chrome. + pub sidebar: Hsla, pub primary: Hsla, pub primary_foreground: Hsla, pub secondary: Hsla, @@ -56,6 +58,7 @@ impl ColorTokens { foreground: hex(0x18181b), surface: hex(0xfafafa), surface_foreground: hex(0x18181b), + sidebar: hex(0xf4f4f5), primary: hex(0x2563eb), primary_foreground: hex(0xffffff), secondary: hex(0xf4f4f5), @@ -90,6 +93,7 @@ impl ColorTokens { foreground: hex(0xfafafa), surface: hex(0x18181b), surface_foreground: hex(0xfafafa), + sidebar: hex(0x18181b), primary: hex(0x3b82f6), primary_foreground: hex(0xffffff), secondary: hex(0x27272a), diff --git a/crates/theme/src/definition.rs b/crates/theme/src/definition.rs index 82c50c7..8da096b 100644 --- a/crates/theme/src/definition.rs +++ b/crates/theme/src/definition.rs @@ -19,6 +19,7 @@ pub struct ThemeDefinition { foreground: Option, surface: Option, surface_foreground: Option, + sidebar: Option, primary: Option, primary_foreground: Option, secondary: Option, @@ -87,6 +88,10 @@ impl ThemeDefinition { self.color(&self.surface_foreground, "surface_foreground") } + pub fn sidebar(&self) -> Option { + self.color(&self.sidebar, "sidebar") + } + pub fn primary(&self) -> Option { self.color(&self.primary, "primary") } diff --git a/crates/theme/src/resolve.rs b/crates/theme/src/resolve.rs index 841a35c..b93d8ae 100644 --- a/crates/theme/src/resolve.rs +++ b/crates/theme/src/resolve.rs @@ -117,6 +117,11 @@ pub(crate) fn resolve( system_palette.surface_foreground, base.surface_foreground, ), + sidebar: pick( + def_color(|d| d.sidebar()), + system_palette.sidebar, + base.sidebar, + ), primary, primary_foreground: pick( def_color(|d| d.primary_foreground()), diff --git a/crates/theme/src/source/macos.rs b/crates/theme/src/source/macos.rs index dcdf9b8..937a7da 100644 --- a/crates/theme/src/source/macos.rs +++ b/crates/theme/src/source/macos.rs @@ -86,6 +86,7 @@ impl MacosSource { foreground: Self::color_to_hsla(&NSColor::labelColor()), surface: Self::color_to_hsla(&NSColor::textBackgroundColor()), surface_foreground: Self::color_to_hsla(&NSColor::labelColor()), + sidebar: Self::color_to_hsla(&NSColor::windowBackgroundColor()), primary_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()), accent_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()), secondary: None, diff --git a/crates/theme/src/system.rs b/crates/theme/src/system.rs index 0cf4a4e..77eb9d4 100644 --- a/crates/theme/src/system.rs +++ b/crates/theme/src/system.rs @@ -63,6 +63,8 @@ pub struct PartialPalette { pub foreground: Option, pub surface: Option, pub surface_foreground: Option, + /// Only macOS states it, the window backdrop its sidebars show. + pub sidebar: Option, pub primary_foreground: Option, pub accent_foreground: Option, pub secondary: Option, diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index f4a89d2..3e343f2 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -4199,6 +4199,8 @@ impl Render for SidebarDemo { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { let view = cx.entity(); let view_slots = view.clone(); + let view_opaque = view.clone(); + let view_options = view.clone(); let theme = cx.theme(); let colors = theme.colors; let radius = theme.radius; @@ -4210,16 +4212,16 @@ impl Render for SidebarDemo { "standalone; the app's own left sidebar is this component", colors, div() - .w(rems(15.)) + .w(px(240.)) .h(rems(22.5)) .rounded(radius.control) .border_1() .border_color(colors.border) + .bg(colors.surface) .overflow_hidden() .child( Sidebar::new("sidebar-demo-list") .selected(self.selected) - .transparent(true) .on_change(move |selected, _, cx| { view.update(cx, |demo, cx| { demo.selected = selected; @@ -4260,11 +4262,12 @@ impl Render for SidebarDemo { "custom entries slot user content around the rows", colors, div() - .w(rems(15.)) + .w(px(240.)) .h(rems(22.5)) .rounded(radius.control) .border_1() .border_color(colors.border) + .bg(colors.surface) .overflow_hidden() .child( Sidebar::new("sidebar-demo-slots") @@ -4304,31 +4307,68 @@ impl Render for SidebarDemo { ), )) .child(demo_section( - "a custom entry fills the list; the right border is off", + "opaque sidebars paint the platform's sidebar tone", colors, div() - .w(rems(15.)) + .w(px(240.)) .h(rems(13.)) .rounded(radius.control) .border_1() .border_color(colors.border) + .bg(colors.surface) .overflow_hidden() .child( - Sidebar::new("sidebar-demo-custom") - .transparent(true) + Sidebar::new("sidebar-demo-opaque") + .selected(self.selected) + .on_change(move |selected, _, cx| { + view_opaque.update(cx, |demo, cx| { + demo.selected = selected; + cx.notify(); + }); + }) + .entries(|_, _| { + vec![ + SidebarEntry::header("Favorites"), + SidebarEntry::row("Documents", "Documents"), + SidebarEntry::row("Pictures", "Pictures").detail("24"), + SidebarEntry::row("Archive", "Archive").disabled(true), + SidebarEntry::header("Locations"), + SidebarEntry::row("Trash", "Trash"), + ] + }), + ), + )) + .child(demo_section( + "width, padding, and the right border are local options", + colors, + div() + .w(px(192.)) + .h(rems(13.)) + .rounded(radius.control) + .border_1() + .border_color(colors.border) + .bg(colors.surface) + .overflow_hidden() + .child( + Sidebar::new("sidebar-demo-options") + .selected(self.selected) + .width(px(192.)) + .padded(false) .border_right(false) - .entries(move |_, _| { - vec![SidebarEntry::custom( - div() - .w_full() - .px_2() - .py_6() - .flex() - .items_center() - .justify_center() - .text_color(colors.muted_foreground) - .child("Nothing here yet"), - )] + .on_change(move |selected, _, cx| { + view_options.update(cx, |demo, cx| { + demo.selected = selected; + cx.notify(); + }); + }) + .entries(|_, _| { + vec![ + SidebarEntry::header("Favorites"), + SidebarEntry::row("Documents", "Documents"), + SidebarEntry::row("Pictures", "Pictures").detail("24"), + SidebarEntry::header("Locations"), + SidebarEntry::row("Trash", "Trash"), + ] }), ), ))