Skip to content

Commit 19c49a5

Browse files
committed
Cleanup
1 parent 9173901 commit 19c49a5

2 files changed

Lines changed: 48 additions & 41 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,10 @@ impl TableRowLayout for GradientType {
785785
"GradientType"
786786
}
787787
fn identifier(&self) -> String {
788-
format!("{self:?}")
788+
self.to_string()
789789
}
790790
fn value_widget(&self, _target: PathStep, _data: &LayoutData) -> WidgetInstance {
791-
TextLabel::new(format!("{self:?}")).narrow(true).widget_instance()
791+
TextLabel::new(self.to_string()).narrow(true).widget_instance()
792792
}
793793
fn value_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
794794
vec![LayoutGroup::row(vec![self.value_widget(PathStep::Element(0), _data)])]
@@ -800,10 +800,10 @@ impl TableRowLayout for GradientSpreadMethod {
800800
"GradientSpreadMethod"
801801
}
802802
fn identifier(&self) -> String {
803-
format!("{self:?}")
803+
self.to_string()
804804
}
805805
fn value_widget(&self, _target: PathStep, _data: &LayoutData) -> WidgetInstance {
806-
TextLabel::new(format!("{self:?}")).narrow(true).widget_instance()
806+
TextLabel::new(self.to_string()).narrow(true).widget_instance()
807807
}
808808
fn value_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
809809
vec![LayoutGroup::row(vec![self.value_widget(PathStep::Element(0), _data)])]
@@ -974,6 +974,9 @@ macro_rules! known_table_row_types {
974974

975975
/// Uses `Display` instead of `Debug` for attribute types that have a nicer human-readable format.
976976
fn display_value_override(any: &dyn Any) -> Option<String> {
977+
if let Some(value) = any.downcast_ref::<DVec2>() {
978+
return Some(format_dvec2(*value));
979+
}
977980
if let Some(value) = any.downcast_ref::<BlendMode>() {
978981
return Some(value.to_string());
979982
}

node-graph/nodes/graphic/src/graphic.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ pub fn path_of_subgraph(_: impl Ctx, node_path: Table<NodeId>) -> Table<NodeId>
217217
node_path.into_iter().take(len.saturating_sub(1)).collect()
218218
}
219219

220-
/// Writes a named attribute on each item of the input `Table`. The value-producing input is evaluated once per item,
221-
/// with the item's index and the item itself (as a `Table` containing only that item, passed as a vararg) provided via
222-
/// context, so the upstream pipeline can return a different value per item that may be derived from the item's own data.
223-
/// If the attribute already exists, its values are replaced; if not, the attribute is added.
224-
#[node_macro::node(category("General"))]
220+
/// Sets a named attribute on the input `Table`, computing one value per item via the value-producing input. That input
221+
/// is evaluated once per item, with the item's index and the item itself (as a `Table` containing only that item,
222+
/// passed as a vararg) provided via context, so the upstream pipeline can return a different value per item that may
223+
/// be derived from the item's own data. If the attribute already exists, its values are replaced; if not, it's added.
224+
#[node_macro::node(category("Attributes: Write"))]
225225
async fn write_attribute<T: AnyHash + Clone + Send + Sync + CacheHash, U: Clone + Send + Sync + Default + std::fmt::Debug + PartialEq + CacheHash + 'static>(
226226
ctx: impl ExtractAll + CloneVarArgs + Ctx,
227-
/// The `Table` whose items will gain or have replaced the named attribute.
227+
/// The `Table` to set the named attribute on (one value per item).
228228
#[implementations(
229229
Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>, Table<Artboard>,
230230
Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>, Table<Graphic>,
@@ -258,9 +258,9 @@ async fn write_attribute<T: AnyHash + Clone + Send + Sync + CacheHash, U: Clone
258258
content
259259
}
260260

261-
/// Zips a new attribute onto each row of the primary table, taking the value from the corresponding element values in the source table. Source elements are wrapped if there are fewer than in the destination table.
262-
#[node_macro::node(category("General"))]
263-
fn zip_attribute<T: AnyHash + Clone + Send + Sync + CacheHash, U: AnyHash + Clone + Send + Sync + CacheHash + Default + std::fmt::Debug + PartialEq + 'static>(
261+
/// Sets a named attribute on the primary table, with each value taken from the corresponding item's element in the source table (paired by index, wrapping if the source has fewer items).
262+
#[node_macro::node(category("Attributes: Write"))]
263+
fn attach_attribute<T: AnyHash + Clone + Send + Sync + CacheHash, U: AnyHash + Clone + Send + Sync + CacheHash + Default + std::fmt::Debug + PartialEq + 'static>(
264264
_: impl Ctx,
265265
/// The `Table` to attach the new attribute to.
266266
#[implementations(
@@ -310,16 +310,16 @@ fn zip_attribute<T: AnyHash + Clone + Send + Sync + CacheHash, U: AnyHash + Clon
310310
content
311311
}
312312

