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

+87 -12
View File
@@ -1,9 +1,68 @@
use std::{collections::HashMap, sync::LazyLock};
use gpui::{App, Global};
use super::IconName;
/// The icon a file's name suggests, by its extension.
pub(crate) fn file_icon(name: &str) -> IconName {
let extension = name.rsplit_once('.').map(|(_, ext)| ext.to_lowercase());
match extension.as_deref() {
/// Which icon a file shows: an owner's rules by name and by extension, laid over Ely's map. Without one, Ely's map alone.
#[derive(Clone, Default)]
pub struct IconTheme {
names: HashMap<String, IconName>,
extensions: HashMap<String, IconName>,
}
impl Global for IconTheme {}
impl IconTheme {
/// A file of this exact name, in any case: `Cargo.toml`, `Dockerfile`.
pub fn name(mut self, name: &str, icon: IconName) -> Self {
self.names.insert(name.to_lowercase(), icon);
self
}
/// Files ending in this extension, given without its dot.
pub fn extension(mut self, extension: &str, icon: IconName) -> Self {
self.extensions.insert(extension.to_lowercase(), icon);
self
}
/// Serves every window from now on.
pub fn apply(self, cx: &mut App) {
log::info!(
"icon theme: {} names, {} extensions",
self.names.len(),
self.extensions.len()
);
cx.set_global(self);
cx.refresh_windows();
}
pub(crate) fn file(&self, name: &str) -> IconName {
let name = name.to_lowercase();
let extension = name.rsplit_once('.').map(|(_, extension)| extension);
self.names
.get(&name)
.or_else(|| extension.and_then(|extension| self.extensions.get(extension)))
.copied()
.unwrap_or_else(|| ely_icon(extension))
}
}
static ELY: LazyLock<IconTheme> = LazyLock::new(IconTheme::default);
/// The owner's icon theme, or Ely's map alone.
pub(crate) fn icon_theme(cx: &App) -> &IconTheme {
cx.try_global::<IconTheme>().unwrap_or(&ELY)
}
/// The icon a file's name suggests, under the owner's icon theme.
pub(crate) fn file_icon(name: &str, cx: &App) -> IconName {
icon_theme(cx).file(name)
}
/// Ely's icon for a file by its extension, in lower case.
fn ely_icon(extension: Option<&str>) -> IconName {
match extension {
Some(
"rs" | "ts" | "tsx" | "js" | "jsx" | "py" | "go" | "swift" | "c" | "h" | "cpp" | "java"
| "kt" | "rb" | "php" | "css" | "html",
@@ -26,16 +85,32 @@ pub(crate) fn file_icon(name: &str) -> IconName {
#[cfg(test)]
mod tests {
use super::{IconName, file_icon};
use super::{IconName, IconTheme};
#[test]
fn a_name_picks_its_icon_by_its_last_extension() {
assert_eq!(file_icon("main.RS"), IconName::FileCode);
assert_eq!(file_icon("lift.PNG"), IconName::FileImage);
assert_eq!(file_icon("notes.md"), IconName::FileText);
assert_eq!(file_icon("backup.tar.gz"), IconName::FileArchive);
assert_eq!(file_icon(".env"), IconName::FileCog);
assert_eq!(file_icon("take.mov"), IconName::FileVideoCamera);
assert_eq!(file_icon("Makefile"), IconName::File);
assert_eq!(IconTheme::default().file("main.RS"), IconName::FileCode);
assert_eq!(IconTheme::default().file("lift.PNG"), IconName::FileImage);
assert_eq!(IconTheme::default().file("notes.md"), IconName::FileText);
assert_eq!(
IconTheme::default().file("backup.tar.gz"),
IconName::FileArchive
);
assert_eq!(IconTheme::default().file(".env"), IconName::FileCog);
assert_eq!(
IconTheme::default().file("take.mov"),
IconName::FileVideoCamera
);
assert_eq!(IconTheme::default().file("Makefile"), IconName::File);
}
#[test]
fn an_owners_rules_come_before_elys_map() {
let theme = IconTheme::default()
.name("Cargo.toml", IconName::Package)
.extension("RS", IconName::Braces);
assert_eq!(theme.file("cargo.TOML"), IconName::Package);
assert_eq!(theme.file("main.rs"), IconName::Braces);
assert_eq!(theme.file("deploy.toml"), IconName::FileCog);
}
}
+2 -1
View File
@@ -18,7 +18,8 @@ mod tests;
pub use backdrop::{Backdrop, Place};
pub use disclosure::Disclosure;
pub use divider::Divider;
pub(crate) use files::file_icon;
pub use files::IconTheme;
pub(crate) use files::{file_icon, icon_theme};
pub use focus::{FocusNext, FocusPrev, FocusRing, FocusScope};
pub(crate) use focus::{Takeover, give_back, hand_back, hold_focus, tab_stop, take_focus};
pub use ghost::DragGhost;