Add initial element inspector for Zed development (#31315)

Open inspector with `dev: toggle inspector` from command palette or
`cmd-alt-i` on mac or `ctrl-alt-i` on linux.

https://github.com/user-attachments/assets/54c43034-d40b-414e-ba9b-190bed2e6d2f

* Picking of elements via the mouse, with scroll wheel to inspect
occluded elements.

* Temporary manipulation of the selected element.

* Layout info and JSON-based style manipulation for `Div`.

* Navigation to code that constructed the element.

Big thanks to @as-cii and @maxdeviant for sorting out how to implement
the core of an inspector.

Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Marshall Bowers <git@maxdeviant.com>
Co-authored-by: Federico Dionisi <code@fdionisi.me>
This commit is contained in:
Michael Sloan 2025-05-23 17:08:59 -06:00 committed by GitHub
parent 685933b5c8
commit ab59982bf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 2631 additions and 406 deletions

View file

@ -404,16 +404,20 @@ impl IntoElement for TextElement {
impl Element for TextElement {
type RequestLayoutState = ();
type PrepaintState = PrepaintState;
fn id(&self) -> Option<ElementId> {
None
}
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
None
}
fn request_layout(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&gpui::InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState) {
@ -426,6 +430,7 @@ impl Element for TextElement {
fn prepaint(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&gpui::InspectorElementId>,
bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState,
window: &mut Window,
@ -523,6 +528,7 @@ impl Element for TextElement {
fn paint(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&gpui::InspectorElementId>,
bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState,
prepaint: &mut Self::PrepaintState,

View file

@ -121,7 +121,7 @@ impl Render for HelloWorld {
.bg(gpui::blue())
.border_3()
.border_color(gpui::black())
.shadow(smallvec::smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.5),
blur_radius: px(1.0),
spread_radius: px(5.0),

View file

@ -3,8 +3,6 @@ use gpui::{
WindowOptions, div, hsla, point, prelude::*, px, relative, rgb, size,
};
use smallvec::smallvec;
struct Shadow {}
impl Shadow {
@ -103,7 +101,7 @@ impl Render for Shadow {
example(
"Square",
Shadow::square()
.shadow(smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -113,7 +111,7 @@ impl Render for Shadow {
example(
"Rounded 4",
Shadow::rounded_small()
.shadow(smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -123,7 +121,7 @@ impl Render for Shadow {
example(
"Rounded 8",
Shadow::rounded_medium()
.shadow(smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -133,7 +131,7 @@ impl Render for Shadow {
example(
"Rounded 16",
Shadow::rounded_large()
.shadow(smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -143,7 +141,7 @@ impl Render for Shadow {
example(
"Circle",
Shadow::base()
.shadow(smallvec![BoxShadow {
.shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -175,7 +173,7 @@ impl Render for Shadow {
.children(vec![
example(
"Blur 0",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(0.),
@ -184,7 +182,7 @@ impl Render for Shadow {
),
example(
"Blur 2",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(2.),
@ -193,7 +191,7 @@ impl Render for Shadow {
),
example(
"Blur 4",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(4.),
@ -202,7 +200,7 @@ impl Render for Shadow {
),
example(
"Blur 8",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -211,7 +209,7 @@ impl Render for Shadow {
),
example(
"Blur 16",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(16.),
@ -227,7 +225,7 @@ impl Render for Shadow {
.children(vec![
example(
"Spread 0",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -236,7 +234,7 @@ impl Render for Shadow {
),
example(
"Spread 2",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -245,7 +243,7 @@ impl Render for Shadow {
),
example(
"Spread 4",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -254,7 +252,7 @@ impl Render for Shadow {
),
example(
"Spread 8",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -263,7 +261,7 @@ impl Render for Shadow {
),
example(
"Spread 16",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -279,7 +277,7 @@ impl Render for Shadow {
.children(vec![
example(
"Square Spread 0",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -288,7 +286,7 @@ impl Render for Shadow {
),
example(
"Square Spread 8",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -297,7 +295,7 @@ impl Render for Shadow {
),
example(
"Square Spread 16",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -313,7 +311,7 @@ impl Render for Shadow {
.children(vec![
example(
"Rounded Large Spread 0",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -322,7 +320,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Spread 8",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -331,7 +329,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Spread 16",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.0, 0.0, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -347,7 +345,7 @@ impl Render for Shadow {
.children(vec![
example(
"Left",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(-8.), px(0.)),
blur_radius: px(8.),
@ -356,7 +354,7 @@ impl Render for Shadow {
),
example(
"Right",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(8.), px(0.)),
blur_radius: px(8.),
@ -365,7 +363,7 @@ impl Render for Shadow {
),
example(
"Top",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(-8.)),
blur_radius: px(8.),
@ -374,7 +372,7 @@ impl Render for Shadow {
),
example(
"Bottom",
Shadow::base().shadow(smallvec![BoxShadow {
Shadow::base().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -390,7 +388,7 @@ impl Render for Shadow {
.children(vec![
example(
"Square Left",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(-8.), px(0.)),
blur_radius: px(8.),
@ -399,7 +397,7 @@ impl Render for Shadow {
),
example(
"Square Right",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(8.), px(0.)),
blur_radius: px(8.),
@ -408,7 +406,7 @@ impl Render for Shadow {
),
example(
"Square Top",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(-8.)),
blur_radius: px(8.),
@ -417,7 +415,7 @@ impl Render for Shadow {
),
example(
"Square Bottom",
Shadow::square().shadow(smallvec![BoxShadow {
Shadow::square().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -433,7 +431,7 @@ impl Render for Shadow {
.children(vec![
example(
"Rounded Large Left",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(-8.), px(0.)),
blur_radius: px(8.),
@ -442,7 +440,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Right",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(8.), px(0.)),
blur_radius: px(8.),
@ -451,7 +449,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Top",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(-8.)),
blur_radius: px(8.),
@ -460,7 +458,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Bottom",
Shadow::rounded_large().shadow(smallvec![BoxShadow {
Shadow::rounded_large().shadow(vec![BoxShadow {
color: hsla(0.0, 0.5, 0.5, 0.3),
offset: point(px(0.), px(8.)),
blur_radius: px(8.),
@ -476,7 +474,7 @@ impl Render for Shadow {
.children(vec![
example(
"Circle Multiple",
Shadow::base().shadow(smallvec![
Shadow::base().shadow(vec![
BoxShadow {
color: hsla(0.0 / 360., 1.0, 0.5, 0.3), // Red
offset: point(px(0.), px(-12.)),
@ -505,7 +503,7 @@ impl Render for Shadow {
),
example(
"Square Multiple",
Shadow::square().shadow(smallvec![
Shadow::square().shadow(vec![
BoxShadow {
color: hsla(0.0 / 360., 1.0, 0.5, 0.3), // Red
offset: point(px(0.), px(-12.)),
@ -534,7 +532,7 @@ impl Render for Shadow {
),
example(
"Rounded Large Multiple",
Shadow::rounded_large().shadow(smallvec![
Shadow::rounded_large().shadow(vec![
BoxShadow {
color: hsla(0.0 / 360., 1.0, 0.5, 0.3), // Red
offset: point(px(0.), px(-12.)),

View file

@ -73,7 +73,7 @@ impl Render for HelloWorld {
.flex_shrink_0()
.text_xl()
.overflow_hidden()
.text_overflow(TextOverflow::Ellipsis(""))
.text_overflow(TextOverflow::Truncate("".into()))
.border_1()
.border_color(gpui::green())
.child("TRUNCATE: ".to_owned() + text),
@ -83,7 +83,7 @@ impl Render for HelloWorld {
.flex_shrink_0()
.text_xl()
.overflow_hidden()
.text_overflow(TextOverflow::Ellipsis(""))
.text_overflow(TextOverflow::Truncate("".into()))
.line_clamp(3)
.border_1()
.border_color(gpui::green())

View file

@ -104,7 +104,7 @@ impl Render for WindowShadow {
.when(!tiling.left, |div| div.border_l(border_size))
.when(!tiling.right, |div| div.border_r(border_size))
.when(!tiling.is_tiled(), |div| {
div.shadow(smallvec::smallvec![gpui::BoxShadow {
div.shadow(vec![gpui::BoxShadow {
color: Hsla {
h: 0.,
s: 0.,
@ -144,7 +144,7 @@ impl Render for WindowShadow {
.w(px(200.0))
.h(px(100.0))
.bg(green())
.shadow(smallvec::smallvec![gpui::BoxShadow {
.shadow(vec![gpui::BoxShadow {
color: Hsla {
h: 0.,
s: 0.,