313-
/// Reads a named `Vector` attribute from each row of the input table, outputting a new table where each row's element is the attribute value. Rows without the attribute are omitted.
314-
#[node_macro::node(category("General"))]
313+
/// Reads a named `Vector` attribute from the input table, outputting each value as an element of a new `Table<Vector>`.
314+
#[node_macro::node(category("Attributes: Read"))]
315315
fn read_attribute_vector<T: AnyHash + Clone + Send + Sync + CacheHash>(
316316
_: impl Ctx,
317317
#[implementations(
318318
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
319319
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
320320
)]
321321
content: Table<T>,
322-
/// The attribute name (key) to read from each row.
322+
/// The attribute name (key) to read.
323323
name: String,
324324
) -> Table<Vector> {
325325
let mut result = Table::with_capacity(content.len());
@@ -330,37 +330,41 @@ fn read_attribute_vector<T: AnyHash + Clone + Send + Sync + CacheHash>(
330330
result
331331
}
332332

333-
/// Reads a named numeric attribute (`f64` or `u64`) from each row of the input table, outputting a new `Table<f64>`. `u64` values are converted to `f64`. Rows without the attribute are omitted.
334-
#[node_macro::node(category("General"))]
333+
/// Reads a named numeric attribute (`f64`, `u64`, or `u32`) from the input table, outputting each value as an element of a new `Table<f64>`. Integer values are converted to `f64`.
334+
#[node_macro::node(category("Attributes: Read"))]
335335
fn read_attribute_number<T: AnyHash + Clone + Send + Sync + CacheHash>(
336336
_: impl Ctx,
337337
#[implementations(
338338
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
339339
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
340340
)]
341341
content: Table<T>,
342-
/// The attribute name (key) to read from each row.
342+
/// The attribute name (key) to read.
343343
name: String,
344344
) -> Table<f64> {
345345
let mut result = Table::with_capacity(content.len());
346346
for index in 0..content.len() {
347-
let value = content.attribute::<f64>(&name, index).copied().or_else(|| content.attribute::<u64>(&name, index).map(|v| *v as f64));
347+
let value = content
348+
.attribute::<f64>(&name, index)
349+
.copied()
350+
.or_else(|| content.attribute::<u64>(&name, index).map(|v| *v as f64))
351+
.or_else(|| content.attribute::<u32>(&name, index).map(|v| *v as f64));
348352
let Some(value) = value else { continue };
349353
result.push(TableRow::new_from_element(value));
350354
}
351355
result
352356
}
353357

