Allow the Stroke node to receive "Dash Lengths" values from the node graph
This commit is contained in:
parent
0298f9a5ad
commit
ac74bd9903
|
|
@ -388,7 +388,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||||
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.join_miter_limit), false), false);
|
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.join_miter_limit), false), false);
|
||||||
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::PaintOrderInput::INDEX);
|
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::PaintOrderInput::INDEX);
|
||||||
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::PaintOrder(stroke.paint_order), false), false);
|
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::PaintOrder(stroke.paint_order), false), false);
|
||||||
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashLengthsInput::INDEX);
|
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashLengthsInput::<Vec<f64>>::INDEX);
|
||||||
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::VecF64(stroke.dash_lengths), false), true);
|
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::VecF64(stroke.dash_lengths), false), true);
|
||||||
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashOffsetInput::INDEX);
|
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashOffsetInput::INDEX);
|
||||||
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.dash_offset), false), true);
|
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.dash_offset), false), true);
|
||||||
|
|
|
||||||
|
|
@ -1849,7 +1849,7 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
|
||||||
_ => &StrokeJoin::Miter,
|
_ => &StrokeJoin::Miter,
|
||||||
};
|
};
|
||||||
|
|
||||||
let dash_lengths_val = match &document_node.inputs[DashLengthsInput::INDEX].as_value() {
|
let dash_lengths_val = match &document_node.inputs[DashLengthsInput::<Vec<f64>>::INDEX].as_value() {
|
||||||
Some(TaggedValue::VecF64(x)) => x,
|
Some(TaggedValue::VecF64(x)) => x,
|
||||||
_ => &vec![],
|
_ => &vec![],
|
||||||
};
|
};
|
||||||
|
|
@ -1877,7 +1877,10 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
|
||||||
.for_socket(ParameterWidgetsInfo::new(node_id, PaintOrderInput::INDEX, true, context))
|
.for_socket(ParameterWidgetsInfo::new(node_id, PaintOrderInput::INDEX, true, context))
|
||||||
.property_row();
|
.property_row();
|
||||||
let disabled_number_input = NumberInput::default().unit(" px").disabled(has_dash_lengths);
|
let disabled_number_input = NumberInput::default().unit(" px").disabled(has_dash_lengths);
|
||||||
let dash_lengths = array_of_number_widget(ParameterWidgetsInfo::new(node_id, DashLengthsInput::INDEX, true, context), TextInput::default().centered(true));
|
let dash_lengths = array_of_number_widget(
|
||||||
|
ParameterWidgetsInfo::new(node_id, DashLengthsInput::<Vec<f64>>::INDEX, true, context),
|
||||||
|
TextInput::default().centered(true),
|
||||||
|
);
|
||||||
let number_input = disabled_number_input;
|
let number_input = disabled_number_input;
|
||||||
let dash_offset = number_widget(ParameterWidgetsInfo::new(node_id, DashOffsetInput::INDEX, true, context), number_input);
|
let dash_offset = number_widget(ParameterWidgetsInfo::new(node_id, DashOffsetInput::INDEX, true, context), number_input);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,31 @@ async fn fill<F: Into<Fill> + 'n + Send, V: VectorTableIterMut + 'n + Send>(
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait IntoF64Vec {
|
||||||
|
fn into_vec(self) -> Vec<f64>;
|
||||||
|
}
|
||||||
|
impl IntoF64Vec for f64 {
|
||||||
|
fn into_vec(self) -> Vec<f64> {
|
||||||
|
vec![self]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl IntoF64Vec for Vec<f64> {
|
||||||
|
fn into_vec(self) -> Vec<f64> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl IntoF64Vec for String {
|
||||||
|
fn into_vec(self) -> Vec<f64> {
|
||||||
|
self.split(&[',', ' ']).filter(|s| !s.is_empty()).filter_map(|s| s.parse::<f64>().ok()).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Applies a stroke style to the vector content, giving an appearance to the area within the outline of the geometry.
|
/// Applies a stroke style to the vector content, giving an appearance to the area within the outline of the geometry.
|
||||||
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("stroke_properties"))]
|
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("stroke_properties"))]
|
||||||
async fn stroke<V>(
|
async fn stroke<V, L: IntoF64Vec>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
/// The content with vector paths to apply the stroke style to.
|
/// The content with vector paths to apply the stroke style to.
|
||||||
#[implementations(Table<Vector>, Table<Graphic>)]
|
#[implementations(Table<Vector>, Table<Vector>, Table<Vector>, Table<Graphic>, Table<Graphic>, Table<Graphic>)]
|
||||||
mut content: Table<V>,
|
mut content: Table<V>,
|
||||||
/// The stroke color.
|
/// The stroke color.
|
||||||
#[default(Color::BLACK)]
|
#[default(Color::BLACK)]
|
||||||
|
|
@ -173,7 +192,8 @@ async fn stroke<V>(
|
||||||
/// <https://svgwg.org/svg2-draft/painting.html#PaintOrderProperty>
|
/// <https://svgwg.org/svg2-draft/painting.html#PaintOrderProperty>
|
||||||
paint_order: PaintOrder,
|
paint_order: PaintOrder,
|
||||||
/// The stroke dash lengths. Each length forms a distance in a pattern where the first length is a dash, the second is a gap, and so on. If the list is an odd length, the pattern repeats with solid-gap roles reversed.
|
/// The stroke dash lengths. Each length forms a distance in a pattern where the first length is a dash, the second is a gap, and so on. If the list is an odd length, the pattern repeats with solid-gap roles reversed.
|
||||||
dash_lengths: Vec<f64>,
|
#[implementations(Vec<f64>, f64, String, Vec<f64>, f64, String)]
|
||||||
|
dash_lengths: L,
|
||||||
/// The phase offset distance from the starting point of the dash pattern.
|
/// The phase offset distance from the starting point of the dash pattern.
|
||||||
#[unit(" px")]
|
#[unit(" px")]
|
||||||
dash_offset: f64,
|
dash_offset: f64,
|
||||||
|
|
@ -184,7 +204,7 @@ where
|
||||||
let stroke = Stroke {
|
let stroke = Stroke {
|
||||||
color: color.into(),
|
color: color.into(),
|
||||||
weight,
|
weight,
|
||||||
dash_lengths,
|
dash_lengths: dash_lengths.into_vec(),
|
||||||
dash_offset,
|
dash_offset,
|
||||||
cap,
|
cap,
|
||||||
join,
|
join,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue