Skip to content

Commit 9018e7f

Browse files
committed
Move Vec<f64> to Table<f64>
1 parent 75a917d commit 9018e7f

10 files changed

Lines changed: 42 additions & 21 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
170170
Table<Color>,
171171
Table<GradientStops>,
172172
Table<String>,
173+
Table<f64>,
173174
Table<u8>,
174175
GradientStops,
175176
f64,
@@ -829,6 +830,7 @@ macro_rules! known_table_row_types {
829830
Table<Color>,
830831
Table<GradientStops>,
831832
Table<String>,
833+
Table<f64>,
832834
Table<u8>,
833835
GradientStops,
834836
Color,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,9 @@ impl<'a> ModifyInputsContext<'a> {
491491
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.join_miter_limit), false), false);
492492
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::PaintOrderInput::INDEX);
493493
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::PaintOrder(stroke.paint_order), false), false);
494-
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashLengthsInput::<Vec<f64>>::INDEX);
495-
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::VecF64(stroke.dash_lengths), false), true);
494+
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashLengthsInput::<graphene_std::table::Table<f64>>::INDEX);
495+
let dash_lengths_table = stroke.dash_lengths.into_iter().map(graphene_std::table::TableRow::new_from_element).collect();
496+
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64Table(dash_lengths_table), false), true);
496497
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::DashOffsetInput::INDEX);
497498
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.dash_offset), false), true);
498499
}

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,10 @@ pub(crate) fn property_from_type(
210210
Some(x) if x == TypeId::of::<String>() => text_widget(default_info).into(),
211211
Some(x) if x == TypeId::of::<DVec2>() => vec2_widget(default_info, "X", "Y", "", None, false),
212212
Some(x) if x == TypeId::of::<DAffine2>() => transform_widget(default_info, &mut extra_widgets),
213-
// ==========================
214-
// PRIMITIVE COLLECTION TYPES
215-
// ==========================
216-
Some(x) if x == TypeId::of::<Vec<f64>>() => array_of_number_widget(default_info, TextInput::default()).into(),
217213
// ===========
218214
// TABLE TYPES
219215
// ===========
216+
Some(x) if x == TypeId::of::<Table<f64>>() => array_of_number_widget(default_info, TextInput::default()).into(),
220217
Some(x) if x == TypeId::of::<Table<Color>>() => color_widget(default_info, ColorInput::default().allow_none(true)),
221218
Some(x) if x == TypeId::of::<Table<GradientStops>>() => color_widget(default_info, ColorInput::default().allow_none(false)),
222219
// ============
@@ -775,19 +772,19 @@ pub fn array_of_number_widget(parameter_widgets_info: ParameterWidgetsInfo, text
775772
.map(str::parse::<f64>)
776773
.collect::<Result<Vec<_>, _>>()
777774
.ok()
778-
.map(TaggedValue::VecF64)
775+
.map(|values| TaggedValue::F64Table(values.into_iter().map(graphene_std::table::TableRow::new_from_element).collect()))
779776
};
780777

781778
let Some(document_node) = document_node else { return Vec::new() };
782779
let Some(input) = document_node.inputs.get(index) else {
783780
log::warn!("A widget failed to be built because its node's input index is invalid.");
784781
return vec![];
785782
};
786-
if let Some(TaggedValue::VecF64(x)) = &input.as_non_exposed_value() {
783+
if let Some(TaggedValue::F64Table(table)) = &input.as_non_exposed_value() {
787784
widgets.extend_from_slice(&[
788785
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
789786
text_input
790-
.value(x.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(", "))
787+
.value(table.iter_element_values().map(|v| v.to_string()).collect::<Vec<_>>().join(", "))
791788
.on_update(optionally_update_value(move |x: &TextInput| from_string(&x.value), node_id, index))
792789
.widget_instance(),
793790
])
@@ -2263,11 +2260,10 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
22632260
_ => &StrokeJoin::Miter,
22642261
};
22652262

2266-
let dash_lengths_val = match &document_node.inputs[DashLengthsInput::<Vec<f64>>::INDEX].as_value() {
2267-
Some(TaggedValue::VecF64(x)) => x,
2268-
_ => &vec![],
2263+
let has_dash_lengths = match &document_node.inputs[DashLengthsInput::<Table<f64>>::INDEX].as_value() {
2264+
Some(TaggedValue::F64Table(table)) => table.is_empty(),
2265+
_ => true,
22692266
};
2270-
let has_dash_lengths = dash_lengths_val.is_empty();
22712267
let miter_limit_disabled = join_value != &StrokeJoin::Miter;
22722268

22732269
let color = color_widget(
@@ -2292,7 +2288,7 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
22922288
.property_row();
22932289
let disabled_number_input = NumberInput::default().unit(" px").disabled(has_dash_lengths);
22942290
let dash_lengths = array_of_number_widget(
2295-
ParameterWidgetsInfo::new(node_id, DashLengthsInput::<Vec<f64>>::INDEX, true, context),
2291+
ParameterWidgetsInfo::new(node_id, DashLengthsInput::<Table<f64>>::INDEX, true, context),
22962292
TextInput::default().centered(true),
22972293
);
22982294
let number_input = disabled_number_input;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl FrontendGraphDataType {
2727
| TaggedValue::F64(_)
2828
| TaggedValue::DVec2(_)
2929
| TaggedValue::F64Array4(_)
30-
| TaggedValue::VecF64(_)
30+
| TaggedValue::F64Table(_)
3131
| TaggedValue::DAffine2(_) => Self::Number,
3232
TaggedValue::Artboard(_) => Self::Artboard,
3333
TaggedValue::Graphic(_) => Self::Graphic,

editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl TypeSource {
5959
| TaggedValue::F64(_)
6060
| TaggedValue::DVec2(_)
6161
| TaggedValue::F64Array4(_)
62-
| TaggedValue::VecF64(_)
62+
| TaggedValue::F64Table(_)
6363
| TaggedValue::DAffine2(_) => FrontendGraphDataType::Number,
6464
TaggedValue::Artboard(_) => FrontendGraphDataType::Artboard,
6565
TaggedValue::Graphic(_) => FrontendGraphDataType::Graphic,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,15 @@ tagged_value! {
178178
// ========================
179179
// LISTS OF PRIMITIVE TYPES
180180
// ========================
181-
#[serde(alias = "VecF32")] // TODO: Eventually remove this alias document upgrade code
182-
VecF64(Vec<f64>),
183181
F64Array4([f64; 4]),
184182
NodePath(Vec<NodeId>),
185183
// ===========
186184
// TABLE TYPES
187185
// ===========
188186
StringTable(Table<String>),
187+
#[serde(deserialize_with = "core_types::misc::migrate_vec_f64_to_table")] // TODO: Eventually remove this migration document upgrade code
188+
#[serde(alias = "VecF64", alias = "VecF32")]
189+
F64Table(Table<f64>),
189190
#[serde(deserialize_with = "graphic_types::migrations::migrate_vector")] // TODO: Eventually remove this migration document upgrade code
190191
#[serde(alias = "VectorData")]
191192
Vector(Table<Vector>),

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
9797
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<f64>]),
9898
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<NodeId>]),
9999
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<String>]),
100+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<f64>]),
100101
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<u8>]),
101102
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => [f64; 4]]),
102103
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Graphic]),
@@ -153,6 +154,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
153154
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
154155
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<GradientStops>]),
155156
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<String>]),
157+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<f64>]),
156158
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<u8>]),
157159
#[cfg(target_family = "wasm")]
158160
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => CanvasHandle]),

node-graph/libraries/core-types/src/misc.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,21 @@ pub fn migrate_color<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Resul
8787
ColorFormat::ColorTable(color_table) => color_table,
8888
})
8989
}
90+
91+
// TODO: Eventually remove this migration document upgrade code
92+
pub fn migrate_vec_f64_to_table<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<crate::table::Table<f64>, D::Error> {
93+
use crate::table::{Table, TableRow};
94+
use serde::Deserialize;
95+
96+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
97+
#[cfg_attr(feature = "serde", serde(untagged))]
98+
enum F64TableFormat {
99+
VecF64(Vec<f64>),
100+
F64Table(Table<f64>),
101+
}
102+
103+
Ok(match F64TableFormat::deserialize(deserializer)? {
104+
F64TableFormat::VecF64(values) => values.into_iter().map(TableRow::new_from_element).collect(),
105+
F64TableFormat::F64Table(table) => table,
106+
})
107+
}

node-graph/nodes/gcore/src/context_modification.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async fn context_modification<T>(
2828
Context -> DVec2,
2929
Context -> Option<NodeId>,
3030
Context -> Table<String>,
31+
Context -> Table<f64>,
3132
Context -> Table<u8>,
3233
Context -> Table<Vector>,
3334
Context -> Table<Graphic>,

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ impl IntoF64Vec for f64 {
179179
vec![self]
180180
}
181181
}
182-
impl IntoF64Vec for Vec<f64> {
182+
impl IntoF64Vec for Table<f64> {
183183
fn into_vec(self) -> Vec<f64> {
184-
self
184+
self.into_iter().map(|row| row.into_element()).collect()
185185
}
186186
}
187187
impl IntoF64Vec for String {
@@ -217,7 +217,7 @@ async fn stroke<V, L: IntoF64Vec>(
217217
/// The order to paint the stroke on top of the fill, or the fill on top of the stroke.
218218
paint_order: PaintOrder,
219219
/// 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.
220-
#[implementations(Vec<f64>, f64, String, Vec<f64>, f64, String)]
220+
#[implementations(Table<f64>, f64, String, Table<f64>, f64, String)]
221221
dash_lengths: L,
222222
/// The phase offset distance from the starting point of the dash pattern.
223223
#[unit(" px")]

0 commit comments

Comments
 (0)