Files
Ely-GPUI-Components/examples/gallery/pages/theme/platform.rs
T
ZacharyZhang-NY 3f1597fa28 Port · Parity: every page matches gpui 0.2.2's; the rules re-tested
Every page and scripted state was shot with gpui 0.2.2 and with the
port, light and dark, full width and at 280px, judged pair by pair by
agents with skeptics, and every page's log diffed. What differed is
fixed, each with a test that fails without it where the test platform
can show it:

- The gallery's harness takes posted mouse moves (gpui_macos listens
  to a tracking area), posts each drag move twice (it no longer
  replays a held drag), and waits three frames before each shot.
- Rolling digits: a block column, so taffy 0.13 lends the cell no
  baseline, and a line of whole device pixels, since gpui snaps each
  length on its own. DescriptionList's row aligns ends.
- Margins that taffy 0.13 collapses through a plain block: the
  drawer's pull and snap, the stagger and transition rise, the dialog
  and palette rises, the fullscreen dialog's slide.
- An Input keeps room to type in a squeezed row; the field rows drop
  w_full, whose reason was taffy 0.9's.

AGENTS.md's rules that named gpui 0.2.2 or taffy 0.9 were re-tested
against both sources and rewritten, and new ones say what the port
changed. TASKS.md's tags follow: what the new gpui makes possible is
prove. Captions, doc comments and README say what holds now.
2026-09-29 10:39:55 -04:00

193 lines
6.3 KiB
Rust

use ely_gpui_component::{
buttons::{Button, SegmentedControl},
files::FileIcon,
forms::Switch,
primitives::{IconName, IconTheme},
shell::{Vibrancy, WindowControls},
theme::{ActiveTheme, Platform, Theme},
typography::{Kbd, KbdCombo},
};
use gpui::{
App, AppContext, Bounds, Context, IntoElement, ParentElement, Render, Styled, TitlebarOptions,
Window, WindowBackgroundAppearance, WindowBounds, WindowOptions, div, point, px, size,
};
use crate::{
probe::{Opened, probe},
ui::{change, keep, section, specimen, specimens},
};
const PLATFORMS: [(Platform, &str); 3] = [
(Platform::Mac, "macOS"),
(Platform::Windows, "Windows"),
(Platform::Linux, "Linux"),
];
/// Whether the demo's own icon rules are on.
struct Owned(bool);
pub fn platform(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
section(
"Platform Style · IconThemeProvider · VibrancyBackground",
"The theme's platform decides window buttons and key caps, and starts as the system's. An icon theme lays an owner's rules over Ely's file icons. A frosted pane lets a blurred window's backdrop through; gpui blurs as vibrancy on macOS and acrylic on Windows, and sets Mica on Windows 11.",
cx,
)
.child(
specimens()
.child(specimen("Platform", platforms(cx), cx))
.child(specimen("IconTheme", icons(window, cx), cx))
.child(specimen(
"Vibrancy",
probe(
"frosted-open",
Button::new("frosted-open", "Open a frosted window")
.on_click(|_, _, cx| frosted(cx)),
),
cx,
)),
)
}
fn platforms(cx: &App) -> impl IntoElement + use<> {
let shown = cx.theme().platform;
let label = PLATFORMS
.iter()
.find(|(platform, _)| *platform == shown)
.map(|(_, label)| *label)
.expect("a listed platform");
let control = PLATFORMS.iter().fold(
SegmentedControl::new("platform", label),
|control, (_, label)| control.segment(*label, *label, None),
);
div()
.w(px(320.))
.flex()
.flex_col()
.gap_4()
.child(control.on_change(|picked, _, cx| {
let (platform, _) = PLATFORMS
.iter()
.find(|(_, label)| *label == picked.as_ref())
.expect("a listed platform");
Theme::update(cx, |theme| theme.platform = *platform);
}))
.child(
div()
.flex()
.flex_wrap()
.items_center()
.justify_between()
.gap_3()
.child(WindowControls::new("platform-controls"))
.child(
div()
.flex()
.items_center()
.gap_3()
.child(Kbd::new("secondary-s"))
.child(KbdCombo::new("secondary-k secondary-s")),
),
)
}
fn icons(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
let owned = keep("icon-theme", || Owned(false), window, cx);
let on = owned.read(cx).0;
let muted = cx.theme().colors.fg_muted;
let rows = ["Cargo.toml", "README.md", "main.rs", "logo.svg"].map(|name| {
div()
.flex()
.items_center()
.gap_2()
.child(FileIcon::file(name))
.child(div().text_color(muted).child(name))
});
div()
.w(px(240.))
.flex()
.flex_col()
.gap_2()
.child(
Switch::new("icon-theme", on)
.label("The owner's icons")
.on_change(move |on, _, cx| {
let theme = if on {
IconTheme::default()
.name("Cargo.toml", IconName::Package)
.name("README.md", IconName::BookOpen)
.extension("rs", IconName::Braces)
} else {
IconTheme::default()
};
theme.apply(cx);
change(&owned, cx, |owned| owned.0 = on);
}),
)
.children(rows)
}
fn frosted(cx: &mut App) {
let options = WindowOptions {
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
None,
size(px(560.), px(340.)),
cx,
))),
titlebar: Some(TitlebarOptions {
title: Some("Frosted".into()),
appears_transparent: true,
traffic_light_position: Some(point(px(16.0), px(18.0))),
}),
window_background: WindowBackgroundAppearance::Blurred,
..Default::default()
};
let handle = cx
.open_window(options, |_, cx| cx.new(|_| Frosted))
.expect("the frosted window opens");
Opened::insert("frosted", handle.into(), cx);
}
/// A window whose sidebar lets the desktop through.
struct Frosted;
impl Render for Frosted {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();
let colors = &theme.colors;
div()
.size_full()
.flex()
.font_family(theme.font_family.clone())
.text_color(colors.fg)
.child(
Vibrancy::new()
.w(px(180.))
.h_full()
.pt_12()
.px_3()
.flex()
.flex_col()
.gap_1()
.children(
["Library", "Recents", "Shared"]
.map(|name| div().px_2().py_1().child(name)),
),
)
.child(
div()
.flex_1()
.h_full()
.p_6()
.pt_12()
.bg(colors.bg)
.border_l_1()
.border_color(colors.border)
.min_w_0()
.text_color(colors.fg_muted)
.child(
div().child("The sidebar lets the desktop through; this pane stays solid."),
),
)
}
}