Components / content
BrowserPanel builder
A framed web view: address, controls, and the rectangle a page goes in.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::content::BrowserPanel;
Reviewed in browser-panel.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
url(url: impl Into<SharedString>) -> Self
state(state: ViewportState) -> Self
viewport(viewport: impl IntoElement) -> Self
on_back(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
on_forward(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
on_reload(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
Example · browser-panel
fn browser_panel(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.child(
// One size class for every panel: a difference between two tiles
// here is a difference in what the panel shows, never in the frame
// it was handed.
row(&theme)
.items_start()
.child(
div().w(px(272.0)).h(px(200.0)).child(
BrowserPanel::new("scene.browser.loading")
.url("https://docs.example.com/a/long/path/that-must-stay-inside-the-address-well")
.state(ViewportState::Loading)
.on_reload(|_, _| {}),
),
)
.child(
div().w(px(272.0)).h(px(200.0)).child(
BrowserPanel::new("scene.browser.empty")
.url("https://docs.example.com/empty")
.state(ViewportState::Empty)
.on_back(|_, _| {})
.on_reload(|_, _| {}),
),
)
.child(
div().w(px(272.0)).h(px(200.0)).child(
BrowserPanel::new("scene.browser.unavailable")
.url("https://internal.example.com/admin")
.state(ViewportState::Unavailable(
"The workspace policy does not allow this host.".into(),
))
.on_reload(|_, _| {}),
),
),
)
.child(
row(&theme)
.items_start()
.child(
div().w(px(272.0)).h(px(200.0)).child(
BrowserPanel::new("scene.browser.error")
.url("https://status.example.com/incidents/current")
.state(ViewportState::Error(
"The host could not resolve this address.".into(),
))
.on_back(|_, _| {})
.on_reload(|_, _| {}),
),
)
.child(
div().w(px(272.0)).h(px(200.0)).child(
BrowserPanel::new("scene.browser.ready")
.url("https://docs.example.com/ready")
.state(ViewportState::Ready)
.viewport(
div()
.size_full()
.p_token(&theme, Space::Md)
.child(crate::foundation::text(
&theme,
TypeScale::Subtitle,
"Host-owned page surface",
))
.child(
div()
.mt_token(&theme, Space::Sm)
.child(crate::foundation::text(&theme, TypeScale::Body, "Long page content remains clipped by the BrowserPanel viewport even when it cannot wrap naturally.").text_tone(&theme, TextTone::Muted)),
),
)
.on_back(|_, _| {})
.on_forward(|_, _| {})
.on_reload(|_, _| {}),
),
),
)
.into_any_element()
}