Theme · Platform: one platform for buttons and caps, icon themes, frosted panes

theme::Platform moves out of typography and shell's ControlsStyle folds
into it; the theme's platform starts as the system's. Window buttons Ely
draws, the title bar's layout and every key cap follow it, secondary
included, through typography::keys::keystroke; a title bar whose buttons
the OS draws follows the OS. primitives::IconTheme lays an owner's rules
by file name and extension over Ely's map, for every file icon.
shell::Vibrancy fills a pane with the palette's new glass, translucent
so a window opened Blurred shows its backdrop, solid under high contrast.
gpui 0.2.2 has no Mica; that line stays blocked.
This commit is contained in:
ZacharyZhang-NY committed 2026-09-27 17:41:15 -04:00
1 parent 7f2205c811
commit d3cfc71ead
30 files changed
+593 -162

No files matched your search

+17 -15
View File
@@ -7,8 +7,8 @@ use gpui::{
use regex::RegexBuilder;
use smallvec::SmallVec;
use super::keys::{Platform, keystroke_labels};
use crate::theme::{ActiveTheme, Radius, TextSize};
use super::keys::{keystroke, keystroke_labels};
use crate::theme::{ActiveTheme, Platform, Radius, TextSize};
/// Monospace fragment on a quiet fill.
#[derive(IntoElement)]
@@ -56,28 +56,25 @@ fn cap(label: String, cx: &App) -> impl IntoElement + use<> {
.child(label)
}
fn parse(source: &str) -> Keystroke {
Keystroke::parse(source).unwrap_or_else(|error| panic!("bad keystroke {source:?}: {error}"))
}
/// One key, labeled for this platform. Takes gpui key syntax.
/// One key, labeled for the theme's platform. Takes gpui key syntax.
#[derive(IntoElement)]
pub struct Kbd {
stroke: Keystroke,
source: SharedString,
}
impl Kbd {
/// `"secondary-s"` reads ⌘S on macOS and Ctrl S elsewhere.
/// `"secondary-s"` reads ⌘S for the Mac and Ctrl S for the others.
pub fn new(source: &str) -> Self {
Self {
stroke: parse(source),
source: SharedString::from(source.to_string()),
}
}
}
impl RenderOnce for Kbd {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let labels = keystroke_labels(&self.stroke, Platform::current());
let platform = cx.theme().platform;
let labels = keystroke_labels(&keystroke(&self.source, platform), platform);
div()
.flex()
.gap_0p5()
@@ -88,27 +85,32 @@ impl RenderOnce for Kbd {
/// A chord sequence such as `"cmd-k cmd-s"`.
#[derive(IntoElement)]
pub struct KbdCombo {
strokes: SmallVec<[Keystroke; 2]>,
source: SharedString,
}
impl KbdCombo {
pub fn new(source: &str) -> Self {
Self {
strokes: source.split_whitespace().map(parse).collect(),
source: SharedString::from(source.to_string()),
}
}
}
impl RenderOnce for KbdCombo {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let platform = Platform::current();
let platform = cx.theme().platform;
let strokes: Vec<Keystroke> = self
.source
.split_whitespace()
.map(|source| keystroke(source, platform))
.collect();
let subtle = cx.theme().colors.fg_subtle;
let spelled = platform != Platform::Mac;
div()
.flex()
.items_center()
.gap_2()
.children(self.strokes.iter().map(|stroke| {
.children(strokes.iter().map(|stroke| {
let labels = keystroke_labels(stroke, platform);
let last = labels.len() - 1;
div().flex().items_center().gap_0p5().children(
+25 -16
View File
@@ -1,22 +1,20 @@
use gpui::Keystroke;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Platform {
Mac,
Windows,
Linux,
}
use crate::theme::Platform;
impl Platform {
pub fn current() -> Self {
if cfg!(target_os = "macos") {
Platform::Mac
} else if cfg!(target_os = "windows") {
Platform::Windows
} else {
Platform::Linux
}
}
/// One keystroke in gpui key syntax, `secondary` read for `platform`: Command on the Mac, Control elsewhere.
pub fn keystroke(source: &str, platform: Platform) -> Keystroke {
let secondary = if platform == Platform::Mac {
"cmd"
} else {
"ctrl"
};
let spelled: Vec<&str> = source
.split('-')
.map(|part| if part == "secondary" { secondary } else { part })
.collect();
Keystroke::parse(&spelled.join("-"))
.unwrap_or_else(|error| panic!("bad keystroke {source:?}: {error}"))
}
/// Caps for one keystroke, modifiers first, in platform order.
@@ -94,6 +92,17 @@ mod tests {
assert_eq!(labels, ["Super", "Esc"]);
}
#[test]
fn secondary_reads_for_the_platform() {
let mac = keystroke_labels(&keystroke("secondary-s", Platform::Mac), Platform::Mac);
assert_eq!(mac, ["⌘", "S"]);
let windows = Platform::Windows;
assert_eq!(
keystroke_labels(&keystroke("secondary-s", windows), windows),
["Ctrl", "S"]
);
}
#[test]
fn keys_keep_their_names_or_upper_case() {
assert_eq!(key_label("f12", Platform::Mac), "F12");