From 51cff7656da54f33f47fc14454dcdcd76a667438 Mon Sep 17 00:00:00 2001 From: "Sergei G." Date: Fri, 12 Jun 2026 10:41:36 +0400 Subject: [PATCH] component_preview: Fix example rendering no text or icons The example never attached the embedded asset source and built gpui_platform without any platform text-system features. On macOS the missing "font-kit" feature makes MacPlatform fall back to gpui::NoopTextSystem, which accepts fonts and resolves font ids but rasterizes every glyph to an empty bitmap, so the window rendered no text at all. On Linux the missing "wayland"/"x11" features leave no windowing backend either. Icons were missing because the SVG assets were never embedded. Attach Assets and load the embedded fonts (the default ".ZedSans" UI font resolves to the bundled IBM Plex Sans, which is not a system font), and enable the same gpui_platform features as the zed binary. Initialize env_logger so platform warnings reach the terminal. Also fix three startup panics: - zed::Quit is already registered by zed_actions (linked through the workspace crate), so the example's own Quit action moves to the component_preview namespace. - db::kvp::KeyValueStore::global panics unless the app database global is set first. - ui_input::InputField panics unless the editor factory registered by editor::init exists. --- Cargo.lock | 3 +++ crates/component_preview/Cargo.toml | 5 ++++- .../examples/component_preview.rs | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dbae254fb27866..c456b6e7fe190b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3622,10 +3622,13 @@ name = "component_preview" version = "0.1.0" dependencies = [ "anyhow", + "assets", "client", "collections", "component", "db", + "editor", + "env_logger 0.11.8", "fs", "gpui", "gpui_platform", diff --git a/crates/component_preview/Cargo.toml b/crates/component_preview/Cargo.toml index 4a3cde33631e2d..f6aeeefdc26d64 100644 --- a/crates/component_preview/Cargo.toml +++ b/crates/component_preview/Cargo.toml @@ -40,7 +40,10 @@ uuid.workspace = true workspace.workspace = true [dev-dependencies] -gpui_platform = { workspace = true, features = ["screen-capture"] } +assets.workspace = true +editor.workspace = true +env_logger.workspace = true +gpui_platform = { workspace = true, features = ["screen-capture", "font-kit", "wayland", "x11"] } [[example]] name = "component_preview" diff --git a/crates/component_preview/examples/component_preview.rs b/crates/component_preview/examples/component_preview.rs index 8deaff1a8a61a4..a65821d0717116 100644 --- a/crates/component_preview/examples/component_preview.rs +++ b/crates/component_preview/examples/component_preview.rs @@ -1,6 +1,7 @@ //! Component Preview Example //! //! Run with: `cargo run -p component_preview --example component_preview"` +use assets::Assets; use fs::RealFs; use gpui::{AppContext as _, Bounds, KeyBinding, WindowBounds, WindowOptions, actions, size}; @@ -16,20 +17,28 @@ use workspace::{AppState, Workspace, WorkspaceStore}; use component_preview::{ComponentPreview, init}; -actions!(zed, [Quit]); +actions!(component_preview, [Quit]); fn quit(_: &Quit, cx: &mut App) { cx.quit(); } fn main() { - gpui_platform::application().run(|cx| { + env_logger::builder() + .filter_level(log::LevelFilter::Warn) + .init(); + + gpui_platform::application().with_assets(Assets).run(|cx| { component::init(); cx.on_action(quit); cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]); let version = release_channel::AppVersion::load(env!("CARGO_PKG_VERSION"), None, None); release_channel::init(version, cx); + cx.set_global(db::AppDatabase::new()); + Assets + .load_fonts(cx) + .expect("Failed to load embedded fonts"); let http_client = ReqwestClient::user_agent("component_preview").expect("Failed to create HTTP client"); @@ -68,6 +77,7 @@ fn main() { AppState::set_global(app_state.clone(), cx); workspace::init(app_state.clone(), cx); + editor::init(cx); init(app_state.clone(), cx); let size = size(px(1200.), px(800.));