`gpui_web` currently embeds IBM Plex Sans and Lilex into every browser application during platform construction. Applications such as Delta already provide their own fonts, so those binaries contain overlapping font bundles and register the same faces twice. This change starts the web platform with an empty font database, matching the ownership boundary used by native applications: the application selects and registers its fonts before opening a window. Delta already follows that sequence. GPUI's browser-capable examples now load the former eight-face bundle explicitly through shared example support, while the standalone `hello_web` example demonstrates registering a minimal application font directly. Testing performed: - `cargo check -p gpui --examples --target wasm32-unknown-unknown` - `cargo check -p gpui --examples` - `cargo check -p gpui_web --target wasm32-unknown-unknown` - `cargo check --manifest-path crates/gpui_web/examples/hello_web/Cargo.toml --target wasm32-unknown-unknown` - `./script/clippy -p gpui_web --target wasm32-unknown-unknown` - `cargo fmt -p gpui -p gpui_web --check` Release Notes: - N/A
145 lines
4.8 KiB
Rust
145 lines
4.8 KiB
Rust
#![cfg_attr(target_family = "wasm", no_main)]
|
|
|
|
#[path = "example_support/fonts.rs"]
|
|
mod example_support;
|
|
|
|
use gpui::{
|
|
App, Bounds, Context, TextOverflow, Window, WindowBounds, WindowOptions, div, prelude::*, px,
|
|
size,
|
|
};
|
|
use gpui_platform::application;
|
|
|
|
struct HelloWorld {}
|
|
|
|
impl Render for HelloWorld {
|
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
|
let text = "The longest word 你好世界这段是中文,こんにちはこの段落は日本語です in any of the major \
|
|
English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that \
|
|
refers to a lung disease contracted from the inhalation of very fine silica particles, \
|
|
a url https://github.com/zed-industries/zed/pull/35724?query=foo&bar=2, \
|
|
specifically from a volcano; medically, it is the same as silicosis.";
|
|
div()
|
|
.id("page")
|
|
.size_full()
|
|
.flex()
|
|
.flex_col()
|
|
.p_2()
|
|
.gap_2()
|
|
.bg(gpui::white())
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.flex_shrink_0()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.border_1()
|
|
.border_color(gpui::red())
|
|
.text_ellipsis()
|
|
.child("longer text in flex 1"),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.border_1()
|
|
.border_color(gpui::red())
|
|
.text_ellipsis()
|
|
.child("short flex"),
|
|
)
|
|
.child(
|
|
div()
|
|
.overflow_hidden()
|
|
.border_1()
|
|
.border_color(gpui::red())
|
|
.text_ellipsis()
|
|
.w_full()
|
|
.child("A short text in normal div"),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex_shrink_0()
|
|
.text_xl()
|
|
.truncate()
|
|
.border_1()
|
|
.border_color(gpui::blue())
|
|
.child("ELLIPSIS: ".to_owned() + text),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex_shrink_0()
|
|
.text_xl()
|
|
.overflow_hidden()
|
|
.text_ellipsis()
|
|
.line_clamp(2)
|
|
.border_1()
|
|
.border_color(gpui::blue())
|
|
.child("ELLIPSIS 2 lines: ".to_owned() + text),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex_shrink_0()
|
|
.text_xl()
|
|
.overflow_hidden()
|
|
.text_overflow(TextOverflow::Truncate("".into()))
|
|
.border_1()
|
|
.border_color(gpui::green())
|
|
.child("TRUNCATE: ".to_owned() + text),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex_shrink_0()
|
|
.text_xl()
|
|
.overflow_hidden()
|
|
.text_overflow(TextOverflow::Truncate("".into()))
|
|
.line_clamp(3)
|
|
.border_1()
|
|
.border_color(gpui::green())
|
|
.child("TRUNCATE 3 lines: ".to_owned() + text),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex_shrink_0()
|
|
.text_xl()
|
|
.whitespace_nowrap()
|
|
.overflow_hidden()
|
|
.border_1()
|
|
.border_color(gpui::black())
|
|
.child("NOWRAP: ".to_owned() + text),
|
|
)
|
|
.child(div().text_xl().w_full().child(text))
|
|
}
|
|
}
|
|
|
|
fn run_example() {
|
|
application().run(|cx: &mut App| {
|
|
if !example_support::load_fonts(cx) {
|
|
return;
|
|
}
|
|
let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
|
|
cx.open_window(
|
|
WindowOptions {
|
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
|
..Default::default()
|
|
},
|
|
|_, cx| cx.new(|_| HelloWorld {}),
|
|
)
|
|
.unwrap();
|
|
cx.activate(true);
|
|
});
|
|
}
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
fn main() {
|
|
run_example();
|
|
}
|
|
|
|
#[cfg(target_family = "wasm")]
|
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
|
pub fn start() {
|
|
gpui_platform::web_init();
|
|
run_example();
|
|
}
|