Skip to content

Commit 0998abd

Browse files
committed
Add support for visualizing Vec<String> in the Data panel
1 parent 0d8c521 commit 0998abd

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
165165
Table<Raster<GPU>>,
166166
Table<Color>,
167167
Table<GradientStops>,
168+
Vec<String>,
168169
f64,
169170
u32,
170171
u64,
@@ -203,12 +204,44 @@ trait TableRowLayout {
203204
}
204205
}
205206

207+
impl<T: TableRowLayout> TableRowLayout for Vec<T> {
208+
fn type_name() -> &'static str {
209+
"Vec"
210+
}
211+
fn identifier(&self) -> String {
212+
format!("Vec<{}> ({} element{})", T::type_name(), self.len(), if self.len() == 1 { "" } else { "s" })
213+
}
214+
fn element_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
215+
if let Some(index) = data.desired_path.get(data.current_depth).copied() {
216+
if let Some(row) = self.get(index) {
217+
data.current_depth += 1;
218+
let result = row.layout_with_breadcrumb(data);
219+
data.current_depth -= 1;
220+
return result;
221+
} else {
222+
warn!("Desired path truncated");
223+
data.desired_path.truncate(data.current_depth);
224+
}
225+
}
226+
227+
let mut rows = self
228+
.iter()
229+
.enumerate()
230+
.map(|(index, row)| vec![TextLabel::new(format!("{index}")).narrow(true).widget_holder(), row.element_widget(index)])
231+
.collect::<Vec<_>>();
232+
233+
rows.insert(0, column_headings(&["", "element"]));
234+
235+
vec![LayoutGroup::Table { rows }]
236+
}
237+
}
238+
206239
impl<T: TableRowLayout> TableRowLayout for Table<T> {
207240
fn type_name() -> &'static str {
208241
"Table"
209242
}
210243
fn identifier(&self) -> String {
211-
format!("Table<{}> ({} row{})", T::type_name(), self.len(), if self.len() == 1 { "" } else { "s" })
244+
format!("Table<{}> ({} element{})", T::type_name(), self.len(), if self.len() == 1 { "" } else { "s" })
212245
}
213246
fn element_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
214247
if let Some(index) = data.desired_path.get(data.current_depth).copied() {
@@ -595,7 +628,13 @@ impl TableRowLayout for String {
595628
"String"
596629
}
597630
fn identifier(&self) -> String {
598-
"String".to_string()
631+
// Show the first line, and if there are more, indicate that with an ellipsis
632+
let first_line = self.lines().next().unwrap_or("");
633+
if self.lines().count() > 1 {
634+
format!("\"{} …\"", first_line)
635+
} else {
636+
format!("\"{}\"", first_line)
637+
}
599638
}
600639
fn element_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
601640
let widgets = vec![TextAreaInput::new(self.to_string()).disabled(true).widget_holder()];

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl FrontendGraphDataType {
3737
TaggedValue::Vector(_) => Self::Vector,
3838
TaggedValue::Color(_) => Self::Color,
3939
TaggedValue::Gradient(_) | TaggedValue::GradientStops(_) | TaggedValue::GradientTable(_) => Self::Gradient,
40-
TaggedValue::String(_) => Self::Typography,
40+
TaggedValue::String(_) | TaggedValue::VecString(_) => Self::Typography,
4141
_ => Self::General,
4242
}
4343
}

frontend/src/components/panels/Data.svelte

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@
4545
&:not(:first-child) {
4646
margin-top: 0;
4747
}
48+
49+
tr:first-child:has(td:first-child label:empty) ~ tr td:first-child {
50+
width: 0;
51+
}
52+
}
53+
54+
.widget-span:has(.text-area-input) {
55+
flex: 1 1 100%;
56+
57+
.text-area-input textarea {
58+
height: 100%;
59+
margin-top: 0;
60+
margin-bottom: 0;
61+
resize: none;
62+
}
4863
}
4964
}
5065
</style>

node-graph/graph-craft/src/document/value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ tagged_value! {
180180
VecF64(Vec<f64>),
181181
VecDVec2(Vec<DVec2>),
182182
F64Array4([f64; 4]),
183+
VecString(Vec<String>),
183184
NodePath(Vec<NodeId>),
184185
// ===========
185186
// TABLE TYPES

0 commit comments

Comments
 (0)