diff --git a/editor/src/messages/color_picker/color_picker_message_handler.rs b/editor/src/messages/color_picker/color_picker_message_handler.rs index 73361b4588..7e03956b02 100644 --- a/editor/src/messages/color_picker/color_picker_message_handler.rs +++ b/editor/src/messages/color_picker/color_picker_message_handler.rs @@ -5,7 +5,7 @@ use crate::messages::prelude::*; use graphene_std::Color; use graphene_std::color::SRGBA8; use graphene_std::core_types::misc::parse_css_color; -use graphene_std::vector::style::{FillChoice, FillChoiceUI, GradientStops, GradientStopsUI}; +use graphene_std::vector::style::{FillChoice, FillChoiceUI, Gradient, GradientUI}; /// Bounds for a midpoint position (relative to the interval between two adjacent gradient stops). const MIN_MIDPOINT: f64 = 0.01; @@ -28,7 +28,7 @@ pub struct ColorPickerMessageHandler { old_is_none: bool, // When set, the picker is editing a gradient: the visual pickers and inputs target the active stop's color. - gradient: Option, + gradient: Option, active_marker_index: Option, active_marker_is_midpoint: bool, @@ -430,7 +430,7 @@ impl ColorPickerMessageHandler { // For gradient editing, the markers' handle colors mirror their gradient stop colors let markers = gradient.iter().map(|stop| SpectrumMarker::new(stop.position, stop.midpoint, stop.color)).collect(); let mut row_widgets = vec![ - SpectrumInput::new(GradientStopsUI::from(gradient)) + SpectrumInput::new(GradientUI::from(gradient)) .markers(markers) .active_marker_index(self.active_marker_index) .active_marker_is_midpoint(self.active_marker_is_midpoint) diff --git a/editor/src/messages/layout/utility_types/widgets/input_widgets.rs b/editor/src/messages/layout/utility_types/widgets/input_widgets.rs index 727b353f5b..12d17eb422 100644 --- a/editor/src/messages/layout/utility_types/widgets/input_widgets.rs +++ b/editor/src/messages/layout/utility_types/widgets/input_widgets.rs @@ -6,7 +6,7 @@ use derivative::*; use graphene_std::Color; use graphene_std::color::SRGBA8; use graphene_std::transform::ReferencePoint; -use graphene_std::vector::style::{FillChoiceUI, GradientStopsUI}; +use graphene_std::vector::style::{FillChoiceUI, GradientUI}; use graphite_proc_macros::WidgetBuilder; #[cfg_attr(feature = "wasm", derive(tsify::Tsify))] @@ -531,7 +531,7 @@ pub struct SpectrumInput { // Content /// The colored gradient drawn behind the markers (display-only, caller-owned). #[widget_builder(constructor)] - pub track: GradientStopsUI, + pub track: GradientUI, /// CSS `linear-gradient(...)` string for the track strip's `background-image`. Auto-populated from `track` at layout-send time. #[serde(rename = "trackCSS")] #[widget_builder(skip)] diff --git a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs index c9bda31717..fe5d07b38d 100644 --- a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs +++ b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs @@ -8,7 +8,7 @@ use glam::{Affine2, DAffine2, Vec2}; use graph_craft::document::NodeId; use graphene_std::blending::BlendMode; use graphene_std::color::SRGBA8; -use graphene_std::gradient::GradientStops; +use graphene_std::gradient::Gradient; use graphene_std::list::List; use graphene_std::raster_types::{CPU, GPU, Raster}; use graphene_std::vector::Vector; @@ -192,7 +192,7 @@ fn generate_layout(introspected_data: &Arc>, List>, List, - List, + List, List, List, List, @@ -201,7 +201,7 @@ fn generate_layout(introspected_data: &Arc, List, List, - GradientStops, + Gradient, f64, u32, u64, @@ -543,7 +543,7 @@ impl TableItemLayout for Color { } } -impl TableItemLayout for GradientStops { +impl TableItemLayout for Gradient { fn type_name() -> &'static str { "Gradient" } @@ -911,12 +911,12 @@ macro_rules! known_item_types { List>, List>, List, - List, + List, List, List, List, List, - GradientStops, + Gradient, Color, NodeId, DAffine2, diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 7f8941df2f..bb2ccd3604 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -125,7 +125,7 @@ pub struct DocumentMessageHandler { /// network path, the node itself, and its original relative gradient. The deferred migration removes each entry as its bake lands. /// Transient migration state, but persisted in the saved document so unfinished bakes retry on the next open instead of losing placement. #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub(crate) pending_gradient_bbox_bake: Vec<(Vec, NodeId, graphic_types::migrations::legacy::Gradient)>, + pub(crate) pending_gradient_bbox_bake: Vec<(Vec, NodeId, graphic_types::migrations::legacy::LegacyGradient)>, // ============================================= // Fields omitted from the saved document format @@ -4007,7 +4007,7 @@ mod document_message_handler_tests { #[test] fn pending_gradient_bakes_round_trip_through_serialization() { let document = DocumentMessageHandler { - pending_gradient_bbox_bake: vec![(vec![NodeId(7)], NodeId(42), graphic_types::migrations::legacy::Gradient::default())], + pending_gradient_bbox_bake: vec![(vec![NodeId(7)], NodeId(42), graphic_types::migrations::legacy::LegacyGradient::default())], ..Default::default() }; diff --git a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs index 7d986bce1b..dc02447cc3 100644 --- a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs +++ b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs @@ -11,7 +11,7 @@ use graphene_std::raster_types::Image; use graphene_std::subpath::Subpath; use graphene_std::text::{Font, TypesettingConfig}; use graphene_std::vector::style::{GradientSpreadMethod, GradientType, Stroke}; -use graphene_std::vector::{GradientStops, PointId, VectorModificationType}; +use graphene_std::vector::{Gradient, PointId, VectorModificationType}; #[impl_message(Message, DocumentMessage, GraphOperation)] #[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)] @@ -22,7 +22,7 @@ pub enum GraphOperationMessage { }, FillGradientSet { layer: LayerNodeIdentifier, - gradient: GradientStops, + gradient: Gradient, gradient_type: GradientType, spread_method: GradientSpreadMethod, transform: DAffine2, @@ -33,7 +33,7 @@ pub enum GraphOperationMessage { }, GradientStopsSet { layer: LayerNodeIdentifier, - stops: GradientStops, + stops: Gradient, }, GradientTransformSet { layer: LayerNodeIdentifier, diff --git a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs index 4e64599e79..cc5acd602e 100644 --- a/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs +++ b/editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs @@ -13,7 +13,7 @@ use graph_craft::document::{NodeId, NodeInput}; use graphene_std::list::List; use graphene_std::renderer::convert_usvg_path::convert_usvg_path; use graphene_std::text::{Font, TypesettingConfig}; -use graphene_std::vector::style::{GradientSpreadMethod, GradientStop, GradientStops, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin}; +use graphene_std::vector::style::{Gradient, GradientSpreadMethod, GradientStop, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin}; use graphene_std::{Artboard, Color}; #[derive(ExtractField)] @@ -508,8 +508,8 @@ const GRAPHITE_NAMESPACE: &str = "https://graphite.art"; /// Pre-parses the raw SVG XML to extract gradient stops that have `graphite:midpoint` attributes. /// Graphite exports gradients with midpoint curve data by writing interpolated approximation stops /// alongside the real stops. Real stops are tagged with `graphite:midpoint` attributes. -/// Returns a map from gradient element `id` to `GradientStops` containing only the real stops. -fn extract_graphite_gradient_stops(svg: &str) -> HashMap { +/// Returns a map from gradient element `id` to `Gradient` containing only the real stops. +fn extract_graphite_gradient_stops(svg: &str) -> HashMap { let mut result = HashMap::new(); // Quick check: if the SVG doesn't reference `graphite:midpoint` at all, skip parsing @@ -555,7 +555,7 @@ fn extract_graphite_gradient_stops(svg: &str) -> HashMap } if has_any_midpoint && !real_stops.is_empty() { - result.insert(gradient_id, GradientStops::new(real_stops)); + result.insert(gradient_id, Gradient::new(real_stops)); } } @@ -579,14 +579,7 @@ fn parse_hex_stop_color(hex: &str, opacity: f32) -> Option { /// interact with any existing layers in the parent stack. All descendant layers use a lightweight /// O(n) import path that skips collision detection and instead calculates positions directly from /// the known tree structure. -fn import_usvg_node( - modify_inputs: &mut ModifyInputsContext, - node: &usvg::Node, - id: NodeId, - parent: LayerNodeIdentifier, - insert_index: usize, - graphite_gradient_stops: &HashMap, -) { +fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node, id: NodeId, parent: LayerNodeIdentifier, insert_index: usize, graphite_gradient_stops: &HashMap) { let layer = modify_inputs.create_layer(id); modify_inputs.network_interface.move_layer_to_stack(layer, parent, insert_index, &[]); @@ -649,7 +642,7 @@ fn import_usvg_node_inner( id: NodeId, parent: LayerNodeIdentifier, insert_index: usize, - graphite_gradient_stops: &HashMap, + graphite_gradient_stops: &HashMap, group_extents_map: &mut HashMap>, ) -> u32 { let layer = modify_inputs.create_layer(id); @@ -692,7 +685,7 @@ fn import_usvg_node_inner( } /// Helper to apply path data (vector geometry, fill, stroke, transform) to a layer. -fn import_usvg_path(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node, path: &usvg::Path, layer: LayerNodeIdentifier, graphite_gradient_stops: &HashMap) { +fn import_usvg_path(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node, path: &usvg::Path, layer: LayerNodeIdentifier, graphite_gradient_stops: &HashMap) { let subpaths = convert_usvg_path(path); // Skip creating a Transform node entirely when the SVG-native transform is identity. @@ -807,7 +800,7 @@ fn convert_spread_method(spread_method: usvg::SpreadMethod) -> GradientSpreadMet } } -fn apply_usvg_fill(fill: &usvg::Fill, modify_inputs: &mut ModifyInputsContext, graphite_gradient_stops: &HashMap) { +fn apply_usvg_fill(fill: &usvg::Fill, modify_inputs: &mut ModifyInputsContext, graphite_gradient_stops: &HashMap) { match &fill.paint() { usvg::Paint::Color(color) => modify_inputs.fill_color_set(Some(usvg_color(*color, fill.opacity().get()))), usvg::Paint::LinearGradient(linear) => { @@ -827,7 +820,7 @@ fn apply_usvg_fill(fill: &usvg::Fill, modify_inputs: &mut ModifyInputsContext, g midpoint: 0.5, color: usvg_color(stop.color(), stop.opacity().get()), }); - GradientStops::new(stops) + Gradient::new(stops) } }; let spread_method = convert_spread_method(linear.spread_method()); @@ -851,7 +844,7 @@ fn apply_usvg_fill(fill: &usvg::Fill, modify_inputs: &mut ModifyInputsContext, g midpoint: 0.5, color: usvg_color(stop.color(), stop.opacity().get()), }); - GradientStops::new(stops) + Gradient::new(stops) } }; let spread_method = convert_spread_method(radial.spread_method()); diff --git a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs index 638e2a133d..2fcad7f069 100644 --- a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs +++ b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs @@ -16,7 +16,7 @@ use graphene_std::raster_types::Image; use graphene_std::subpath::Subpath; use graphene_std::text::{Font, TypesettingConfig}; use graphene_std::vector::style::{GradientSpreadMethod, GradientType, Stroke}; -use graphene_std::vector::{GradientStops, PointId, Vector, VectorModification, VectorModificationType}; +use graphene_std::vector::{Gradient, PointId, Vector, VectorModification, VectorModificationType}; use graphene_std::{Artboard, Color, Graphic, NodeInputDecleration}; #[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] @@ -464,7 +464,7 @@ impl<'a> ModifyInputsContext<'a> { self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::Color(color), false), false); } - pub fn fill_gradient_set(&mut self, gradient: GradientStops, gradient_type: GradientType, spread_method: GradientSpreadMethod, transform: DAffine2) { + pub fn fill_gradient_set(&mut self, gradient: Gradient, gradient_type: GradientType, spread_method: GradientSpreadMethod, transform: DAffine2) { let Some(fill_node_id) = self.existing_proto_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, true) else { return; }; @@ -563,7 +563,7 @@ impl<'a> ModifyInputsContext<'a> { } /// Write the gradient stops to the 'Gradient Value' node feeding the layer. - pub fn gradient_stops_set(&mut self, stops: GradientStops) { + pub fn gradient_stops_set(&mut self, stops: Gradient) { let Some(output_layer) = self.get_output_layer() else { return }; let gradient_value_id = match get_upstream_gradient_value_node_id(output_layer, self.network_interface) { diff --git a/editor/src/messages/portfolio/document/node_graph/node_properties.rs b/editor/src/messages/portfolio/document/node_graph/node_properties.rs index a8e2c7a491..596d1b6dc2 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_properties.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_properties.rs @@ -33,7 +33,7 @@ use graphene_std::transform::{Footprint, ReferencePoint, ScaleType, Transform}; use graphene_std::vector::misc::BooleanOperation; use graphene_std::vector::misc::{ArcType, CentroidType, ExtrudeJoiningAlgorithm, GridType, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns, SpiralType}; use graphene_std::vector::style::{ - FillChoice, FillChoiceUI, GradientSpreadMethod, GradientStops, GradientStopsUI, GradientType, PaintOrder, StrokeAlign, StrokeCap, StrokeJoin, build_transform_with_y_preservation, + FillChoice, FillChoiceUI, Gradient, GradientSpreadMethod, GradientType, GradientUI, PaintOrder, StrokeAlign, StrokeCap, StrokeJoin, build_transform_with_y_preservation, }; use graphene_std::vector::{QRCodeErrorCorrectionLevel, VectorModification}; @@ -254,11 +254,11 @@ pub(crate) fn property_from_type( // ========== Some(x) if x == TypeId::of::>() => array_of_number_widget(default_info, TextInput::default()).into(), Some(x) if x == TypeId::of::>() => color_widget(default_info, ColorInput::default().allow_none(true)), - Some(x) if x == TypeId::of::>() => color_widget(default_info, ColorInput::default().allow_none(false)), + Some(x) if x == TypeId::of::>() => color_widget(default_info, ColorInput::default().allow_none(false)), Some(x) if x == TypeId::of::>() => brush_strokes_widget(default_info).into(), // Leveled wires type by their element; each element keeps its list form's widget. Some(x) if x == TypeId::of::() => color_widget(default_info, ColorInput::default().allow_none(true)), - Some(x) if x == TypeId::of::() => color_widget(default_info, ColorInput::default().allow_none(false)), + Some(x) if x == TypeId::of::() => color_widget(default_info, ColorInput::default().allow_none(false)), Some(x) if x == TypeId::of::() => brush_strokes_widget(default_info).into(), // ============ // STRUCT TYPES @@ -1190,7 +1190,7 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button: color_button .value(FillChoiceUI::from(&FillChoice::Gradient(stops.clone()))) .on_update(update_value( - |input: &ColorInput| TaggedValue::Gradient(input.value.as_gradient().map(GradientStops::from).unwrap_or_default()), + |input: &ColorInput| TaggedValue::Gradient(input.value.as_gradient().map(Gradient::from).unwrap_or_default()), node_id, index, )) @@ -1267,8 +1267,8 @@ pub fn query_assign_colors_randomize(node_id: NodeId, context: &NodePropertiesCo } /// 2-stop black-to-white gradient track for spectrum sliders that map a value to a grayscale axis. -fn bw_track() -> GradientStops { - GradientStops { +fn bw_track() -> Gradient { + Gradient { position: vec![0., 1.], midpoint: vec![0.5, 0.5], color: vec![Color::BLACK, Color::WHITE], @@ -1276,8 +1276,8 @@ fn bw_track() -> GradientStops { } /// 3-stop black-to-color-to-white gradient track for spectrum sliders that map a value to a hue's full luminance range. -fn color_track(color: Color) -> GradientStops { - GradientStops { +fn color_track(color: Color) -> Gradient { + Gradient { position: vec![0., 0.5, 1.], midpoint: vec![0.5; 3], color: vec![Color::BLACK, color, Color::WHITE], @@ -1312,7 +1312,7 @@ pub(crate) fn brightness_contrast_properties(node_id: NodeId, context: &mut Node let contrast_min = if use_classic_value { -100. } else { -50. }; let zero_position = -contrast_min / (100. - contrast_min); - let contrast_track = GradientStops { + let contrast_track = Gradient { position: vec![0., zero_position, 1.], midpoint: vec![0.5; 3], color: vec![Color::from_rgbf32_unchecked(0.5, 0.5, 0.5), Color::BLACK, Color::from_rgbf32_unchecked(0.5, 0.5, 0.5)], @@ -1409,7 +1409,7 @@ fn build_shared_spectrum_section(node_id: NodeId, context: &mut NodePropertiesCo // Build the shared spectrum widget (placed on the first non-exposed row) let spectrum_widget = (!spectrum_markers.is_empty()).then(|| { - SpectrumInput::new(GradientStopsUI::from(&bw_track())) + SpectrumInput::new(GradientUI::from(&bw_track())) .markers(spectrum_markers) .show_midpoints(false) .allow_insert(false) @@ -1502,13 +1502,13 @@ pub(crate) fn hue_saturation_properties(node_id: NodeId, context: &mut NodePrope let saturated_current_hue = Color::from_hsva(marker_hue, 1., 1., 1.); // Hue: cyclic rainbow - let hue_track = GradientStops { + let hue_track = Gradient { position: vec![0., 1. / 6., 2. / 6., 3. / 6., 4. / 6., 5. / 6., 1.], midpoint: vec![0.5; 7], color: vec![Color::RED, Color::YELLOW, Color::GREEN, Color::CYAN, Color::BLUE, Color::MAGENTA, Color::RED], }; // Saturation: gray to the fully saturated current hue - let saturation_track = GradientStops { + let saturation_track = Gradient { position: vec![0., 1.], midpoint: vec![0.5, 0.5], color: vec![Color::from_rgbf32_unchecked(0.5, 0.5, 0.5), saturated_current_hue], @@ -1558,7 +1558,7 @@ fn spectrum_slider_row( node_id: NodeId, context: &mut NodePropertiesContext, input_index: usize, - track: GradientStops, + track: Gradient, handle_color: Color, value_min: f64, value_max: f64, @@ -1583,7 +1583,7 @@ fn spectrum_slider_row( let position_to_value = move |position: f64| value_min + position * value_range; row.push( - SpectrumInput::new(GradientStopsUI::from(&track)) + SpectrumInput::new(GradientUI::from(&track)) .markers(vec![SpectrumMarker::new(position, 0.5, handle_color)]) .show_midpoints(false) .allow_insert(false) @@ -1643,7 +1643,7 @@ pub(crate) fn threshold_properties(node_id: NodeId, context: &mut NodeProperties pub(crate) fn vibrance_properties(node_id: NodeId, context: &mut NodePropertiesContext) -> Vec { use graphene_std::raster::vibrance::*; - let track = GradientStops { + let track = Gradient { position: vec![0., 1.], midpoint: vec![0.5, 0.5], color: vec![Color::from_rgbf32_unchecked(0.5, 0.5, 0.5), Color::RED], @@ -2451,7 +2451,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte enum ResolvedFill { Solid(Option), Gradient { - gradient: GradientStops, + gradient: Gradient, gradient_type: GradientType, spread_method: GradientSpreadMethod, transform: DAffine2, @@ -2487,7 +2487,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte ResolvedFill::Other } } - Some(ty) if ty == &concrete!(List) => { + Some(ty) if ty == &concrete!(List) => { // Read this node's own inputs rather than the layer's nearest Fill, which may be a different node when Fills are chained if let Ok(document_node) = get_document_node(node_id, context) && let Some(gradient) = graph_modification_utils::read_fill_node_gradient(document_node, || { @@ -2515,11 +2515,11 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte }; let backup_stops = match document_node.inputs[BackupGradientInput::INDEX].as_value() { Some(TaggedValue::Gradient(stops)) => stops.clone(), - _ => GradientStops::default(), + _ => Gradient::default(), }; (backup_color, backup_stops) } - Err(_) => (None, GradientStops::default()), + Err(_) => (None, Gradient::default()), }; match &fill { @@ -2545,7 +2545,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte FillChoiceUI::None } } - ResolvedFill::Gradient { gradient: stops, .. } => FillChoiceUI::Gradient(GradientStopsUI::from(stops)), + ResolvedFill::Gradient { gradient: stops, .. } => FillChoiceUI::Gradient(GradientUI::from(stops)), ResolvedFill::Other => FillChoiceUI::None, }; @@ -2566,7 +2566,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte ]), }; - let gradient_set_messages = move |gradient: GradientStops| Message::Batched { + let gradient_set_messages = move |gradient: Gradient| Message::Batched { messages: Box::new([ NodeGraphMessage::SetInputValue { node_id, @@ -2594,7 +2594,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte solid_set_messages(color) } FillChoiceUI::Gradient(gradient_stops_ui) => { - let gradient = GradientStops::from(gradient_stops_ui); + let gradient = Gradient::from(gradient_stops_ui); gradient_set_messages(gradient) } }) diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index df2932ce85..a09e834164 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -32,6 +32,9 @@ const TEXT_REPLACEMENTS: &[(&str, &str)] = &[ ("\"OptionalF64\":", "\"F64\":"), ("\"path_bool_nodes::BooleanOperation\"", "\"vector_types::vector::misc::BooleanOperation\""), ("\"core_types::table::Table<", "\"core_types::list::List<"), + // The `GradientStops` type was renamed to `Gradient`; stale stored output names are cleared so the display falls back to the live type name + ("\"output_names\":[\"GradientStops\"]", "\"output_names\":[\"\"]"), + ("vector_types::gradient::GradientStops", "vector_types::gradient::Gradient"), ]; pub struct NodeReplacement<'a> { @@ -1622,21 +1625,21 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId], // Content: no change document.network_interface.set_input(&InputConnector::node(*node_id, 0), old_inputs[0].clone(), network_path); - // Fill: a literal Fill value is decomposed, and a wired input (`List / List`) is kept as-is + // Fill: a literal Fill value is decomposed, and a wired input (`List / List`) is kept as-is match old_inputs[1].as_value() { Some(TaggedValue::LegacyFill(old_fill)) => { let exposed = old_inputs[1].is_exposed(); let fill_value = match old_fill { - graphic_types::migrations::legacy::Fill::None => TaggedValue::Color(None), - graphic_types::migrations::legacy::Fill::Solid(color) => TaggedValue::Color(Some(*color)), - graphic_types::migrations::legacy::Fill::Gradient(gradient) => TaggedValue::Gradient(gradient.stops.clone()), + graphic_types::migrations::legacy::LegacyFill::None => TaggedValue::Color(None), + graphic_types::migrations::legacy::LegacyFill::Solid(color) => TaggedValue::Color(Some(*color)), + graphic_types::migrations::legacy::LegacyFill::Gradient(gradient) => TaggedValue::Gradient(gradient.stops.clone()), }; document .network_interface .set_input(&InputConnector::node(*node_id, 1), NodeInput::value(fill_value, exposed), network_path); // Gradient metadata (4, 5, 6): applies only to a literal gradient, solids/none keep the template defaults - if let graphic_types::migrations::legacy::Fill::Gradient(gradient) = old_fill { + if let graphic_types::migrations::legacy::LegacyFill::Gradient(gradient) = old_fill { document.network_interface.set_input( &InputConnector::node(*node_id, 4), NodeInput::value(TaggedValue::GradientType(gradient.gradient_type), false), @@ -1661,7 +1664,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId], } } // Wired/exposed fill keeps the connection. - // The generic paint connector accepts the existing `List`/`List` paint sources directly. + // The generic paint connector accepts the existing `List`/`List` paint sources directly. _ => { document.network_interface.set_input(&InputConnector::node(*node_id, 1), old_inputs[1].clone(), network_path); } @@ -1680,7 +1683,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId], if matches!( old_inputs[1].as_value(), Some(TaggedValue::LegacyFill( - graphic_types::migrations::legacy::Fill::None | graphic_types::migrations::legacy::Fill::Solid(_) + graphic_types::migrations::legacy::LegacyFill::None | graphic_types::migrations::legacy::LegacyFill::Solid(_) )) ) { document diff --git a/editor/src/messages/tool/common_functionality/graph_modification_utils.rs b/editor/src/messages/tool/common_functionality/graph_modification_utils.rs index 0f58b12710..c4ba053364 100644 --- a/editor/src/messages/tool/common_functionality/graph_modification_utils.rs +++ b/editor/src/messages/tool/common_functionality/graph_modification_utils.rs @@ -15,7 +15,7 @@ use graphene_std::subpath::Subpath; use graphene_std::text::{Font, TypesettingConfig}; use graphene_std::vector::misc::ManipulatorPointId; use graphene_std::vector::style::{FillChoice, PaintOrder, StrokeAlign, StrokeCap, StrokeJoin, initial_gradient_transform_for_bounding_box}; -use graphene_std::vector::{GradientSpreadMethod, GradientStops, GradientType, PointId, SegmentId, VectorModificationType}; +use graphene_std::vector::{Gradient, GradientSpreadMethod, GradientType, PointId, SegmentId, VectorModificationType}; use std::collections::VecDeque; /// Returns the ID of the first Spline node in the horizontal flow which is not followed by a `Path` node, or `None` if none exists. @@ -309,7 +309,7 @@ pub fn get_fill_input_node_id(layer: LayerNodeIdentifier, network_interface: &No } /// Get the gradient stops of a layer, if any. -pub fn get_gradient_stops(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option { +pub fn get_gradient_stops(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option { // Try to find the gradient stops value that is created by a Fill node first if let Some(fill_node_id) = get_fill_node_id_with_direct_fill_input(layer, network_interface) { return network_interface @@ -328,7 +328,7 @@ pub fn get_gradient_stops(layer: LayerNodeIdentifier, network_interface: &NodeNe Some(stops.clone()) } -/// Compute the transform from a gradient's local space to viewport space for the given layer. For a `List` +/// Compute the transform from a gradient's local space to viewport space for the given layer. For a `List` /// layer this is the layer's incoming footprint transform; for a Fill-owned gradient value it composes the layer's viewport /// transform with the [0,1]² → bounding-box mapping. pub fn gradient_space_transform(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> glam::DAffine2 { @@ -625,7 +625,7 @@ pub fn set_stroke_weight_for_selected_layers(weight: f64, document: &DocumentMes /// A Fill node's decoded gradient inputs, with the transform kept in its raw form (not yet baked into `start`/`end`). pub struct FillNodeGradient { - pub stops: GradientStops, + pub stops: Gradient, pub gradient_type: GradientType, pub spread_method: GradientSpreadMethod, pub transform: DAffine2, diff --git a/editor/src/messages/tool/tool_messages/gradient_tool.rs b/editor/src/messages/tool/tool_messages/gradient_tool.rs index c5a1749e74..c76179e1eb 100644 --- a/editor/src/messages/tool/tool_messages/gradient_tool.rs +++ b/editor/src/messages/tool/tool_messages/gradient_tool.rs @@ -16,7 +16,7 @@ use glam::DMat2; use graph_craft::document::value::TaggedValue; use graphene_std::color::SRGBA8; use graphene_std::raster::color::Color; -use graphene_std::vector::style::{FillChoice, FillChoiceUI, GradientSpreadMethod, GradientStop, GradientStops, GradientStopsUI, GradientType, build_transform_with_y_preservation}; +use graphene_std::vector::style::{FillChoice, FillChoiceUI, Gradient, GradientSpreadMethod, GradientStop, GradientType, GradientUI, build_transform_with_y_preservation}; #[derive(Default, ExtractField)] pub struct GradientTool { @@ -53,7 +53,7 @@ pub enum GradientToolMessage { CommitTransactionForColorStop, CloseStopColorPicker, UpdateStopColor { color: Color }, - UpdateStops { stops: GradientStopsUI }, + UpdateStops { stops: GradientUI }, UpdateOptions { options: GradientOptionsUpdate }, } @@ -146,7 +146,7 @@ impl<'a> MessageHandler> for Grad } } ToolMessage::Gradient(GradientToolMessage::UpdateStops { stops }) => { - apply_stops_update(&mut self.data, context, responses, GradientStops::from(&stops)); + apply_stops_update(&mut self.data, context, responses, Gradient::from(&stops)); } ToolMessage::Gradient(GradientToolMessage::CloseStopColorPicker) => { if self.data.color_picker_transaction_open { @@ -264,7 +264,7 @@ impl LayoutHolder for GradientTool { .or_else(|| self.data.default_gradient_stops.clone()) .map(FillChoice::Gradient) .unwrap_or_else(|| { - FillChoice::Gradient(GradientStops::new([ + FillChoice::Gradient(Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -389,7 +389,7 @@ enum GradientSource { } /// Get the gradient with appearance information from Fill node values, or the chain connected to Fill node / layer. -fn resolve_gradient(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<(GradientStops, GradientAppearance, GradientSource)> { +fn resolve_gradient(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<(Gradient, GradientAppearance, GradientSource)> { if let Some(stops) = get_gradient_stops(layer, network_interface) { // A Fill node holding a direct gradient value decodes through the shared reader if let Some(fill_id) = get_fill_node_id_with_direct_fill_input(layer, network_interface) { @@ -521,15 +521,15 @@ struct SelectedGradient { dragging: GradientDragTarget, /// Transform from the geometry's local gradient space to viewport space. gradient_space_transform: DAffine2, - gradient: GradientStops, + gradient: Gradient, appearance: GradientAppearance, - initial_gradient: GradientStops, + initial_gradient: Gradient, /// Transform from unit [0, 1] line to the geometry's local gradient space, the snapshot from `GradientAppearance.transform`. initial_gradient_transform: DAffine2, is_gradient_chain: bool, } -fn calculate_insertion(start: DVec2, end: DVec2, stops: &GradientStops, mouse: DVec2) -> Option { +fn calculate_insertion(start: DVec2, end: DVec2, stops: &Gradient, mouse: DVec2) -> Option { let distance = (end - start).angle_to(mouse - start).sin() * (mouse - start).length(); let projection = ((end - start).angle_to(mouse - start)).cos() * start.distance(mouse) / start.distance(end); @@ -568,7 +568,7 @@ fn calculate_insertion(start: DVec2, end: DVec2, stops: &GradientStops, mouse: D } impl SelectedGradient { - pub fn new(gradient: GradientStops, appearance: GradientAppearance, source: GradientSource, layer: LayerNodeIdentifier, document: &DocumentMessageHandler) -> Self { + pub fn new(gradient: Gradient, appearance: GradientAppearance, source: GradientSource, layer: LayerNodeIdentifier, document: &DocumentMessageHandler) -> Self { let gradient_space_transform = gradient_space_transform(layer, document); Self { layer: Some(layer), @@ -820,7 +820,7 @@ impl SelectedGradient { } /// Send the four per-attribute graph operations that mirror the in-memory `Gradient` onto the chain feeding the layer. -fn dispatch_gradient_chain_writes(layer: LayerNodeIdentifier, gradient: &GradientStops, appearance: GradientAppearance, responses: &mut VecDeque) { +fn dispatch_gradient_chain_writes(layer: LayerNodeIdentifier, gradient: &Gradient, appearance: GradientAppearance, responses: &mut VecDeque) { responses.add(GraphOperationMessage::GradientStopsSet { layer, stops: gradient.clone() }); responses.add(GraphOperationMessage::GradientTransformSet { layer, @@ -868,11 +868,11 @@ struct GradientToolData { has_selected_gradient: bool, /// Cached stops of the currently selected layer's gradient, mirrored into the control-bar widget. /// Independent of any in-progress drag (which uses `selected_gradient`) so it stays current after selection changes too. - current_gradient_stops: Option, + current_gradient_stops: Option, /// User-customized default gradient stop colors: used when nothing that has a gradient is selected. /// `None` means to follow the working colors. /// Cleared on tool deactivation so each fresh activation starts from the working colors again. - default_gradient_stops: Option, + default_gradient_stops: Option, /// Cached viewport-space orientation (true = predominantly rightward) of the selected gradient line. /// Used to refresh the control bar's "Reverse Direction" icon only when the line's apparent direction flips. gradient_orientation_rightward: bool, @@ -1496,7 +1496,7 @@ impl Fsm for GradientToolFsmState { // Generate a new gradient running primary → secondary so the default working colors // (primary = black, secondary = white) produce the expected black-to-white gradient None => ( - GradientStops::new([ + Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -1738,7 +1738,7 @@ impl Fsm for GradientToolFsmState { } } -fn insert_stop_at_point(gradient: &mut GradientStops, point: DVec2, unit_to_viewport: DAffine2) -> Option { +fn insert_stop_at_point(gradient: &mut Gradient, point: DVec2, unit_to_viewport: DAffine2) -> Option { let (start, end) = gradient_handle_positions(unit_to_viewport); let t = ((end - start).angle_to(point - start)).cos() * start.distance(point) / start.distance(end); (0. ..=1.).contains(&t).then(|| gradient.insert_stop(t)) @@ -1831,8 +1831,8 @@ fn apply_gradient_update( data: &mut GradientToolData, context: &mut ToolActionMessageContext, responses: &mut VecDeque, - condition: impl Fn((&GradientStops, &GradientAppearance)) -> bool, - update: impl Fn((&mut GradientStops, &mut GradientAppearance)), + condition: impl Fn((&Gradient, &GradientAppearance)) -> bool, + update: impl Fn((&mut Gradient, &mut GradientAppearance)), ) { let selected_layers: Vec<_> = context .document @@ -1888,7 +1888,7 @@ fn apply_gradient_update( /// Set new gradient stops on every selected layer's gradient. Unlike `apply_gradient_update`, this doesn't open its own /// transaction so it can be called repeatedly during a color picker drag and have all the changes coalesced into a /// single undo entry by the surrounding 'on_commit' callback. -fn apply_stops_update(data: &mut GradientToolData, context: &mut ToolActionMessageContext, responses: &mut VecDeque, new_gradient: GradientStops) { +fn apply_stops_update(data: &mut GradientToolData, context: &mut ToolActionMessageContext, responses: &mut VecDeque, new_gradient: Gradient) { let selected_layers: Vec<_> = context .document .network_interface @@ -1933,7 +1933,7 @@ fn apply_stops_update(data: &mut GradientToolData, context: &mut ToolActionMessa } /// Find the first selected visible layer that has a gradient and return both the layer ID and its resolved gradient. -fn current_layer_and_gradient(document: &DocumentMessageHandler) -> (Option, Option<(GradientStops, GradientAppearance)>) { +fn current_layer_and_gradient(document: &DocumentMessageHandler) -> (Option, Option<(Gradient, GradientAppearance)>) { for layer in document.network_interface.selected_nodes().selected_visible_layers(&document.network_interface) { if let Some((gradient, appearance, _source)) = resolve_gradient(layer, &document.network_interface) { return (Some(layer), Some((gradient, appearance))); @@ -1942,7 +1942,7 @@ fn current_layer_and_gradient(document: &DocumentMessageHandler) -> (Option Option<(GradientStops, GradientAppearance, GradientSource)> { +fn get_gradient_on_selected_layer(document: &DocumentMessageHandler) -> Option<(Gradient, GradientAppearance, GradientSource)> { document .network_interface .selected_nodes() @@ -2015,18 +2015,18 @@ mod test_gradient { use graphene_std::NodeInputDecleration; use graphene_std::color::SRGBA8; use graphene_std::vector::style::{GradientSpreadMethod, build_transform_with_y_preservation}; - use graphene_std::vector::{GradientStop, GradientStops, fill}; + use graphene_std::vector::{Gradient, GradientStop, fill}; use super::gradient_space_transform; struct ResolvedGradient { - stops: GradientStops, + stops: Gradient, spread_method: GradientSpreadMethod, transform: DAffine2, } impl ResolvedGradient { - fn new(stops: GradientStops, appearance: super::GradientAppearance) -> Self { + fn new(stops: Gradient, appearance: super::GradientAppearance) -> Self { Self { stops, spread_method: appearance.spread_method, @@ -2146,7 +2146,7 @@ mod test_gradient { .handle_message(NodeGraphMessage::SetInputValue { node_id: gradient_node_id, input_index: 1, - value: Box::new(TaggedValue::Gradient(GradientStops::new([ + value: Box::new(TaggedValue::Gradient(Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -2183,7 +2183,7 @@ mod test_gradient { .handle_message(NodeGraphMessage::SetInputValue { node_id: gradient_node_id, input_index: 1, - value: Box::new(TaggedValue::Gradient(GradientStops::new([ + value: Box::new(TaggedValue::Gradient(Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -2654,7 +2654,7 @@ mod test_gradient { // Create original transform for the control geometry and apply it let initial_start = DVec2::new(10., 50.); let initial_end = DVec2::new(200., 50.); - let stops = GradientStops::new([ + let stops = Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -2725,7 +2725,7 @@ mod test_gradient { let layer = create_gradient_list_layer(&mut editor).await; // Set up a 3-stop gradient with distinct colors - let original_stops = GradientStops::new([ + let original_stops = Gradient::new([ GradientStop { position: 0., midpoint: 0.5, @@ -2826,7 +2826,7 @@ mod test_gradient { .handle_message(NodeGraphMessage::SetInputValue { node_id: gradient_value_id, input_index: 1, - value: Box::new(TaggedValue::Gradient(GradientStops::new([ + value: Box::new(TaggedValue::Gradient(Gradient::new([ GradientStop { position: 0., midpoint: 0.5, diff --git a/editor/src/node_graph_executor.rs b/editor/src/node_graph_executor.rs index 8907e80c90..f7662e3836 100644 --- a/editor/src/node_graph_executor.rs +++ b/editor/src/node_graph_executor.rs @@ -84,7 +84,7 @@ struct ExecutionContext { /// Set when this execution is a gradient-migration measurement run, carrying the "Fill" node (addressed by its enclosing /// network path) and its original relative gradient. The evaluated geometry is read back from the inspect result to size the /// gradient; such runs never touch the visible artwork. Carrying the entry keeps a stale re-dispatched response paired with the fill it measured. - measure_fill: Option<(Vec, NodeId, graphic_types::migrations::legacy::Gradient)>, + measure_fill: Option<(Vec, NodeId, graphic_types::migrations::legacy::LegacyGradient)>, } // TODO: Eventually remove this document upgrade code @@ -94,7 +94,7 @@ struct ExecutionContext { #[derive(Debug, Clone)] struct GradientMigration { document_id: DocumentId, - remaining: VecDeque<(Vec, NodeId, graphic_types::migrations::legacy::Gradient)>, + remaining: VecDeque<(Vec, NodeId, graphic_types::migrations::legacy::LegacyGradient)>, resolution: UVec2, scale: f64, } @@ -507,7 +507,7 @@ impl NodeGraphExecutor { } // Snapshot the queue but leave `pending_gradient_bbox_bake` populated, so subsequent render requests keep deferring here (and hit the guard above); each entry is removed from the document as its bake lands. - let remaining: VecDeque<(Vec, NodeId, graphic_types::migrations::legacy::Gradient)> = document.pending_gradient_bbox_bake.iter().cloned().collect(); + let remaining: VecDeque<(Vec, NodeId, graphic_types::migrations::legacy::LegacyGradient)> = document.pending_gradient_bbox_bake.iter().cloned().collect(); let Some((first_network_path, first_fill, first_gradient)) = remaining.front().cloned() else { return false; }; @@ -534,7 +534,7 @@ impl NodeGraphExecutor { document_id: DocumentId, network_path: Vec, fill_node_id: NodeId, - gradient: graphic_types::migrations::legacy::Gradient, + gradient: graphic_types::migrations::legacy::LegacyGradient, resolution: UVec2, scale: f64, responses: &mut VecDeque, @@ -603,7 +603,7 @@ impl NodeGraphExecutor { &mut self, document: &mut DocumentMessageHandler, document_id: DocumentId, - bake_target: (Vec, NodeId, graphic_types::migrations::legacy::Gradient), + bake_target: (Vec, NodeId, graphic_types::migrations::legacy::LegacyGradient), inspect_result: Option, responses: &mut VecDeque, ) { diff --git a/frontend/src/components/widgets/inputs/ColorInput.svelte b/frontend/src/components/widgets/inputs/ColorInput.svelte index ba0896d801..d2c9306e76 100644 --- a/frontend/src/components/widgets/inputs/ColorInput.svelte +++ b/frontend/src/components/widgets/inputs/ColorInput.svelte @@ -2,7 +2,7 @@ import { createEventDispatcher } from "svelte"; import ColorPicker from "/src/components/floating-menus/ColorPicker.svelte"; import LayoutCol from "/src/components/layout/LayoutCol.svelte"; - import { contrastingOutlineFactor, fillChoiceUIColor, fillChoiceUIGradientStops } from "/src/utility-functions/colors"; + import { contrastingOutlineFactor, fillChoiceUIColor, fillChoiceUIGradient } from "/src/utility-functions/colors"; import type { FillChoiceUI, MenuDirection, ActionShortcut } from "/wrapper/pkg/graphite_wasm_wrapper"; const dispatch = createEventDispatcher<{ value: FillChoiceUI; startHistoryTransaction: undefined }>(); @@ -29,10 +29,10 @@ $: outlineFactor = contrastingOutlineFactor(value, "--color-3-darkgray", 0.01); $: outlined = outlineFactor > 0.0001; - $: gradientStops = fillChoiceUIGradientStops(value); + $: gradient = fillChoiceUIGradient(value); $: solidColor = fillChoiceUIColor(value); $: none = value === "None"; - $: transparency = gradientStops ? gradientStops.color.some((color) => color.alpha < 255) : solidColor ? solidColor.alpha < 255 : false; + $: transparency = gradient ? gradient.color.some((color) => color.alpha < 255) : solidColor ? solidColor.alpha < 255 : false; ), - /// Stored compactly as a `GradientStops`, materializes as a single-row `List` at runtime via `to_dynany`/`to_any`. Aliases recover legacy on-disk shapes. + /// Stored compactly as a `Gradient`, materializes as a single-row `List` at runtime via `to_dynany`/`to_any`. Aliases recover legacy on-disk shapes. /// (Old documents that stored a full `Gradient` struct under this same `"Gradient"` tag are routed to `LegacyGradient` by `deserialize_tagged_value_with_legacy_migration`.) - #[serde(deserialize_with = "graphic_types::vector_types::gradient::migrate_to_gradient_stops")] // TODO: Eventually remove this migration document upgrade code + #[serde(deserialize_with = "graphic_types::vector_types::gradient::migrate_to_gradient")] // TODO: Eventually remove this migration document upgrade code #[serde(alias = "GradientTable", alias = "GradientPositions", alias = "GradientStops")] - Gradient(GradientStops), + Gradient(Gradient), /// Stored compactly as a `Vec`, materializes as `List` at runtime via `to_dynany`/`to_any`. Aliases recover legacy on-disk shapes. #[serde(deserialize_with = "brush_nodes::migrations::migrate_to_brush_strokes")] // TODO: Eventually remove this migration document upgrade code #[serde(alias = "BrushStrokeTable")] @@ -160,7 +160,7 @@ macro_rules! tagged_value { let list: List = color.into_iter().map(core_types::list::Item::new_from_element).collect(); Box::new(list) } - Self::Gradient(stops) => Box::new(List::::new_from_element(stops)), + Self::Gradient(stops) => Box::new(List::::new_from_element(stops)), Self::BrushStrokes(strokes) => { let list: List = strokes.into_iter().map(core_types::list::Item::new_from_element).collect(); Box::new(list) @@ -207,7 +207,7 @@ macro_rules! tagged_value { let list: List = color.into_iter().map(core_types::list::Item::new_from_element).collect(); Arc::new(list) } - Self::Gradient(stops) => Arc::new(List::::new_from_element(stops)), + Self::Gradient(stops) => Arc::new(List::::new_from_element(stops)), Self::BrushStrokes(strokes) => { let list: List = strokes.into_iter().map(core_types::list::Item::new_from_element).collect(); Arc::new(list) @@ -248,7 +248,7 @@ macro_rules! tagged_value { } Self::F64Array(_) => concrete!(f64), Self::Color(_) => concrete!(Color), - Self::Gradient(_) => concrete!(GradientStops), + Self::Gradient(_) => concrete!(Gradient), Self::BrushStrokes(_) => concrete!(BrushStroke), // ======================= // AUTO-GENERATED VARIANTS @@ -297,7 +297,7 @@ macro_rules! tagged_value { } Self::F64Array(_) => leveled::(), Self::Color(_) => leveled::(), - Self::Gradient(_) => leveled::(), + Self::Gradient(_) => leveled::(), Self::BrushStrokes(_) => leveled::(), $( Self::$identifier(_) => scalar::<$ty>(), )* Self::RenderOutput(_) => scalar::(), @@ -443,14 +443,14 @@ macro_rules! tagged_value { if name == core_types::normalize_type_name(std::any::type_name::<()>()) { return Some(TaggedValue::None) } // List-wrapped types need a single-item default with the element's default, not an empty list if name == core_types::normalize_type_name(std::any::type_name::>()) { return Some(TaggedValue::Color(Some(Color::default()))) } - if name == core_types::normalize_type_name(std::any::type_name::>()) { return Some(TaggedValue::Gradient(GradientStops::default())) } + if name == core_types::normalize_type_name(std::any::type_name::>()) { return Some(TaggedValue::Gradient(Gradient::default())) } $( if name == core_types::normalize_type_name(std::any::type_name::<$ty>()) { return Some(TaggedValue::$identifier(Default::default())) } )* if name == core_types::normalize_type_name(std::any::type_name::>()) { return Some(TaggedValue::F64Array(Vec::new())) } if name == core_types::normalize_type_name(std::any::type_name::>()) { return Some(TaggedValue::BrushStrokes(Vec::new())) } // Leveled inputs type by their element; each element name maps to the // same tagged default as its legacy list form. if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::Color(Some(Color::default()))) } - if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::Gradient(GradientStops::default())) } + if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::Gradient(Gradient::default())) } if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::BrushStrokes(Vec::new())) } if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::TypeDefault(core_types::descriptor!(List))) } if name == core_types::normalize_type_name(std::any::type_name::()) { return Some(TaggedValue::TypeDefault(core_types::descriptor!(List))) } @@ -540,7 +540,7 @@ tagged_value! { DAffine2(DAffine2), OptionalDAffine2(Option), #[serde(alias = "FillGradient")] - LegacyGradient(graphic_types::migrations::legacy::Gradient), + LegacyGradient(graphic_types::migrations::legacy::LegacyGradient), Font(Font), Footprint(Footprint), VectorModification(Box), @@ -550,7 +550,7 @@ tagged_value! { // ENUM TYPES // ========== #[serde(alias = "Fill")] - LegacyFill(graphic_types::migrations::legacy::Fill), + LegacyFill(graphic_types::migrations::legacy::LegacyFill), BlendMode(core_types::blending::BlendMode), LuminanceCalculation(raster_nodes::adjustments::LuminanceCalculation), QRCodeErrorCorrectionLevel(vector_nodes::generator_nodes::QRCodeErrorCorrectionLevel), @@ -648,11 +648,11 @@ impl TaggedValue { None } - fn to_gradient(input: &str) -> Option { + fn to_gradient(input: &str) -> Option { // String syntax: (e.g. "000000ff, ff0000ff") let stops = input.split(',').filter_map(|s| to_color(s.trim())).collect::>(); if stops.len() == 1 { - Some(GradientStops::new(vec![ + Some(Gradient::new(vec![ GradientStop { position: 0., midpoint: 0.5, @@ -666,7 +666,7 @@ impl TaggedValue { ])) } else if stops.len() >= 2 { let step = 1. / (stops.len() - 1) as f64; - Some(GradientStops::new(stops.into_iter().enumerate().map(|(i, color)| GradientStop { + Some(Gradient::new(stops.into_iter().enumerate().map(|(i, color)| GradientStop { position: i as f64 * step, midpoint: 0.5, color, @@ -726,7 +726,7 @@ impl TaggedValue { () if ty == TypeId::of::>() => to_color(string).map(|color| TaggedValue::Color(Some(color)))?, // The Fill and Stroke nodes' paint connectors default to `List`, their first registered implementation row () if ty == TypeId::of::>() => to_color(string).map(|color| TaggedValue::Color(Some(color)))?, - () if ty == TypeId::of::>() => to_gradient(string).map(TaggedValue::Gradient)?, + () if ty == TypeId::of::>() => to_gradient(string).map(TaggedValue::Gradient)?, () if ty == TypeId::of::() => to_reference_point(string).map(TaggedValue::ReferencePoint)?, _ => return None, }; @@ -794,10 +794,10 @@ pub fn deserialize_tagged_value_with_legacy_migration<'de, D: serde::Deserialize } return Ok(MemoHash::new(TaggedValue::TypeDefault(descriptor!(List)))); } - // The `Gradient` tag was reused: it used to carry a full `Gradient` struct (now `LegacyGradient`), and now carries an `Option`. - // Disambiguate by payload shape: a Gradient struct has `start`/`end` keys; a `GradientStops` has none of those (it has `position`/`midpoint`/`color`). + // The `Gradient` tag was reused: it used to carry a full `Gradient` struct (now `LegacyGradient`), and now carries an `Option`. + // Disambiguate by payload shape: a Gradient struct has `start`/`end` keys; a `Gradient` has none of those (it has `position`/`midpoint`/`color`). "Gradient" if content.as_object().is_some_and(|c| c.contains_key("start") && c.contains_key("end")) => { - let gradient: graphic_types::migrations::legacy::Gradient = serde_json::from_value(content.clone()).map_err(serde::de::Error::custom)?; + let gradient: graphic_types::migrations::legacy::LegacyGradient = serde_json::from_value(content.clone()).map_err(serde::de::Error::custom)?; return Ok(MemoHash::new(TaggedValue::LegacyGradient(gradient))); } _ => {} diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 283a47aea0..f5090290c1 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -140,7 +140,7 @@ fn node_registry() -> HashMap> { "List>", "List>", "List", - "List", + "List", "List", ]) .map(|(entry, target)| (ProtoNodeIdentifier::with_owned_string(format!("graphene_core::ops::ConvertNode<{target}>")), entry)), diff --git a/node-graph/libraries/core-types/src/bounds.rs b/node-graph/libraries/core-types/src/bounds.rs index 517347c1e9..68f0e7756d 100644 --- a/node-graph/libraries/core-types/src/bounds.rs +++ b/node-graph/libraries/core-types/src/bounds.rs @@ -16,7 +16,7 @@ pub trait BoundingBox { /// Returns the bounding box to use when sizing this value's thumbnail in the Layers panel. /// /// Diverges from `bounding_box` for types where the rendering bounds wouldn't make a useful thumbnail frame. - /// For instance, `GradientStops` is `Infinite` for rendering but returns the line's AABB here, so a `List` + /// For instance, `Gradient` is `Infinite` for rendering but returns the line's AABB here, so a `List` /// group of a gradient and a vector frames around the vector's geometry rather than infinity. /// Types with no meaningful contribution (e.g., `Color`) return `Infinite` from both; the runtime substitutes a /// small fallback rectangle at the end if no finite bounds remain after combining. diff --git a/node-graph/libraries/graphic-types/src/boundary.rs b/node-graph/libraries/graphic-types/src/boundary.rs index ca53dc2157..990e530904 100644 --- a/node-graph/libraries/graphic-types/src/boundary.rs +++ b/node-graph/libraries/graphic-types/src/boundary.rs @@ -13,7 +13,7 @@ use core_types::node::Node; use core_types::record::{Group, GroupItem, LevelStatus, materialize_level}; use core_types::uuid::NodeId; use glam::{DAffine2, DVec2}; -use vector_types::GradientStops; +use vector_types::Gradient; /// The outcome of materializing a leveled wire into a group. // The group is the render path's success payload; boxing it would add a heap allocation per materialized level. @@ -93,7 +93,7 @@ pub fn batch_to_legacy(layout: &core_types::record::Layout, batch: core_types::n .or_else(|| typed::>(&item)) .or_else(|| typed::>(&item)) .or_else(|| typed::(&item)) - .or_else(|| typed::(&item)) + .or_else(|| typed::(&item)) .or_else(|| typed::(&item)) .or_else(|| typed::(&item)) .or_else(|| typed::(&item)) diff --git a/node-graph/libraries/graphic-types/src/graphic/legacy.rs b/node-graph/libraries/graphic-types/src/graphic/legacy.rs index 50a2578153..057a2d10a1 100644 --- a/node-graph/libraries/graphic-types/src/graphic/legacy.rs +++ b/node-graph/libraries/graphic-types/src/graphic/legacy.rs @@ -6,7 +6,7 @@ use crate::markers::{ATTR_FILL, ATTR_STROKE}; use core_types::Color; use core_types::list::{Item, List}; use raster_types::{CPU, GPU, Raster}; -use vector_types::{GradientStops, Vector}; +use vector_types::{Gradient, Vector}; /// One typed run as an owned list, elements cloned and every attribute copied /// through its erased read. Content keeps its native form; the legacy @@ -69,7 +69,7 @@ pub fn group_to_legacy_graphic(group: &core_types::record::Group) -> Graphic<'st .or_else(|| run_to_legacy_list::>(item).map(|list| detable_items(list, Graphic::RasterCPU))) .or_else(|| run_to_legacy_list::>(item).map(|list| detable_items(list, Graphic::RasterGPU))) .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Color))) - .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Gradient))) + .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Gradient))) .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Text))); if let Some(typed) = typed { return Graphic::Graphic(typed); @@ -93,7 +93,7 @@ pub fn group_to_legacy_list(group: &core_types::record::Group) -> List>(item).map(|list| detable_items(list, Graphic::RasterCPU))) .or_else(|| run_to_legacy_list::>(item).map(|list| detable_items(list, Graphic::RasterGPU))) .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Color))) - .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Gradient))) + .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Gradient))) .or_else(|| run_to_legacy_list::(item).map(|list| detable_items(list, Graphic::Text))) .unwrap_or_default() } diff --git a/node-graph/libraries/graphic-types/src/graphic/mod.rs b/node-graph/libraries/graphic-types/src/graphic/mod.rs index f05631539e..e29046f33a 100644 --- a/node-graph/libraries/graphic-types/src/graphic/mod.rs +++ b/node-graph/libraries/graphic-types/src/graphic/mod.rs @@ -24,7 +24,7 @@ use core_types::{ATTR_CLIPPING_MASK, ATTR_EDITOR_LAYER_PATH, ATTR_OPACITY, ATTR_ use dyn_any::DynAny; use glam::{DAffine2, DVec2}; use raster_types::{CPU, GPU, Raster}; -use vector_types::GradientStops; +use vector_types::Gradient; pub use vector_types::Vector; /// The possible forms of graphical content that can be rendered by the Render node into either an image or SVG syntax. @@ -38,7 +38,7 @@ pub enum Graphic<'e> { RasterCPU(Raster), RasterGPU(Raster), Color(Color), - Gradient(GradientStops), + Gradient(Gradient), Text(String), Group(core_types::record::Group<'e>), } @@ -101,7 +101,7 @@ into_graphic_element! { RasterCPU: Raster; RasterGPU: Raster; Color: Color; - Gradient: GradientStops; + Gradient: Gradient; Text: String; } @@ -146,9 +146,9 @@ impl From for Graphic<'_> { } // Note: List -> Option is in gcore (Color is defined there) -// GradientStops -impl From for Graphic<'_> { - fn from(gradient: GradientStops) -> Self { +// Gradient +impl From for Graphic<'_> { + fn from(gradient: Gradient) -> Self { Graphic::Gradient(gradient) } } @@ -251,7 +251,7 @@ impl TryFromGraphic for Color { } } -impl TryFromGraphic for GradientStops { +impl TryFromGraphic for Gradient { fn try_from_graphic(graphic: Graphic) -> Option> { if let Graphic::Gradient(t) = graphic { Some(List::new_from_element(t)) } else { None } } @@ -306,7 +306,7 @@ impl IntoGraphicList for List { } } -impl IntoGraphicList for List { +impl IntoGraphicList for List { fn into_graphic_list(self) -> List> { detable_items(self, Graphic::Gradient) } @@ -612,7 +612,7 @@ mod graphic_is_opaque_tests { Graphic::Color(color) } - fn gradient_graphic(gradient: GradientStops) -> Graphic<'static> { + fn gradient_graphic(gradient: Gradient) -> Graphic<'static> { Graphic::Gradient(gradient) } @@ -638,7 +638,7 @@ mod graphic_is_opaque_tests { fn gradient_with_all_opaque_stops_is_opaque() { let color_1 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap(); let color_2 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap(); - let gradient = GradientStops::new(vec![ + let gradient = Gradient::new(vec![ GradientStop { position: 0., midpoint: 0.5, @@ -658,7 +658,7 @@ mod graphic_is_opaque_tests { fn gradient_with_transparent_stop_is_not_opaque() { let color_1 = Color::from_rgbaf32(1., 0., 0., 0.5).unwrap(); let color_2 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap(); - let gradient = GradientStops::new(vec![ + let gradient = Gradient::new(vec![ GradientStop { position: 0., midpoint: 0.5, diff --git a/node-graph/libraries/graphic-types/src/graphic/walk.rs b/node-graph/libraries/graphic-types/src/graphic/walk.rs index bffb4be056..2230c2caed 100644 --- a/node-graph/libraries/graphic-types/src/graphic/walk.rs +++ b/node-graph/libraries/graphic-types/src/graphic/walk.rs @@ -13,7 +13,7 @@ use core_types::uuid::NodeId; use core_types::{ATTR_EDITOR_LAYER_PATH, ATTR_OPACITY, ATTR_OPACITY_FILL, ATTR_TRANSFORM, Color}; use glam::{DAffine2, DVec2}; use raster_types::{CPU, GPU, Raster}; -use vector_types::{GradientStops, Vector}; +use vector_types::{Gradient, Vector}; /// One run's attribute tokens, minted once so the lane loops read at an offset. struct RunAttrs { @@ -117,7 +117,7 @@ pub(in crate::graphic) fn group_bounding_box(group: &core_types::record::Group, .or_else(|| typed_run::>(item, transform, include_stroke, thumbnail)) .or_else(|| typed_run::>(item, transform, include_stroke, thumbnail)) .or_else(|| typed_run::(item, transform, include_stroke, thumbnail)) - .or_else(|| typed_run::(item, transform, include_stroke, thumbnail)) + .or_else(|| typed_run::(item, transform, include_stroke, thumbnail)) .or_else(|| typed_run::(item, transform, include_stroke, thumbnail)) .unwrap_or(RenderBoundingBox::Infinite) } @@ -497,7 +497,7 @@ pub(in crate::graphic) fn group_render_complexity(group: &core_types::record::Gr .or_else(|| typed_run::>(item)) .or_else(|| typed_run::>(item)) .or_else(|| typed_run::(item)) - .or_else(|| typed_run::(item)) + .or_else(|| typed_run::(item)) .or_else(|| typed_run::(item)) .unwrap_or(item.len()) } diff --git a/node-graph/libraries/graphic-types/src/lib.rs b/node-graph/libraries/graphic-types/src/lib.rs index 8d920b6a05..d5e00f2619 100644 --- a/node-graph/libraries/graphic-types/src/lib.rs +++ b/node-graph/libraries/graphic-types/src/lib.rs @@ -23,11 +23,11 @@ pub mod migrations { use dyn_any::DynAny; use glam::{DAffine2, DVec2}; use vector_types::vector::{PointDomain, RegionDomain, SegmentDomain, misc::HandleId, style::Stroke}; - use vector_types::{GradientStops, Vector, vector}; + use vector_types::{Gradient, Vector, vector}; #[derive(Default, Debug, Clone, PartialEq, graphene_hash::CacheHash, DynAny, serde::Serialize, serde::Deserialize)] - pub struct Gradient { - pub stops: GradientStops, + pub struct LegacyGradient { + pub stops: Gradient, pub gradient_type: vector::style::GradientType, pub start: DVec2, pub end: DVec2, @@ -39,11 +39,11 @@ pub mod migrations { pub transform: DAffine2, } - impl Gradient { + impl LegacyGradient { /// Converts a legacy bounding-box-relative gradient (`start`/`end` in [0,1]) into an absolute one in the geometry's local space. /// `bounding_box` maps [0,1] onto the geometry's bounding box; `layer_transform` is the layer's own transform, /// used to bake the elliptical adjustment that reproduces the legacy isotropic radial through a non-uniform layer. - pub fn to_absolute(&self, bounding_box: DAffine2, layer_transform: DAffine2) -> Gradient { + pub fn to_absolute(&self, bounding_box: DAffine2, layer_transform: DAffine2) -> LegacyGradient { let start = bounding_box.transform_point2(self.start); let end = bounding_box.transform_point2(self.end); let direction = end - start; @@ -66,7 +66,7 @@ pub mod migrations { DAffine2::IDENTITY }; - Gradient { + LegacyGradient { start, end, transform, @@ -83,15 +83,15 @@ pub mod migrations { } #[derive(Default, Debug, Clone, PartialEq, graphene_hash::CacheHash, DynAny, serde::Serialize, serde::Deserialize)] - pub enum Fill { + pub enum LegacyFill { #[default] None, Solid(Color), - Gradient(Gradient), + Gradient(LegacyGradient), } /// The legacy `fill` field is intentionally omitted because vector payload migration only - /// recovers editable vector data. The fill/stroke paints are migrated from the the node inputs. + /// recovers editable vector data. The fill/stroke paints are migrated from the node inputs. #[derive(serde::Deserialize)] #[cfg_attr(test, derive(Default, serde::Serialize))] pub(super) struct PathStyle { @@ -165,7 +165,7 @@ pub mod migrations { .unwrap() .as_object_mut() .unwrap() - .insert("fill".into(), serde_json::to_value(legacy::Fill::default()).unwrap()); + .insert("fill".into(), serde_json::to_value(legacy::LegacyFill::default()).unwrap()); let migrated = migrate_to_optional_vector(value).unwrap().unwrap(); assert_eq!(migrated.stroke.unwrap().weight, 12.); diff --git a/node-graph/libraries/rendering/src/render_ext.rs b/node-graph/libraries/rendering/src/render_ext.rs index 74da9ddcb3..ca50b373c9 100644 --- a/node-graph/libraries/rendering/src/render_ext.rs +++ b/node-graph/libraries/rendering/src/render_ext.rs @@ -11,7 +11,7 @@ use graphic_types::vector_types::gradient::GradientType; use graphic_types::vector_types::markers::{GradientType as GradientTypeAttr, SpreadMethod}; use graphic_types::vector_types::vector::style::{PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin}; use std::fmt::Write; -use vector_types::GradientStops; +use vector_types::Gradient; use vector_types::gradient::GradientSpreadMethod; #[derive(Copy, Clone, PartialEq)] @@ -83,7 +83,7 @@ impl RenderExt for List { } } -impl RenderExt for List { +impl RenderExt for List { type Output = u64; /// Adds the gradient def through mutating the first argument, returning the gradient ID. @@ -103,7 +103,7 @@ impl RenderExt for List { /// Adds the gradient def through mutating `svg_defs`, returning the gradient /// ID, over any gradient lane source. -pub fn render_gradient_paint>(source: &S, svg_defs: &mut String, item_transform: DAffine2, element_transform: DAffine2) -> u64 { +pub fn render_gradient_paint>(source: &S, svg_defs: &mut String, item_transform: DAffine2, element_transform: DAffine2) -> u64 { let mut stop = String::new(); { diff --git a/node-graph/libraries/rendering/src/renderer.rs b/node-graph/libraries/rendering/src/renderer.rs index 7a04057534..7859397485 100644 --- a/node-graph/libraries/rendering/src/renderer.rs +++ b/node-graph/libraries/rendering/src/renderer.rs @@ -26,7 +26,7 @@ use graphene_resource::Resource; use graphic_types::graphic::{PaintColumns, PaintOverlay, PaintReach, has_paint, is_paint_present, paint_graphics, set_paint_attribute, vector_can_reduce_to_clip_path}; use graphic_types::markers::{EditorMergedLayers, Fill, Stroke}; use graphic_types::raster_types::{BitmapMut, CPU, GPU, Image, Raster, Texture}; -use graphic_types::vector_types::gradient::{GradientStops, GradientType}; +use graphic_types::vector_types::gradient::{Gradient, GradientType}; use graphic_types::vector_types::markers::{GradientType as GradientTypeAttr, SpreadMethod}; use graphic_types::vector_types::subpath::Subpath; use graphic_types::vector_types::vector::click_target::{ClickTarget, FreePoint}; @@ -400,7 +400,7 @@ pub(crate) fn gradient_placement(transform: DAffine2, gradient_type: GradientTyp } } -fn create_peniko_gradient_brush>(gradient_list: &S, multiplied_transform: &DAffine2) -> Option<(peniko::Brush, DAffine2)> { +fn create_peniko_gradient_brush>(gradient_list: &S, multiplied_transform: &DAffine2) -> Option<(peniko::Brush, DAffine2)> { let stops = gradient_list.element(0)?; let gradient_type: GradientType = gradient_list.attr::(0); @@ -694,7 +694,7 @@ fn collect_group_row_metadata(group: &Group, metadata: &mut RenderMetadata, elem .or_else(|| lane_zero_transform::>(item)) .or_else(|| lane_zero_transform::>(item)) .or_else(|| lane_zero_transform::(item)) - .or_else(|| lane_zero_transform::(item)) + .or_else(|| lane_zero_transform::(item)) .or_else(|| lane_zero_transform::(item)); if let Some(transform) = transform { metadata.local_transforms.insert(element_id, transform); @@ -741,7 +741,7 @@ fn render_group_svg<'a>(group: &'a Group, reach: PaintReach<'a>, render: &mut Sv } else if item.typed_lanes::>().is_some() { } else if let Some(run) = RunView::::new(item) { render_color_svg(&run, render, render_params) - } else if let Some(run) = RunView::::new(item) { + } else if let Some(run) = RunView::::new(item) { render_gradient_svg(&run, render, render_params) } else if let Some(run) = RunView::::new(item) { render_text_svg(&run, render, render_params) @@ -763,7 +763,7 @@ fn render_group_vello<'a>(group: &'a Group, reach: PaintReach<'a>, scene: &mut S render_raster_gpu_vello(&run, scene, transform, context, render_params) } else if let Some(run) = RunView::::new(item) { render_color_vello(&run, scene, render_params) - } else if let Some(run) = RunView::::new(item) { + } else if let Some(run) = RunView::::new(item) { render_gradient_vello(&run, scene, transform, render_params) } else if let Some(run) = RunView::::new(item) { render_text_vello(&run, scene, transform, render_params) @@ -786,7 +786,7 @@ fn collect_group_metadata<'a>(group: &'a Group, reach: PaintReach<'a>, metadata: collect_raster_metadata(&run, metadata, footprint, element_id) } else if let Some(run) = RunView::>::new(item) { collect_raster_metadata(&run, metadata, footprint, element_id) - } else if item.typed_lanes::().is_some() || item.typed_lanes::().is_some() { + } else if item.typed_lanes::().is_some() || item.typed_lanes::().is_some() { } else if let Some(run) = RunView::::new(item) { collect_text_metadata(&run, metadata, footprint, element_id) } @@ -2282,7 +2282,7 @@ impl Render for List { } } -fn render_gradient_svg>(source: &S, render: &mut SvgRender, render_params: &RenderParams) { +fn render_gradient_svg>(source: &S, render: &mut SvgRender, render_params: &RenderParams) { // For thumbnails the gradient fills a finite rect at the footprint's document space bounds, with a 1-unit margin to cover the `as u32` truncation of `Footprint::resolution`. // The viewBox crops the overshoot. Canvas rendering keeps the polyline path since Chrome rejects rects larger than ~20 million. let thumbnail_rect = if render_params.thumbnail { @@ -2374,7 +2374,7 @@ fn render_gradient_svg>(source: &S, rende } } -fn render_gradient_vello>(source: &S, scene: &mut Scene, parent_transform: DAffine2, render_params: &RenderParams) { +fn render_gradient_vello>(source: &S, scene: &mut Scene, parent_transform: DAffine2, render_params: &RenderParams) { use vello::peniko; if let RenderMode::Outline = render_params.render_mode { @@ -2458,7 +2458,7 @@ fn render_gradient_vello>(source: &S, sce } } -impl Render for List { +impl Render for List { fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) { render_gradient_svg(self, render, render_params) } @@ -2926,7 +2926,7 @@ impl Render for RunView<'_, Color> { } } -impl Render for RunView<'_, GradientStops> { +impl Render for RunView<'_, Gradient> { fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) { render_gradient_svg(self, render, render_params) } diff --git a/node-graph/libraries/vector-types/src/gradient.rs b/node-graph/libraries/vector-types/src/gradient.rs index 00dc7ea9d6..0a9807d0aa 100644 --- a/node-graph/libraries/vector-types/src/gradient.rs +++ b/node-graph/libraries/vector-types/src/gradient.rs @@ -17,10 +17,10 @@ pub enum GradientType { // TODO: Someday we could switch this to a Box[T] to avoid over-allocation /// A list of colors (linear, unassociated alpha) associated with positions (in the range 0 to 1) along a gradient. /// -/// Not exposed via Tsify; use [`GradientStopsUI`] at the JS boundary. +/// Not exposed via Tsify; use [`GradientUI`] at the JS boundary. #[derive(Debug, Clone, PartialEq, graphene_hash::CacheHash, DynAny)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] -pub struct GradientStops { +pub struct Gradient { /// The position of this stop, a factor from 0-1 along the length of the full gradient. pub position: Vec, /// The midpoint to the right of this stop, a factor from 0-1 along the distance to the next stop. The final stop's midpoint is ignored. @@ -29,18 +29,18 @@ pub struct GradientStops { pub color: Vec, } -/// JS-boundary version of [`GradientStops`] where stop colors are [`SRGBA8`] byte triples instead of linear-light [`Color`]. +/// JS-boundary version of [`Gradient`] where stop colors are [`SRGBA8`] byte triples instead of linear-light [`Color`]. #[cfg_attr(feature = "wasm", derive(tsify::Tsify), tsify(from_wasm_abi))] #[derive(Debug, Clone, PartialEq, Default, DynAny)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct GradientStopsUI { +pub struct GradientUI { pub position: Vec, pub midpoint: Vec, pub color: Vec, } -impl From<&GradientStops> for GradientStopsUI { - fn from(s: &GradientStops) -> Self { +impl From<&Gradient> for GradientUI { + fn from(s: &Gradient) -> Self { Self { position: s.position.clone(), midpoint: s.midpoint.clone(), @@ -49,8 +49,8 @@ impl From<&GradientStops> for GradientStopsUI { } } -impl From<&GradientStopsUI> for GradientStops { - fn from(s: &GradientStopsUI) -> Self { +impl From<&GradientUI> for Gradient { + fn from(s: &GradientUI) -> Self { Self { position: s.position.clone(), midpoint: s.midpoint.clone(), @@ -59,7 +59,7 @@ impl From<&GradientStopsUI> for GradientStops { } } -impl GradientStopsUI { +impl GradientUI { /// CSS `linear-gradient(...)` string. Stops are emitted as `#rrggbbaa` hex (already gamma-encoded bytes). pub fn to_css_linear_gradient(&self) -> String { if self.position.len() <= 1 { @@ -67,7 +67,7 @@ impl GradientStopsUI { return format!("linear-gradient(to right, #{hex} 0%, #{hex} 100%)"); } // Sample via the midpoint-aware subdivision used for SVG/Vello stops so browser interpolation matches - let stops: GradientStops = self.into(); + let stops: Gradient = self.into(); let pieces = stops .interpolated_samples() .into_iter() @@ -83,7 +83,7 @@ impl GradientStopsUI { } // TODO: Eventually remove this migration document upgrade code -impl<'de> serde::Deserialize<'de> for GradientStops { +impl<'de> serde::Deserialize<'de> for Gradient { fn deserialize>(deserializer: D) -> Result { #[derive(serde::Deserialize)] struct NewFormat { @@ -117,7 +117,7 @@ impl<'de> serde::Deserialize<'de> for GradientStops { } } -impl Default for GradientStops { +impl Default for Gradient { fn default() -> Self { Self { position: vec![0., 1.], @@ -127,7 +127,7 @@ impl Default for GradientStops { } } -impl RenderComplexity for GradientStops { +impl RenderComplexity for Gradient { fn render_complexity(&self) -> usize { 1 } @@ -158,7 +158,7 @@ pub struct GradientStop { } pub struct GradientStopsIter<'a> { - stops: &'a GradientStops, + stops: &'a Gradient, index: usize, } @@ -187,7 +187,7 @@ impl<'a> Iterator for GradientStopsIter<'a> { impl ExactSizeIterator for GradientStopsIter<'_> {} -impl<'a> IntoIterator for &'a GradientStops { +impl<'a> IntoIterator for &'a Gradient { type Item = GradientStop; type IntoIter = GradientStopsIter<'a>; @@ -196,7 +196,7 @@ impl<'a> IntoIterator for &'a GradientStops { } } -impl IntoIterator for GradientStops { +impl IntoIterator for Gradient { type Item = GradientStop; type IntoIter = std::vec::IntoIter; @@ -211,7 +211,7 @@ impl IntoIterator for GradientStops { } } -impl GradientStops { +impl Gradient { pub fn new(stops: impl IntoIterator) -> Self { let mut position = Vec::new(); let mut midpoint = Vec::new(); @@ -465,7 +465,7 @@ impl GradientStops { let color = a.color.lerp(&b.color, time as f32); GradientStop { position, midpoint: 0.5, color } }); - GradientStops::new(stops) + Gradient::new(stops) } } @@ -540,19 +540,19 @@ pub fn initial_gradient_transform_for_bounding_box(bounds: [DVec2; 2]) -> DAffin } // TODO: Eventually remove this migration document upgrade code -pub fn migrate_to_gradient_stops<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result { +pub fn migrate_to_gradient<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result { use serde::Deserialize; #[derive(serde::Deserialize)] struct LegacyTable { #[serde(alias = "instances", alias = "instance")] - element: Vec, + element: Vec, } #[derive(serde::Deserialize)] #[cfg_attr(feature = "serde", serde(untagged))] enum GradientStopsFormat { - Stops(GradientStops), + Stops(Gradient), List(LegacyTable), } @@ -562,7 +562,7 @@ pub fn migrate_to_gradient_stops<'de, D: serde::Deserializer<'de>>(deserializer: }) } -impl core_types::bounds::BoundingBox for GradientStops { +impl core_types::bounds::BoundingBox for Gradient { fn bounding_box(&self, _transform: DAffine2, _include_stroke: bool) -> core_types::bounds::RenderBoundingBox { core_types::bounds::RenderBoundingBox::Infinite } diff --git a/node-graph/libraries/vector-types/src/lib.rs b/node-graph/libraries/vector-types/src/lib.rs index 42b24aea4c..2ba9d3648b 100644 --- a/node-graph/libraries/vector-types/src/lib.rs +++ b/node-graph/libraries/vector-types/src/lib.rs @@ -9,7 +9,7 @@ pub mod vector; // Re-export commonly used types at the crate root pub use core_types as gcore; -pub use gradient::{GradientSpreadMethod, GradientStop, GradientStops, GradientType}; +pub use gradient::{Gradient, GradientSpreadMethod, GradientStop, GradientType}; pub use markers::{ATTR_EDITOR_CLICK_TARGET, ATTR_GRADIENT_TYPE, ATTR_SPREAD_METHOD}; pub use math::{QuadExt, RectExt}; pub use subpath::Subpath; diff --git a/node-graph/libraries/vector-types/src/vector/style.rs b/node-graph/libraries/vector-types/src/vector/style.rs index 321828c450..c3cf6d6caf 100644 --- a/node-graph/libraries/vector-types/src/vector/style.rs +++ b/node-graph/libraries/vector-types/src/vector/style.rs @@ -10,7 +10,7 @@ use std::f64::consts::{PI, TAU}; /// Describes an editable fill choice, storing color or gradient stops without gradient placement metadata. /// -/// Can be None, a solid [Color], or a linear/radial [GradientStops]. +/// Can be None, a solid [Color], or a linear/radial [Gradient]. /// /// In the future we'll probably also add a pattern fill. /// @@ -22,11 +22,11 @@ pub enum FillChoice { #[default] None, Solid(Color), - Gradient(GradientStops), + Gradient(Gradient), } // TODO: Deprecate [`FillChoice`] and keep this, renamed, as the main widget-controlling type -/// JS-boundary version of [`FillChoice`] where the solid color is [`SRGBA8`] and the gradient is [`GradientStopsUI`]. +/// JS-boundary version of [`FillChoice`] where the solid color is [`SRGBA8`] and the gradient is [`GradientUI`]. #[cfg_attr(feature = "wasm", derive(tsify::Tsify), tsify(from_wasm_abi))] #[derive(Default, Debug, Clone, PartialEq, DynAny)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -34,7 +34,7 @@ pub enum FillChoiceUI { #[default] None, Solid(SRGBA8), - Gradient(GradientStopsUI), + Gradient(GradientUI), } impl From<&FillChoice> for FillChoiceUI { @@ -42,7 +42,7 @@ impl From<&FillChoice> for FillChoiceUI { match value { FillChoice::None => Self::None, FillChoice::Solid(color) => Self::Solid(SRGBA8::from(*color)), - FillChoice::Gradient(stops) => Self::Gradient(GradientStopsUI::from(stops)), + FillChoice::Gradient(stops) => Self::Gradient(GradientUI::from(stops)), } } } @@ -52,7 +52,7 @@ impl From<&FillChoiceUI> for FillChoice { match value { FillChoiceUI::None => Self::None, FillChoiceUI::Solid(srgba) => Self::Solid(Color::from(*srgba)), - FillChoiceUI::Gradient(stops) => Self::Gradient(GradientStops::from(stops)), + FillChoiceUI::Gradient(stops) => Self::Gradient(Gradient::from(stops)), } } } @@ -63,7 +63,7 @@ impl FillChoiceUI { Some(*c) } - pub fn as_gradient(&self) -> Option<&GradientStopsUI> { + pub fn as_gradient(&self) -> Option<&GradientUI> { let Self::Gradient(g) = self else { return None }; Some(g) } @@ -88,7 +88,7 @@ impl FillChoice { Some(*color) } - pub fn as_gradient(&self) -> Option<&GradientStops> { + pub fn as_gradient(&self) -> Option<&Gradient> { let Self::Gradient(gradient) = self else { return None }; Some(gradient) } diff --git a/node-graph/node-macro/src/codegen/entries.rs b/node-graph/node-macro/src/codegen/entries.rs index 2d1f84cd86..9b130080b7 100644 --- a/node-graph/node-macro/src/codegen/entries.rs +++ b/node-graph/node-macro/src/codegen/entries.rs @@ -598,7 +598,7 @@ mod tests { async fn rasterize( _: impl Ctx, _: (), - #[implementations(List, List>, List, List, List)] data: List, + #[implementations(List, List>, List, List, List)] data: List, footprint: Footprint, canvas: CanvasHandle, ) -> (Raster, Attr, OwnedAttr) { @@ -607,7 +607,7 @@ mod tests { ), ); assert!(entries.contains("fn rasterize_entries"), "a registrable record-io source must emit its entries fn"); - for element in ["Vector", "Raster < CPU >", "Graphic", "Color", "GradientStops"] { + for element in ["Vector", "Raster < CPU >", "Graphic", "Color", "Gradient"] { let row = format!("record_source_type :: < List < {element} > > ()"); assert!(entries.contains(&row), "the implementations row {element} is missing: {entries}"); } diff --git a/node-graph/node-macro/src/parsing.rs b/node-graph/node-macro/src/parsing.rs index 2b74ecdc50..0751a5271c 100644 --- a/node-graph/node-macro/src/parsing.rs +++ b/node-graph/node-macro/src/parsing.rs @@ -2186,10 +2186,10 @@ mod tests { #[implementations( () -> List>, () -> List, - () -> List, + () -> List, Footprint -> List>, Footprint -> List, - Footprint -> List, + Footprint -> List, )] image: impl Node, ) -> T { diff --git a/node-graph/nodes/gcore/src/animation.rs b/node-graph/nodes/gcore/src/animation.rs index 9bd9ef2993..45d8420a02 100644 --- a/node-graph/nodes/gcore/src/animation.rs +++ b/node-graph/nodes/gcore/src/animation.rs @@ -3,7 +3,7 @@ use core_types::list::List; use core_types::transform::Footprint; use core_types::{CacheHash, Color, Context, Ctx, DeriveCtx, ExtractAnimationTime, ExtractPointerPosition, ExtractRealTime}; use glam::{DAffine2, DVec2}; -use graphic_types::vector_types::GradientStops; +use graphic_types::vector_types::Gradient; use graphic_types::{Artboard, Graphic, Vector}; use raster_types::{CPU, GPU, Raster}; @@ -80,7 +80,7 @@ fn quantize_real_time( Context -> List>, Context -> List, Context -> List, - Context -> List, + Context -> List, Context -> List, Context -> List, Context -> (), @@ -120,7 +120,7 @@ fn quantize_animation_time( Context -> List>, Context -> List, Context -> List, - Context -> List, + Context -> List, Context -> List, Context -> List, Context -> (), diff --git a/node-graph/nodes/gcore/src/context.rs b/node-graph/nodes/gcore/src/context.rs index ee60d26490..ce742b14e9 100644 --- a/node-graph/nodes/gcore/src/context.rs +++ b/node-graph/nodes/gcore/src/context.rs @@ -3,7 +3,7 @@ use core_types::list::List; use core_types::{Color, ExtractVarArgs}; use core_types::{Ctx, ExtractIndex, ExtractIndices, ExtractPosition}; use glam::DVec2; -use graphic_types::vector_types::GradientStops; +use graphic_types::vector_types::Gradient; use graphic_types::{Graphic, Vector}; use raster_types::{CPU, Raster}; @@ -40,7 +40,7 @@ fn read_color(ctx: impl Ctx + ExtractVarArgs) -> List { } #[node_macro::node(category("Context"), path(graphene_core::vector))] -fn read_gradient(ctx: impl Ctx + ExtractVarArgs) -> List { +fn read_gradient(ctx: impl Ctx + ExtractVarArgs) -> List { let Ok(var_arg) = ctx.vararg(0) else { return Default::default() }; let var_arg = var_arg as &dyn std::any::Any; @@ -111,12 +111,12 @@ fn read_color_row_extent(_: &ReadColorRowNode, ctx: &C, /// Rank-model vararg source: the mapped row's items as lanes, elements only. #[node_macro::node(category("Test"), extent_raw(read_gradient_row_extent))] -pub fn read_gradient_row(ctx: impl Ctx + ExtractVarArgs + ExtractIndex) -> Result, Interrupt> { +pub fn read_gradient_row(ctx: impl Ctx + ExtractVarArgs + ExtractIndex) -> Result, Interrupt> { vararg_element(ctx) } fn read_gradient_row_extent(_: &ReadGradientRowNode, ctx: &C, level: u8) -> GPoll { - vararg_lanes::(ctx, level) + vararg_lanes::(ctx, level) } #[node_macro::node(category("Context"), path(core_types::vector))] diff --git a/node-graph/nodes/graphic/src/graphic.rs b/node-graph/nodes/graphic/src/graphic.rs index 49277a1075..2f9a416797 100644 --- a/node-graph/nodes/graphic/src/graphic.rs +++ b/node-graph/nodes/graphic/src/graphic.rs @@ -13,7 +13,7 @@ use graphic_types::{ATTR_EDITOR_MERGED_LAYERS, Artboard, Vector}; use raster_types::{CPU, GPU, Raster}; use vector_types::gradient::{GradientSpreadMethod, GradientType as GradientTypeValue}; -use vector_types::{GradientStop, GradientStops, ReferencePoint}; +use vector_types::{Gradient, GradientStop, ReferencePoint}; /// Resolves a signed index over `total` lanes: negatives count from the end, /// out of range resolves to nothing. @@ -100,7 +100,7 @@ fn omit_element_extent(list: ExtentIn<'_>, index: ValueIn<'_, f64>, level: Level pub fn extract_element( _: impl Ctx, /// The `List` of data to extract from. - #[implementations(String, f64, NodeId, Color, GradientStops, Vector, Raster, Graphic, Artboard)] + #[implementations(String, f64, NodeId, Color, Gradient, Vector, Raster, Graphic, Artboard)] list: IList, /// The index of the item to retrieve, starting from 0 for the first item. Negative indices count backwards from the end of the list, starting from -1 for the last item. index: SignedInteger, @@ -114,7 +114,7 @@ pub fn extract_element( #[node_macro::node(category("General"))] fn map( ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy, - #[implementations(Graphic, Vector, Raster, Color, GradientStops, String)] content: IList, + #[implementations(Graphic, Vector, Raster, Color, Gradient, String)] content: IList, mapped: impl Node, Output = IList>, ) -> Result, Interrupt> { let mut remaining = ctx.index(); @@ -429,9 +429,9 @@ fn extend_extent(base: ExtentIn<'_>, new: ExtentIn<'_>, level: LevelIn) -> GPoll #[node_macro::node(category(""))] pub fn legacy_layer_extend( _: impl Ctx, - #[implementations(List, List, List, List, List>, List>, List, List)] base: List, + #[implementations(List, List, List, List, List>, List>, List, List)] base: List, #[expose] - #[implementations(List, List, List, List, List>, List>, List, List)] + #[implementations(List, List, List, List, List>, List>, List, List)] new: List, nested_node_path: List, ) -> List { @@ -458,7 +458,7 @@ pub fn legacy_layer_extend( #[node_macro::node(category("General"), extent(wrap_graphic_extent))] pub fn wrap_graphic<'e, T: Clone + Send + Sync + core_types::CacheHash + 'static>( _: impl Ctx, - #[implementations(Graphic, Vector, Raster, Raster, Color, GradientStops, String)] content: IList, + #[implementations(Graphic, Vector, Raster, Raster, Color, Gradient, String)] content: IList, ) -> Result>, Interrupt> { let item = content.as_group_item(); Ok(Graphic::Group(core_types::record::Group { row: None, content: item })) @@ -483,7 +483,7 @@ pub fn to_graphic<'e, T: graphic_types::graphic::IntoGraphicElement>( List>, List>, List, - List, + List, List, )] content: T, @@ -503,14 +503,14 @@ pub fn to_graphic_element<'e, T: graphic_types::graphic::IntoGraphicElement>( Raster, Raster, Color, - GradientStops, + Gradient, String, List, List, List>, List>, List, - List, + List, List, )] content: T, @@ -524,7 +524,7 @@ pub fn to_graphic_element<'e, T: graphic_types::graphic::IntoGraphicElement>( #[node_macro::node(category(""), extent(wrap_graphic_extent))] pub fn to_graphic_typed<'e, T: Clone + Send + Sync + core_types::CacheHash + 'static>( _: impl Ctx, - #[implementations(Vector, Raster, Raster, Color, GradientStops, String)] content: IList, + #[implementations(Vector, Raster, Raster, Color, Gradient, String)] content: IList, ) -> Result>, Interrupt> { let item = content.as_group_item(); Ok(Graphic::Group(core_types::record::Group { row: None, content: item })) @@ -548,7 +548,7 @@ fn to_graphic_unit_extent(_content: core_types::extent::ValueIn<'_, ()>, _level: #[node_macro::node(category(""))] pub fn level_to_list( _: impl Ctx, - #[implementations(Graphic, Vector, Raster, Raster, Color, GradientStops, String)] value: IList, + #[implementations(Graphic, Vector, Raster, Raster, Color, Gradient, String)] value: IList, _converter: (), ) -> List { let item = value.as_group_item(); @@ -650,19 +650,19 @@ pub fn flatten_color(_: impl Ctx, #[implementations(List(_: impl Ctx, #[implementations(List, List)] content: T) -> List { +pub fn flatten_gradient(_: impl Ctx, #[implementations(List, List)] content: T) -> List { content.into_flattened_list() } /// Constructs a gradient from a `Color[]`, where the colors are evenly distributed as gradient stops across the range from 0 to 1. #[node_macro::node(category("Color"))] -fn colors_to_gradient(_: impl Ctx, colors: IList) -> GradientStops { +fn colors_to_gradient(_: impl Ctx, colors: IList) -> Gradient { let stop = |position: f64, color: Color| GradientStop { position, midpoint: 0.5, color }; match colors.len() { - 0 => GradientStops::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]), - 1 => GradientStops::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]), - total => GradientStops::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))), + 0 => Gradient::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]), + 1 => Gradient::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]), + total => Gradient::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))), } } diff --git a/node-graph/nodes/graphic/src/record.rs b/node-graph/nodes/graphic/src/record.rs index bd0cbeb788..546fadccbb 100644 --- a/node-graph/nodes/graphic/src/record.rs +++ b/node-graph/nodes/graphic/src/record.rs @@ -11,7 +11,7 @@ use glam::DAffine2; use graphic_types::Vector; use graphic_types::graphic::Graphic; use raster_types::{CPU, Raster}; -use vector_types::{GradientStop, GradientStops}; +use vector_types::{Gradient, GradientStop}; /// Whether the walk can descend into a group: the run holds `Graphic` /// elements. @@ -113,12 +113,12 @@ fn wrap_extent(_content: ListIn<'_, Graphic>, _level: LevelIn) -> GPoll /// Rank-model colors-to-gradient: the color level folds into one gradient /// with evenly spaced stops. #[node_macro::node(category("Test"))] -fn to_gradient(_: impl Ctx, colors: IList) -> GradientStops { +fn to_gradient(_: impl Ctx, colors: IList) -> Gradient { let stop = |position: f64, color: Color| GradientStop { position, midpoint: 0.5, color }; match colors.len() { - 0 => GradientStops::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]), - 1 => GradientStops::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]), - total => GradientStops::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))), + 0 => Gradient::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]), + 1 => Gradient::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]), + total => Gradient::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))), } } @@ -135,7 +135,7 @@ pub(crate) fn vararg_row(content: core_types #[node_macro::node(category("Test"))] fn map( ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy, - #[implementations(Graphic, Vector, Raster, Color, GradientStops, String)] content: IList, + #[implementations(Graphic, Vector, Raster, Color, Gradient, String)] content: IList, mapped: impl Node, Output = IList>, ) -> Result>, Interrupt> { let mut remaining = ctx.index(); @@ -159,7 +159,7 @@ fn map( #[node_macro::node(category("Test"))] fn flat_map( ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy, - #[implementations(Graphic, Vector, Raster, Color, GradientStops, String)] content: IList, + #[implementations(Graphic, Vector, Raster, Color, Gradient, String)] content: IList, mapped: impl Node, Output = IList>, ) -> Result, Interrupt> { let mut remaining = ctx.index(); @@ -820,14 +820,14 @@ mod tests { let ctx = ContextImpl::root(&scope); let layout = Layout::default().with_writes(1, record::element_write_hashed::(), &[]); - let out = Layout::default().with_writes(0, record::element_write_hashed::(), &[]); + let out = Layout::default().with_writes(0, record::element_write_hashed::(), &[]); let build = |colors: Vec| install_flip(ToGradientNode::new(RecordSource::new(ColorSource { layout: layout.clone(), colors }, &layout, &layout), &layout), &out); let stops_of = |colors: Vec| { let node = build(colors); let GPoll::Final(record) = record::capture(&node, &ctx, &frames) else { panic!("expected a final record"); }; - record.element::() + record.element::() }; let three = stops_of(vec![Color::BLACK, Color::WHITE, Color::BLACK]); diff --git a/node-graph/nodes/gstd/src/lib.rs b/node-graph/nodes/gstd/src/lib.rs index 67dafe89db..6fe946fc0e 100644 --- a/node-graph/nodes/gstd/src/lib.rs +++ b/node-graph/nodes/gstd/src/lib.rs @@ -58,7 +58,7 @@ pub mod subpath { } pub mod gradient { - pub use vector_types::{GradientStop, GradientStops}; + pub use vector_types::{Gradient, GradientStop}; } pub mod transform { diff --git a/node-graph/nodes/gstd/src/platform_application_io.rs b/node-graph/nodes/gstd/src/platform_application_io.rs index 56f5f1c4e5..f14c1c16de 100644 --- a/node-graph/nodes/gstd/src/platform_application_io.rs +++ b/node-graph/nodes/gstd/src/platform_application_io.rs @@ -33,7 +33,7 @@ use graphic_types::markers::EditorMergedLayers; use graphic_types::raster_types::Image; use graphic_types::raster_types::{CPU, Raster}; #[cfg(target_family = "wasm")] -use graphic_types::vector_types::gradient::GradientStops; +use graphic_types::vector_types::gradient::Gradient; #[cfg(target_family = "wasm")] use rendering::{Render, RenderParams, RenderSvgSegmentList, SvgRender}; use std::sync::Arc; @@ -212,7 +212,7 @@ async fn rasterize( Raster, Graphic, Color, - GradientStops, + Gradient, )] mut data: IList, footprint: Footprint, diff --git a/node-graph/nodes/gstd/src/render_node.rs b/node-graph/nodes/gstd/src/render_node.rs index 326970ad51..4d0e975ec7 100644 --- a/node-graph/nodes/gstd/src/render_node.rs +++ b/node-graph/nodes/gstd/src/render_node.rs @@ -8,7 +8,7 @@ use graphic_types::raster_types::{CPU, Raster}; use graphic_types::{Artboard, Graphic, Vector}; use rendering::{Render, RenderMetadata, RenderOutputType as RenderOutputTypeRequest, RenderParams, SvgRender, SvgRenderOutput}; use std::sync::Arc; -use vector_types::GradientStops; +use vector_types::Gradient; use wgpu_executor::RenderContext; #[derive(Clone, dyn_any::DynAny)] @@ -60,7 +60,7 @@ fn render_intermediate List, Context -> List>, Context -> List, - Context -> List, + Context -> List, Context -> List, )] data: impl Node, Output = T>, @@ -80,7 +80,7 @@ fn render_intermediate( ctx: impl Ctx + ExtractVarArgs + ExtractIndex + InjectIndex + Copy, - #[implementations(Artboard, Graphic, Vector, Raster, Color, GradientStops, String)] data: IList, + #[implementations(Artboard, Graphic, Vector, Raster, Color, Gradient, String)] data: IList, ) -> Result where for<'a> core_types::record::RunView<'a, T>: Render, diff --git a/node-graph/nodes/math/src/lib.rs b/node-graph/nodes/math/src/lib.rs index 11614d6494..efbaba93e0 100644 --- a/node-graph/nodes/math/src/lib.rs +++ b/node-graph/nodes/math/src/lib.rs @@ -11,7 +11,7 @@ use math_parser::value::{Number, Value}; use num_traits::Pow; use rand::{Rng, SeedableRng}; use std::ops::{Add, Div, Mul, Rem, Sub}; -use vector_types::GradientStops; +use vector_types::Gradient; use vector_types::markers::{GradientType as GradientTypeAttr, SpreadMethod as SpreadMethodAttr}; /// The struct that stores the context for the maths parser. @@ -819,25 +819,25 @@ fn hex_to_color(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, hex_code: Str /// Constructs a gradient value which may be set to any sequence of color stops to represent the transition between colors. #[node_macro::node(category("Value"))] -fn gradient_value(_: impl Ctx, _primary: (), gradient: GradientStops) -> GradientStops { +fn gradient_value(_: impl Ctx, _primary: (), gradient: Gradient) -> Gradient { gradient } /// Sets the type (linear or radial) of each gradient in the input list. #[node_macro::node(category("Color"))] -fn gradient_type(_: impl Ctx, gradient: GradientStops, gradient_type: vector_types::GradientType) -> (GradientStops, Attr) { +fn gradient_type(_: impl Ctx, gradient: Gradient, gradient_type: vector_types::GradientType) -> (Gradient, Attr) { (gradient, Attr(gradient_type)) } /// Sets how each gradient in the input list extends past its endpoints: Pad, Reflect, or Repeat. #[node_macro::node(category("Color"))] -fn spread_method(_: impl Ctx, gradient: GradientStops, spread_method: vector_types::GradientSpreadMethod) -> (GradientStops, Attr) { +fn spread_method(_: impl Ctx, gradient: Gradient, spread_method: vector_types::GradientSpreadMethod) -> (Gradient, Attr) { (gradient, Attr(spread_method)) } /// Gets the color at the specified position along the gradient, given a position from 0 (left) to 1 (right). #[node_macro::node(category("Color"))] -fn sample_gradient(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, _primary: (), gradient: IList, position: Fraction) -> Result, Interrupt> { +fn sample_gradient(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, _primary: (), gradient: IList, position: Fraction) -> Result, Interrupt> { // An unwired gradient serves an empty level: no color if gradient.is_empty() || ctx.index() != 0 { return Err(GraphError::past_end().into()); diff --git a/node-graph/nodes/path-bool/src/lib.rs b/node-graph/nodes/path-bool/src/lib.rs index 5c85953e13..13e79c9a6a 100644 --- a/node-graph/nodes/path-bool/src/lib.rs +++ b/node-graph/nodes/path-bool/src/lib.rs @@ -7,7 +7,7 @@ use glam::{DAffine2, DVec2}; use graphic_types::graphic::{GraphicLevel, PaintColumns, PaintReach, bake_paint_transforms, is_paint_present, set_paint_attribute, set_paint_attribute_at}; use graphic_types::markers::{EditorMergedLayers, Fill, Stroke}; use graphic_types::raster_types::{CPU, GPU, Raster}; -use graphic_types::vector_types::GradientStops; +use graphic_types::vector_types::Gradient; use graphic_types::vector_types::gradient::{GradientSpreadMethod, GradientType}; use graphic_types::vector_types::subpath::{ManipulatorGroup, Subpath}; use graphic_types::vector_types::vector::PointId; @@ -283,7 +283,7 @@ fn color_paint_row(color: Color, mut attributes: core_types::list::ItemAttribute /// A gradient row: an empty vector carrying the stops as its fill paint, the /// gradient keys moved onto the paint. -fn gradient_paint_row(stops: GradientStops, mut attributes: core_types::list::ItemAttributeValues) -> Item { +fn gradient_paint_row(stops: Gradient, mut attributes: core_types::list::ItemAttributeValues) -> Item { let mut gradient_paint = List::new_from_element(Graphic::Gradient(stops)); if let Some(transform) = attributes.remove::(ATTR_TRANSFORM) { gradient_paint.set_attribute(ATTR_TRANSFORM, 0, transform); @@ -409,7 +409,7 @@ fn flatten_group(out: &mut List, group: &core_types::record::Group, comp out, (0..color.len()).filter_map(|i| Some(color_paint_row(*color.element(i)?, color.clone_item_attributes(i)))).collect(), ); - } else if let Some(gradient) = graphic_types::graphic::run_to_list::(item) { + } else if let Some(gradient) = graphic_types::graphic::run_to_list::(item) { push_rows( out, (0..gradient.len()) diff --git a/node-graph/nodes/raster/src/adjust.rs b/node-graph/nodes/raster/src/adjust.rs index a08e6d84fc..52f372bcae 100644 --- a/node-graph/nodes/raster/src/adjust.rs +++ b/node-graph/nodes/raster/src/adjust.rs @@ -13,7 +13,7 @@ impl Adjust for Color { mod adjust_std { use super::*; use raster_types::{CPU, Raster}; - use vector_types::GradientStops; + use vector_types::Gradient; impl Adjust for Raster { fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) { @@ -22,7 +22,7 @@ mod adjust_std { } } } - impl Adjust for GradientStops { + impl Adjust for Gradient { fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) { for color in self.color.iter_mut() { *color = map_fn(color); diff --git a/node-graph/nodes/raster/src/adjustments.rs b/node-graph/nodes/raster/src/adjustments.rs index 4e4d1e393b..b16417c347 100644 --- a/node-graph/nodes/raster/src/adjustments.rs +++ b/node-graph/nodes/raster/src/adjustments.rs @@ -14,7 +14,7 @@ use num_traits::float::Float; #[cfg(feature = "std")] use raster_types::{CPU, Raster}; #[cfg(feature = "std")] -use vector_types::GradientStops; +use vector_types::Gradient; // TODO: Implement the following: // Color Balance @@ -53,7 +53,7 @@ fn luminance + Clone + Send + Sync + no_std_types::context::Cac #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -78,7 +78,7 @@ fn gamma_correction + Clone + Send + Sync + no_std_types::conte #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -100,7 +100,7 @@ fn extract_channel + Clone + Send + Sync + no_std_types::contex #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -124,7 +124,7 @@ fn make_opaque + Clone + Send + Sync + no_std_types::context::C #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -146,7 +146,7 @@ fn brightness_contrast_classic + Clone + Send + Sync + no_std_t #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -177,7 +177,7 @@ fn brightness_contrast + Clone + Send + Sync + no_std_types::co #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -258,7 +258,7 @@ fn levels + Clone + Send + Sync + no_std_types::context::CacheH #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -337,7 +337,7 @@ fn black_and_white + Clone + Send + Sync + no_std_types::contex #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -420,7 +420,7 @@ fn hue_saturation + Clone + Send + Sync + no_std_types::context #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -452,7 +452,7 @@ fn invert + Clone + Send + Sync + no_std_types::context::CacheH #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -473,7 +473,7 @@ fn threshold + Clone + Send + Sync + no_std_types::context::Cac #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -519,7 +519,7 @@ fn vibrance + Clone + Send + Sync + no_std_types::context::Cach #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -721,7 +721,7 @@ fn channel_mixer + Clone + Send + Sync + no_std_types::context: #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -853,7 +853,7 @@ fn selective_color + Clone + Send + Sync + no_std_types::contex #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, @@ -999,7 +999,7 @@ fn posterize + Clone + Send + Sync + no_std_types::context::Cac #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, @@ -1028,7 +1028,7 @@ fn exposure + Clone + Send + Sync + no_std_types::context::Cach #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut input: T, diff --git a/node-graph/nodes/raster/src/blending_nodes.rs b/node-graph/nodes/raster/src/blending_nodes.rs index 3970ceb298..69db82bf32 100644 --- a/node-graph/nodes/raster/src/blending_nodes.rs +++ b/node-graph/nodes/raster/src/blending_nodes.rs @@ -6,7 +6,7 @@ use no_std_types::registry::types::PercentageF32; #[cfg(feature = "std")] use raster_types::{CPU, Raster}; #[cfg(feature = "std")] -use vector_types::{GradientStop, GradientStops}; +use vector_types::{Gradient, GradientStop}; pub trait Blend { fn blend(&self, under: &Self, blend_fn: impl Fn(P, P) -> P) -> Self; @@ -36,7 +36,7 @@ mod blend_std { } } - impl Blend for GradientStops { + impl Blend for Gradient { fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self { let mut combined_stops = self.position.iter().chain(under.position.iter()).copied().collect::>(); combined_stops.dedup_by(|a, b| (*a - *b).abs() < 1e-6); @@ -47,7 +47,7 @@ mod blend_std { let color = blend_fn(over_color, under_color); GradientStop { position, midpoint: 0.5, color } }); - GradientStops::new(stops) + Gradient::new(stops) } } } @@ -111,7 +111,7 @@ fn mix + Clone + Send + Sync + core_types::CacheHash + 'static>( #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] over: T, @@ -119,7 +119,7 @@ fn mix + Clone + Send + Sync + core_types::CacheHash + 'static>( #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] under: T, @@ -135,7 +135,7 @@ fn color_overlay + Clone + Send + Sync + no_std_types::context: #[implementations( Raster, Color, - GradientStops, + Gradient, )] #[gpu_image] mut image: T, diff --git a/node-graph/nodes/raster/src/gradient_map.rs b/node-graph/nodes/raster/src/gradient_map.rs index 0965b677c6..a51a6e9c6b 100644 --- a/node-graph/nodes/raster/src/gradient_map.rs +++ b/node-graph/nodes/raster/src/gradient_map.rs @@ -1,9 +1,9 @@ -//! Not immediately shader compatible due to needing [`GradientStops`] as a param, which needs [`Vec`] +//! Not immediately shader compatible due to needing [`Gradient`] as a param, which needs [`Vec`] use crate::adjust::Adjust; use core_types::{Color, Ctx}; use raster_types::{CPU, Raster}; -use vector_types::GradientStops; +use vector_types::Gradient; // Aims for interoperable compatibility with: // https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27grdm%27%20%3D%20Gradient%20Map @@ -14,10 +14,10 @@ fn gradient_map + Clone + Send + Sync + core_types::CacheHash + #[implementations( Raster, Color, - GradientStops, + Gradient, )] mut image: T, - gradient: IList, + gradient: IList, reverse: bool, ) -> T { if gradient.is_empty() { diff --git a/node-graph/nodes/transform/src/transform_nodes.rs b/node-graph/nodes/transform/src/transform_nodes.rs index 12df79bef3..aa5c08b6d2 100644 --- a/node-graph/nodes/transform/src/transform_nodes.rs +++ b/node-graph/nodes/transform/src/transform_nodes.rs @@ -9,7 +9,7 @@ use glam::{DAffine2, DMat2, DVec2}; use graphic_types::Graphic; use graphic_types::Vector; use graphic_types::raster_types::{CPU, GPU, Raster}; -use vector_types::GradientStops; +use vector_types::Gradient; /// Applies the specified transform to each lane of the input, composing onto the lane's transform attribute. #[node_macro::node(category("Math: Transform"), extent(transform_extent))] @@ -97,7 +97,7 @@ fn replace_transform(_: impl Ctx + InjectFootprint, (element, _content_transf // TODO: Figure out how this node should behave once #2982 is implemented. /// Obtains the transform of the first lane of the input, if present. #[node_macro::node(category("Math: Transform"), path(core_types::vector))] -fn extract_transform(_: impl Ctx, #[implementations(Graphic, Vector, Raster, Raster, Color, GradientStops)] content: IList) -> DAffine2 { +fn extract_transform(_: impl Ctx, #[implementations(Graphic, Vector, Raster, Raster, Color, Gradient)] content: IList) -> DAffine2 { match content.len() { 0 => DAffine2::default(), _ => content.lane(0).attr::(), diff --git a/node-graph/nodes/vector/src/vector_nodes.rs b/node-graph/nodes/vector/src/vector_nodes.rs index d0ffe44bba..fea8d6796a 100644 --- a/node-graph/nodes/vector/src/vector_nodes.rs +++ b/node-graph/nodes/vector/src/vector_nodes.rs @@ -37,14 +37,14 @@ use vector_types::vector::misc::{ CentroidType, ExtrudeJoiningAlgorithm, HandleId, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns, bezpath_from_manipulator_groups, bezpath_to_manipulator_groups, handles_to_segment, is_linear, point_to_dvec2, segment_to_handles, }; -use vector_types::vector::style::{GradientStops, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin}; +use vector_types::vector::style::{Gradient, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin}; use vector_types::vector::{FillId, PointId, RegionId, SegmentDomain, SegmentId, StrokeId, VectorExt}; use vector_types::{ATTR_GRADIENT_TYPE, ATTR_SPREAD_METHOD}; use vector_types::{GradientSpreadMethod, GradientType}; /// The gradient color for one assign-colors position, replaying the /// randomized draws up to it. -fn assign_color_at(gradient: &GradientStops, position: usize, length: usize, randomize: bool, seed: SeedValue, repeat_every: u32) -> Color { +fn assign_color_at(gradient: &Gradient, position: usize, length: usize, randomize: bool, seed: SeedValue, repeat_every: u32) -> Color { let factor = match randomize { true => { let mut rng = rand::rngs::StdRng::seed_from_u64(seed.into()); @@ -77,7 +77,7 @@ fn assign_colors<'e>( stroke: bool, /// The range of colors to select from. #[widget(ParsedWidgetOverride::Custom = "assign_colors_gradient")] - gradient: IList, + gradient: IList, /// Whether to reverse the gradient. reverse: bool, /// Whether to randomize the color selection for each element from throughout the gradient. @@ -132,7 +132,7 @@ fn assign_colors_extent( content: ListIn<'_, Vector>, _fill: ValueIn<'_, bool>, _stroke: ValueIn<'_, bool>, - _gradient: ListIn<'_, GradientStops>, + _gradient: ListIn<'_, Gradient>, _reverse: ValueIn<'_, bool>, _randomize: ValueIn<'_, bool>, _seed: ValueIn<'_, SeedValue>, @@ -155,7 +155,7 @@ fn assign_colors_graphic<'e>( #[data] lane_offsets: std::sync::Arc>>, #[default(true)] fill: bool, stroke: bool, - gradient: IList, + gradient: IList, reverse: bool, randomize: bool, seed: SeedValue, @@ -247,7 +247,7 @@ fn assign_colors_graphic_extent( content: ListIn<'_, Graphic>, _fill: ValueIn<'_, bool>, _stroke: ValueIn<'_, bool>, - _gradient: ListIn<'_, GradientStops>, + _gradient: ListIn<'_, Gradient>, _reverse: ValueIn<'_, bool>, _randomize: ValueIn<'_, bool>, _seed: ValueIn<'_, SeedValue>, @@ -322,7 +322,7 @@ fn fill<'e>( #[default(Color::BLACK)] fill: IList>, _backup_color: IList, - _backup_gradient: IList, + _backup_gradient: IList, _gradient_type: GradientType, _spread_method: GradientSpreadMethod, _transform: Option, @@ -342,7 +342,7 @@ fn fill_graphic_leveled<'e>( (element, _content_fill): (Graphic<'static>, Attr), #[default(Color::BLACK)] fill: IList>, _backup_color: IList, - _backup_gradient: IList, + _backup_gradient: IList, _gradient_type: GradientType, _spread_method: GradientSpreadMethod, _transform: Option, @@ -2780,7 +2780,7 @@ fn morph_core(flattened: List, snapshot: List>, progres }; // This keeps the gradient metadata attributes, which ride the paint lane - let gradient_paint = |metadata_source: &List, stops: GradientStops, transform: Option| -> List { + let gradient_paint = |metadata_source: &List, stops: Gradient, transform: Option| -> List { let mut out = List::new_from_item(Item::from_parts(Graphic::Gradient(stops), metadata_source.clone_item_attributes(0))); if let Some(transform) = transform { out.set_attribute(ATTR_TRANSFORM, 0, transform); @@ -3666,7 +3666,7 @@ fn point_inside(_: impl Ctx, source: IList, point: DVec2) -> bool { // TODO: Return u32, u64, or usize instead of f64 after #1621 is resolved and has allowed us to implement automatic type conversion in the node graph for nodes with generic type inputs. // TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.) #[node_macro::node(category("General"), path(graphene_core::vector))] -fn count_elements(_: impl Ctx, #[implementations(Graphic, Artboard, Vector, Raster, Color, GradientStops, String)] content: IList) -> f64 { +fn count_elements(_: impl Ctx, #[implementations(Graphic, Artboard, Vector, Raster, Color, Gradient, String)] content: IList) -> f64 { content.len() as f64 } diff --git a/tools/node-docs/src/page_node.rs b/tools/node-docs/src/page_node.rs index df4a868a80..673928c6e5 100644 --- a/tools/node-docs/src/page_node.rs +++ b/tools/node-docs/src/page_node.rs @@ -180,7 +180,7 @@ fn write_inputs(page: &mut std::fs::File, valid_input_types: &[Vec"#); let default_value = match default_value { "Color::BLACK" => render_color("black"), - "GradientStops([(0.0, Color { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 }), (1.0, Color { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 })])" => { + "Gradient([(0.0, Color { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 }), (1.0, Color { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 })])" => { render_color("linear-gradient(to right, black, white)") } _ => format!("`{default_value}{}`", field.unit.unwrap_or_default()),