sidebar: fall back to theme sidebar color when opaque
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -19,6 +19,7 @@ pub struct ThemeDefinition {
|
||||
foreground: Option<String>,
|
||||
surface: Option<String>,
|
||||
surface_foreground: Option<String>,
|
||||
sidebar: Option<String>,
|
||||
primary: Option<String>,
|
||||
primary_foreground: Option<String>,
|
||||
secondary: Option<String>,
|
||||
@@ -87,6 +88,10 @@ impl ThemeDefinition {
|
||||
self.color(&self.surface_foreground, "surface_foreground")
|
||||
}
|
||||
|
||||
pub fn sidebar(&self) -> Option<Hsla> {
|
||||
self.color(&self.sidebar, "sidebar")
|
||||
}
|
||||
|
||||
pub fn primary(&self) -> Option<Hsla> {
|
||||
self.color(&self.primary, "primary")
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -63,6 +63,8 @@ pub struct PartialPalette {
|
||||
pub foreground: Option<Hsla>,
|
||||
pub surface: Option<Hsla>,
|
||||
pub surface_foreground: Option<Hsla>,
|
||||
/// Only macOS states it, the window backdrop its sidebars show.
|
||||
pub sidebar: Option<Hsla>,
|
||||
pub primary_foreground: Option<Hsla>,
|
||||
pub accent_foreground: Option<Hsla>,
|
||||
pub secondary: Option<Hsla>,
|
||||
|
||||
@@ -4199,6 +4199,8 @@ impl Render for SidebarDemo {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> 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"),
|
||||
]
|
||||
}),
|
||||
),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user