From f5752969abb96e3c10bdfd332a792561a50dfd66 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 14 Apr 2021 15:09:38 -0700 Subject: [PATCH] Include constraints in element tree JSON debug output Co-Authored-By: Nathan Sobo --- gpui/src/elements/constrained_box.rs | 2 +- gpui/src/elements/new.rs | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gpui/src/elements/constrained_box.rs b/gpui/src/elements/constrained_box.rs index 95b6d29637..47e83e27a9 100644 --- a/gpui/src/elements/constrained_box.rs +++ b/gpui/src/elements/constrained_box.rs @@ -91,6 +91,6 @@ impl Element for ConstrainedBox { _: &Self::PaintState, ctx: &DebugContext, ) -> json::Value { - json!({"type": "ConstrainedBox", "constraint": self.constraint.to_json(), "child": self.child.debug(ctx)}) + json!({"type": "ConstrainedBox", "set_constraint": self.constraint.to_json(), "child": self.child.debug(ctx)}) } } diff --git a/gpui/src/elements/new.rs b/gpui/src/elements/new.rs index 3521a5fab0..e45a71e16a 100644 --- a/gpui/src/elements/new.rs +++ b/gpui/src/elements/new.rs @@ -4,6 +4,7 @@ use crate::{ SizeConstraint, }; use core::panic; +use json::ToJson; use replace_with::replace_with_or_abort; use std::{any::Any, borrow::Cow}; @@ -90,11 +91,13 @@ pub enum Lifecycle { }, PostLayout { element: T, + constraint: SizeConstraint, size: Vector2F, layout: T::LayoutState, }, PostPaint { element: T, + constraint: SizeConstraint, bounds: RectF, layout: T::LayoutState, paint: T::PaintState, @@ -119,6 +122,7 @@ impl AnyElement for Lifecycle { result = Some(size); Lifecycle::PostLayout { element, + constraint, size, layout, } @@ -132,6 +136,7 @@ impl AnyElement for Lifecycle { element, size, layout, + .. } = self { element.after_layout(*size, layout, ctx); @@ -144,6 +149,7 @@ impl AnyElement for Lifecycle { replace_with_or_abort(self, |me| { if let Lifecycle::PostLayout { mut element, + constraint, size, mut layout, } = me @@ -152,6 +158,7 @@ impl AnyElement for Lifecycle { let paint = element.paint(bounds, &mut layout, ctx); Lifecycle::PostPaint { element, + constraint, bounds, layout, paint, @@ -168,6 +175,7 @@ impl AnyElement for Lifecycle { bounds, layout, paint, + .. } = self { element.dispatch_event(event, *bounds, layout, paint, ctx) @@ -196,10 +204,25 @@ impl AnyElement for Lifecycle { match self { Lifecycle::PostPaint { element, + constraint, bounds, layout, paint, - } => element.debug(*bounds, layout, paint, ctx), + } => { + let mut value = element.debug(*bounds, layout, paint, ctx); + if let json::Value::Object(map) = &mut value { + let mut new_map: crate::json::Map = + Default::default(); + if let Some(typ) = map.remove("type") { + new_map.insert("type".into(), typ); + } + new_map.insert("constraint".into(), constraint.to_json()); + new_map.append(map); + json::Value::Object(new_map) + } else { + value + } + } _ => panic!("invalid element lifecycle state"), } }