sidebar: fall back to theme sidebar color when opaque
This commit is contained in:
@@ -371,7 +371,13 @@ impl RenderOnce for Sidebar {
|
|||||||
.w(width)
|
.w(width)
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.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)
|
.text_size(theme.sizes.medium.text_size)
|
||||||
.when(border_right, |sidebar| {
|
.when(border_right, |sidebar| {
|
||||||
sidebar
|
sidebar
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ pub struct ColorTokens {
|
|||||||
pub foreground: Hsla,
|
pub foreground: Hsla,
|
||||||
pub surface: Hsla,
|
pub surface: Hsla,
|
||||||
pub surface_foreground: Hsla,
|
pub surface_foreground: Hsla,
|
||||||
|
/// The docked sidebar's backdrop, matching the platform's window chrome.
|
||||||
|
pub sidebar: Hsla,
|
||||||
pub primary: Hsla,
|
pub primary: Hsla,
|
||||||
pub primary_foreground: Hsla,
|
pub primary_foreground: Hsla,
|
||||||
pub secondary: Hsla,
|
pub secondary: Hsla,
|
||||||
@@ -56,6 +58,7 @@ impl ColorTokens {
|
|||||||
foreground: hex(0x18181b),
|
foreground: hex(0x18181b),
|
||||||
surface: hex(0xfafafa),
|
surface: hex(0xfafafa),
|
||||||
surface_foreground: hex(0x18181b),
|
surface_foreground: hex(0x18181b),
|
||||||
|
sidebar: hex(0xf4f4f5),
|
||||||
primary: hex(0x2563eb),
|
primary: hex(0x2563eb),
|
||||||
primary_foreground: hex(0xffffff),
|
primary_foreground: hex(0xffffff),
|
||||||
secondary: hex(0xf4f4f5),
|
secondary: hex(0xf4f4f5),
|
||||||
@@ -90,6 +93,7 @@ impl ColorTokens {
|
|||||||
foreground: hex(0xfafafa),
|
foreground: hex(0xfafafa),
|
||||||
surface: hex(0x18181b),
|
surface: hex(0x18181b),
|
||||||
surface_foreground: hex(0xfafafa),
|
surface_foreground: hex(0xfafafa),
|
||||||
|
sidebar: hex(0x18181b),
|
||||||
primary: hex(0x3b82f6),
|
primary: hex(0x3b82f6),
|
||||||
primary_foreground: hex(0xffffff),
|
primary_foreground: hex(0xffffff),
|
||||||
secondary: hex(0x27272a),
|
secondary: hex(0x27272a),
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ pub struct ThemeDefinition {
|
|||||||
foreground: Option<String>,
|
foreground: Option<String>,
|
||||||
surface: Option<String>,
|
surface: Option<String>,
|
||||||
surface_foreground: Option<String>,
|
surface_foreground: Option<String>,
|
||||||
|
sidebar: Option<String>,
|
||||||
primary: Option<String>,
|
primary: Option<String>,
|
||||||
primary_foreground: Option<String>,
|
primary_foreground: Option<String>,
|
||||||
secondary: Option<String>,
|
secondary: Option<String>,
|
||||||
@@ -87,6 +88,10 @@ impl ThemeDefinition {
|
|||||||
self.color(&self.surface_foreground, "surface_foreground")
|
self.color(&self.surface_foreground, "surface_foreground")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sidebar(&self) -> Option<Hsla> {
|
||||||
|
self.color(&self.sidebar, "sidebar")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn primary(&self) -> Option<Hsla> {
|
pub fn primary(&self) -> Option<Hsla> {
|
||||||
self.color(&self.primary, "primary")
|
self.color(&self.primary, "primary")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ pub(crate) fn resolve(
|
|||||||
system_palette.surface_foreground,
|
system_palette.surface_foreground,
|
||||||
base.surface_foreground,
|
base.surface_foreground,
|
||||||
),
|
),
|
||||||
|
sidebar: pick(
|
||||||
|
def_color(|d| d.sidebar()),
|
||||||
|
system_palette.sidebar,
|
||||||
|
base.sidebar,
|
||||||
|
),
|
||||||
primary,
|
primary,
|
||||||
primary_foreground: pick(
|
primary_foreground: pick(
|
||||||
def_color(|d| d.primary_foreground()),
|
def_color(|d| d.primary_foreground()),
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ impl MacosSource {
|
|||||||
foreground: Self::color_to_hsla(&NSColor::labelColor()),
|
foreground: Self::color_to_hsla(&NSColor::labelColor()),
|
||||||
surface: Self::color_to_hsla(&NSColor::textBackgroundColor()),
|
surface: Self::color_to_hsla(&NSColor::textBackgroundColor()),
|
||||||
surface_foreground: Self::color_to_hsla(&NSColor::labelColor()),
|
surface_foreground: Self::color_to_hsla(&NSColor::labelColor()),
|
||||||
|
sidebar: Self::color_to_hsla(&NSColor::windowBackgroundColor()),
|
||||||
primary_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()),
|
primary_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()),
|
||||||
accent_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()),
|
accent_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()),
|
||||||
secondary: None,
|
secondary: None,
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ pub struct PartialPalette {
|
|||||||
pub foreground: Option<Hsla>,
|
pub foreground: Option<Hsla>,
|
||||||
pub surface: Option<Hsla>,
|
pub surface: Option<Hsla>,
|
||||||
pub surface_foreground: 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 primary_foreground: Option<Hsla>,
|
||||||
pub accent_foreground: Option<Hsla>,
|
pub accent_foreground: Option<Hsla>,
|
||||||
pub secondary: 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 {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let view = cx.entity();
|
let view = cx.entity();
|
||||||
let view_slots = view.clone();
|
let view_slots = view.clone();
|
||||||
|
let view_opaque = view.clone();
|
||||||
|
let view_options = view.clone();
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
let colors = theme.colors;
|
let colors = theme.colors;
|
||||||
let radius = theme.radius;
|
let radius = theme.radius;
|
||||||
@@ -4210,16 +4212,16 @@ impl Render for SidebarDemo {
|
|||||||
"standalone; the app's own left sidebar is this component",
|
"standalone; the app's own left sidebar is this component",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(15.))
|
.w(px(240.))
|
||||||
.h(rems(22.5))
|
.h(rems(22.5))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(colors.border)
|
.border_color(colors.border)
|
||||||
|
.bg(colors.surface)
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.child(
|
.child(
|
||||||
Sidebar::new("sidebar-demo-list")
|
Sidebar::new("sidebar-demo-list")
|
||||||
.selected(self.selected)
|
.selected(self.selected)
|
||||||
.transparent(true)
|
|
||||||
.on_change(move |selected, _, cx| {
|
.on_change(move |selected, _, cx| {
|
||||||
view.update(cx, |demo, cx| {
|
view.update(cx, |demo, cx| {
|
||||||
demo.selected = selected;
|
demo.selected = selected;
|
||||||
@@ -4260,11 +4262,12 @@ impl Render for SidebarDemo {
|
|||||||
"custom entries slot user content around the rows",
|
"custom entries slot user content around the rows",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(15.))
|
.w(px(240.))
|
||||||
.h(rems(22.5))
|
.h(rems(22.5))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(colors.border)
|
.border_color(colors.border)
|
||||||
|
.bg(colors.surface)
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.child(
|
.child(
|
||||||
Sidebar::new("sidebar-demo-slots")
|
Sidebar::new("sidebar-demo-slots")
|
||||||
@@ -4304,31 +4307,68 @@ impl Render for SidebarDemo {
|
|||||||
),
|
),
|
||||||
))
|
))
|
||||||
.child(demo_section(
|
.child(demo_section(
|
||||||
"a custom entry fills the list; the right border is off",
|
"opaque sidebars paint the platform's sidebar tone",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(15.))
|
.w(px(240.))
|
||||||
.h(rems(13.))
|
.h(rems(13.))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(colors.border)
|
.border_color(colors.border)
|
||||||
|
.bg(colors.surface)
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.child(
|
.child(
|
||||||
Sidebar::new("sidebar-demo-custom")
|
Sidebar::new("sidebar-demo-opaque")
|
||||||
.transparent(true)
|
.selected(self.selected)
|
||||||
.border_right(false)
|
.on_change(move |selected, _, cx| {
|
||||||
.entries(move |_, _| {
|
view_opaque.update(cx, |demo, cx| {
|
||||||
vec![SidebarEntry::custom(
|
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()
|
div()
|
||||||
.w_full()
|
.w(px(192.))
|
||||||
.px_2()
|
.h(rems(13.))
|
||||||
.py_6()
|
.rounded(radius.control)
|
||||||
.flex()
|
.border_1()
|
||||||
.items_center()
|
.border_color(colors.border)
|
||||||
.justify_center()
|
.bg(colors.surface)
|
||||||
.text_color(colors.muted_foreground)
|
.overflow_hidden()
|
||||||
.child("Nothing here yet"),
|
.child(
|
||||||
)]
|
Sidebar::new("sidebar-demo-options")
|
||||||
|
.selected(self.selected)
|
||||||
|
.width(px(192.))
|
||||||
|
.padded(false)
|
||||||
|
.border_right(false)
|
||||||
|
.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