354-
/// Reads a named `bool` attribute from each row of the input table, outputting a new `Table<bool>`. Rows without the attribute are omitted.
355-
#[node_macro::node(category("General"))]
358+
/// Reads a named `bool` attribute from the input table, outputting each value as an element of a new `Table<bool>`.
359+
#[node_macro::node(category("Attributes: Read"))]
356360
fn read_attribute_bool<T: AnyHash + Clone + Send + Sync + CacheHash>(
357361
_: impl Ctx,
358362
#[implementations(
359363
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
360364
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
361365
)]
362366
content: Table<T>,
363-
/// The attribute name (key) to read from each row.
367+
/// The attribute name (key) to read.
364368
name: String,
365369
) -> Table<bool> {
366370
let mut result = Table::with_capacity(content.len());
@@ -371,16 +375,16 @@ fn read_attribute_bool<T: AnyHash + Clone + Send + Sync + CacheHash>(
371375
result
372376
}
373377

374-
/// Reads a named `String` attribute from each row of the input table, outputting a new `Table<String>`. Rows without the attribute are omitted.
375-
#[node_macro::node(category("General"))]
378+
/// Reads a named `String` attribute from the input table, outputting each value as an element of a new `Table<String>`.
379+
#[node_macro::node(category("Attributes: Read"))]
376380
fn read_attribute_string<T: AnyHash + Clone + Send + Sync + CacheHash>(
377381
_: impl Ctx,
378382
#[implementations(
379383
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
380384
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
381385
)]
382386
content: Table<T>,
383-
/// The attribute name (key) to read from each row.
387+
/// The attribute name (key) to read.
384388
name: String,
385389
) -> Table<String> {
386390
let mut result = Table::with_capacity(content.len());
@@ -391,16 +395,16 @@ fn read_attribute_string<T: AnyHash + Clone + Send + Sync + CacheHash>(
391395
result
392396
}
393397

394-
/// Reads a named `DAffine2` transform attribute from each row of the input table, outputting a new `Table<DAffine2>`. Rows without the attribute are omitted.
395-
#[node_macro::node(category("General"))]
398+
/// Reads a named `DAffine2` transform attribute from the input table, outputting each value as an element of a new `Table<DAffine2>`.
399+
#[node_macro::node(category("Attributes: Read"))]
396400
fn read_attribute_transform<T: AnyHash + Clone + Send + Sync + CacheHash>(
397401
_: impl Ctx,
398402
#[implementations(
399403
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
400404
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
401405
)]
402406
content: Table<T>,
403-
/// The attribute name (key) to read from each row.
407+
/// The attribute name (key) to read.
404408
name: String,
405409
) -> Table<DAffine2> {
406410
let mut result = Table::with_capacity(content.len());
@@ -411,16 +415,16 @@ fn read_attribute_transform<T: AnyHash + Clone + Send + Sync + CacheHash>(
411415
result
412416
}
413417

414-
/// Reads a named `Color` attribute from each row of the input table, outputting a new `Table<Color>`. Rows without the attribute are omitted.
415-
#[node_macro::node(category("General"))]
418+
/// Reads a named `Color` attribute from the input table, outputting each value as an element of a new `Table<Color>`.
419+
#[node_macro::node(category("Attributes: Read"))]
416420
fn read_attribute_color<T: AnyHash + Clone + Send + Sync + CacheHash>(
417421
_: impl Ctx,
418422
#[implementations(
419423
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
420424
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
421425
)]
422426
content: Table<T>,
423-
/// The attribute name (key) to read from each row.
427+
/// The attribute name (key) to read.
424428
name: String,
425429
) -> Table<Color> {
426430
let mut result = Table::with_capacity(content.len());
@@ -431,16 +435,16 @@ fn read_attribute_color<T: AnyHash + Clone + Send + Sync + CacheHash>(
431435
result
432436
}
433437

434-
/// Reads a named `BlendMode` attribute from each row of the input table, outputting a new `Table<BlendMode>`. Rows without the attribute are omitted.
435-
#[node_macro::node(category("General"))]
438+
/// Reads a named `BlendMode` attribute from the input table, outputting each value as an element of a new `Table<BlendMode>`.
439+
#[node_macro::node(category("Attributes: Read"))]
436440
fn read_attribute_blend_mode<T: AnyHash + Clone + Send + Sync + CacheHash>(
437441
_: impl Ctx,
438442
#[implementations(
439443
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
440444
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
441445
)]
442446
content: Table<T>,
443-
/// The attribute name (key) to read from each row.
447+
/// The attribute name (key) to read.
444448
name: String,
445449
) -> Table<BlendMode> {
446450
let mut result = Table::with_capacity(content.len());
@@ -451,16 +455,16 @@ fn read_attribute_blend_mode<T: AnyHash + Clone + Send + Sync + CacheHash>(
451455
result
452456
}
453457

454-
/// Reads a named `GradientType` attribute from each row of the input table, outputting a new `Table<GradientType>`. Rows without the attribute are omitted.
455-
#[node_macro::node(category("General"))]
458+
/// Reads a named `GradientType` attribute from the input table, outputting each value as an element of a new `Table<GradientType>`.
459+
#[node_macro::node(category("Attributes: Read"))]
456460
fn read_attribute_gradient_type<T: AnyHash + Clone + Send + Sync + CacheHash>(
457461
_: impl Ctx,
458462
#[implementations(
459463
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
460464
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
461465
)]
462466
content: Table<T>,
463-
/// The attribute name (key) to read from each row.
467+
/// The attribute name (key) to read.
464468
name: String,
465469
) -> Table<GradientType> {
466470
let mut result = Table::with_capacity(content.len());
@@ -471,16 +475,16 @@ fn read_attribute_gradient_type<T: AnyHash + Clone + Send + Sync + CacheHash>(
471475
result
472476
}
473477

474-
/// Reads a named `GradientSpreadMethod` attribute from each row of the input table, outputting a new `Table<GradientSpreadMethod>`. Rows without the attribute are omitted.
475-
#[node_macro::node(category("General"))]
478+
/// Reads a named `GradientSpreadMethod` attribute from the input table, outputting each value as an element of a new `Table<GradientSpreadMethod>`.
479+
#[node_macro::node(category("Attributes: Read"))]
476480
fn read_attribute_spread_method<T: AnyHash + Clone + Send + Sync + CacheHash>(
477481
_: impl Ctx,
478482
#[implementations(
479483
Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>, Table<GradientStops>,
480484
Table<f64>, Table<bool>, Table<String>, Table<DAffine2>, Table<BlendMode>, Table<GradientType>, Table<GradientSpreadMethod>,
481485
)]
482486
content: Table<T>,
483-
/// The attribute name (key) to read from each row.
487+
/// The attribute name (key) to read.
484488
name: String,
485489
) -> Table<GradientSpreadMethod> {
486490
let mut result = Table::with_capacity(content.len());

0 commit comments

Comments
 (0)