Skip to content

Commit 1eb2ae9

Browse files
committed
Replace TaggedValue tabular variants for color and gradient with non-tabular forms
1 parent 1305ba9 commit 1eb2ae9

17 files changed

Lines changed: 230 additions & 88 deletions

File tree

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> ModifyInputsContext<'a> {
137137
Some(NodeInput::value(TaggedValue::Graphic(Default::default()), true)),
138138
Some(NodeInput::value(TaggedValue::DVec2(artboard.location.into()), false)),
139139
Some(NodeInput::value(TaggedValue::DVec2(artboard.dimensions.into()), false)),
140-
Some(NodeInput::value(TaggedValue::Color(Table::new_from_element(artboard.background)), false)),
140+
Some(NodeInput::value(TaggedValue::Color(artboard.background), false)),
141141
Some(NodeInput::value(TaggedValue::Bool(artboard.clip), false)),
142142
]);
143143
self.network_interface.insert_node(new_id, artboard_node_template, &[]);
@@ -293,10 +293,7 @@ impl<'a> ModifyInputsContext<'a> {
293293
pub fn insert_color_value(&mut self, color: Color, layer: LayerNodeIdentifier) {
294294
let color_value = resolve_proto_node_type(graphene_std::math_nodes::color_value::IDENTIFIER)
295295
.expect("Color Value node does not exist")
296-
.node_template_input_override([
297-
Some(NodeInput::value(TaggedValue::None, false)),
298-
Some(NodeInput::value(TaggedValue::Color(Table::new_from_element(color)), false)),
299-
]);
296+
.node_template_input_override([Some(NodeInput::value(TaggedValue::None, false)), Some(NodeInput::value(TaggedValue::OptionalColor(Some(color)), false))]);
300297

301298
let color_value_id = NodeId::new();
302299
self.network_interface.insert_node(color_value_id, color_value, &[]);
@@ -420,11 +417,11 @@ impl<'a> ModifyInputsContext<'a> {
420417
match &fill {
421418
Fill::None => {
422419
let input_connector = InputConnector::node(fill_node_id, backup_color_index);
423-
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::Color(Table::new()), false), true);
420+
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::OptionalColor(None), false), true);
424421
}
425422
Fill::Solid(color) => {
426423
let input_connector = InputConnector::node(fill_node_id, backup_color_index);
427-
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::Color(Table::new_from_element(*color)), false), true);
424+
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::OptionalColor(Some(*color)), false), true);
428425
}
429426
Fill::Gradient(gradient) => {
430427
let input_connector = InputConnector::node(fill_node_id, backup_gradient_index);
@@ -473,10 +470,8 @@ impl<'a> ModifyInputsContext<'a> {
473470
return;
474471
};
475472

476-
let stroke_color = if let Some(color) = stroke.color { Table::new_from_element(color) } else { Table::new() };
477-
478-
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::ColorInput::INDEX);
479-
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::Color(stroke_color), false), true);
473+
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::ColorInput::<Option<Color>>::INDEX);
474+
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::OptionalColor(stroke.color), false), true);
480475
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::WeightInput::INDEX);
481476
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(stroke.weight), false), true);
482477
let input_connector = InputConnector::node(stroke_node_id, graphene_std::vector::stroke::AlignInput::INDEX);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
379379
NodeInput::value(TaggedValue::Graphic(Default::default()), true),
380380
NodeInput::value(TaggedValue::DVec2(DVec2::ZERO), false),
381381
NodeInput::value(TaggedValue::DVec2(DVec2::new(1920., 1080.)), false),
382-
NodeInput::value(TaggedValue::Color(Table::new_from_element(Color::WHITE)), false),
382+
NodeInput::value(TaggedValue::Color(Color::WHITE), false),
383383
NodeInput::value(TaggedValue::Bool(true), false),
384384
],
385385
..Default::default()

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use graphene_std::raster::{
2222
SelectiveColorChoice,
2323
};
2424
use graphene_std::raster_types::Image;
25-
use graphene_std::table::{Table, TableRow};
2625
use graphene_std::text::{Font, TextAlign};
2726
use graphene_std::transform::{Footprint, ReferencePoint, ScaleType, Transform};
2827
use graphene_std::vector::misc::BooleanOperation;
@@ -220,11 +219,12 @@ pub(crate) fn property_from_type(
220219
// ==========================
221220
Some(x) if x == TypeId::of::<Vec<f64>>() => array_of_number_widget(default_info, TextInput::default()).into(),
222221
Some(x) if x == TypeId::of::<Vec<DVec2>>() => array_of_vec2_widget(default_info, TextInput::default()).into(),
223-
// ===========
224-
// TABLE TYPES
225-
// ===========
226-
Some(x) if x == TypeId::of::<Table<Color>>() => color_widget(default_info, ColorInput::default().allow_none(true)),
227-
Some(x) if x == TypeId::of::<Table<GradientStops>>() => color_widget(default_info, ColorInput::default().allow_none(false)),
222+
// =========================
223+
// COLOR AND GRADIENT TYPES
224+
// =========================
225+
Some(x) if x == TypeId::of::<Color>() => color_widget(default_info, ColorInput::default().allow_none(false)),
226+
Some(x) if x == TypeId::of::<Option<Color>>() => color_widget(default_info, ColorInput::default().allow_none(true)),
227+
Some(x) if x == TypeId::of::<GradientStops>() => color_widget(default_info, ColorInput::default().allow_none(false)),
228228
// ============
229229
// STRUCT TYPES
230230
// ============
@@ -1180,28 +1180,28 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
11801180

11811181
// Add the color input
11821182
match &**tagged_value {
1183-
TaggedValue::Color(color_table) => widgets.push(
1183+
TaggedValue::Color(color) => widgets.push(
1184+
color_button
1185+
.value(FillChoice::Solid(*color))
1186+
.on_update(update_value(|input: &ColorInput| TaggedValue::Color(input.value.as_solid().unwrap_or(Color::BLACK)), node_id, index))
1187+
.on_commit(commit_value)
1188+
.widget_instance(),
1189+
),
1190+
TaggedValue::OptionalColor(optional_color) => widgets.push(
11841191
color_button
1185-
.value(match color_table.iter().next() {
1186-
Some(color) => FillChoice::Solid(*color.element),
1192+
.value(match optional_color {
1193+
Some(color) => FillChoice::Solid(*color),
11871194
None => FillChoice::None,
11881195
})
1189-
.on_update(update_value(
1190-
|input: &ColorInput| TaggedValue::Color(input.value.as_solid().iter().map(|&color| TableRow::new_from_element(color)).collect()),
1191-
node_id,
1192-
index,
1193-
))
1196+
.on_update(update_value(|input: &ColorInput| TaggedValue::OptionalColor(input.value.as_solid()), node_id, index))
11941197
.on_commit(commit_value)
11951198
.widget_instance(),
11961199
),
1197-
TaggedValue::GradientTable(gradient_table) => widgets.push(
1200+
TaggedValue::GradientStops(gradient_stops) => widgets.push(
11981201
color_button
1199-
.value(match gradient_table.iter().next() {
1200-
Some(row) => FillChoice::Gradient(row.element.clone()),
1201-
None => FillChoice::Gradient(GradientStops::default()),
1202-
})
1202+
.value(FillChoice::Gradient(gradient_stops.clone()))
12031203
.on_update(update_value(
1204-
|input: &ColorInput| TaggedValue::GradientTable(input.value.as_gradient().iter().map(|&gradient| TableRow::new_from_element(gradient.clone())).collect()),
1204+
|input: &ColorInput| TaggedValue::GradientStops(input.value.as_gradient().cloned().unwrap_or_default()),
12051205
node_id,
12061206
index,
12071207
))
@@ -1884,7 +1884,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
18841884
}
18851885
};
18861886

1887-
let (fill, backup_color, backup_gradient) = if let (Some(TaggedValue::Fill(fill)), Some(TaggedValue::Color(backup_color)), Some(TaggedValue::Gradient(backup_gradient))) = (
1887+
let (fill, backup_color, backup_gradient) = if let (Some(TaggedValue::Fill(fill)), Some(TaggedValue::OptionalColor(backup_color)), Some(TaggedValue::Gradient(backup_gradient))) = (
18881888
&document_node.inputs[FillInput::<Color>::INDEX].as_value(),
18891889
&document_node.inputs[BackupColorInput::INDEX].as_value(),
18901890
&document_node.inputs[BackupGradientInput::INDEX].as_value(),
@@ -1894,7 +1894,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
18941894
return vec![LayoutGroup::row(widgets_first_row)];
18951895
};
18961896
let fill2 = fill.clone();
1897-
let backup_color_fill: Fill = backup_color.clone().into();
1897+
let backup_color_fill: Fill = (*backup_color).into();
18981898
let backup_gradient_fill: Fill = backup_gradient.clone().into();
18991899

19001900
widgets_first_row.push(Separator::new(SeparatorStyle::Unrelated).widget_instance());
@@ -1907,13 +1907,13 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
19071907
Fill::None => NodeGraphMessage::SetInputValue {
19081908
node_id,
19091909
input_index: BackupColorInput::INDEX,
1910-
value: TaggedValue::Color(Table::new()),
1910+
value: TaggedValue::OptionalColor(None),
19111911
}
19121912
.into(),
19131913
Fill::Solid(color) => NodeGraphMessage::SetInputValue {
19141914
node_id,
19151915
input_index: BackupColorInput::INDEX,
1916-
value: TaggedValue::Color(Table::new_from_element(*color)),
1916+
value: TaggedValue::OptionalColor(Some(*color)),
19171917
}
19181918
.into(),
19191919
Fill::Gradient(gradient) => NodeGraphMessage::SetInputValue {
@@ -2124,7 +2124,7 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
21242124
let miter_limit_disabled = join_value != &StrokeJoin::Miter;
21252125

21262126
let color = color_widget(
2127-
ParameterWidgetsInfo::new(node_id, ColorInput::INDEX, true, context),
2127+
ParameterWidgetsInfo::new(node_id, ColorInput::<Option<Color>>::INDEX, true, context),
21282128
crate::messages::layout::utility_types::widgets::button_widgets::ColorInput::default(),
21292129
);
21302130
let weight = number_widget(ParameterWidgetsInfo::new(node_id, WeightInput::INDEX, true, context), NumberInput::default().unit(" px").min(0.));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl FrontendGraphDataType {
3434
TaggedValue::Graphic(_) => Self::Graphic,
3535
TaggedValue::Raster(_) => Self::Raster,
3636
TaggedValue::Vector(_) => Self::Vector,
37-
TaggedValue::Color(_) => Self::Color,
38-
TaggedValue::Gradient(_) | TaggedValue::GradientTable(_) => Self::Gradient,
37+
TaggedValue::Color(_) | TaggedValue::OptionalColor(_) => Self::Color,
38+
TaggedValue::Gradient(_) | TaggedValue::GradientStops(_) => Self::Gradient,
3939
TaggedValue::String(_) | TaggedValue::VecString(_) => Self::Typography,
4040
_ => Self::General,
4141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl TypeSource {
6666
TaggedValue::Graphic(_) => FrontendGraphDataType::Graphic,
6767
TaggedValue::Raster(_) => FrontendGraphDataType::Raster,
6868
TaggedValue::Vector(_) => FrontendGraphDataType::Vector,
69-
TaggedValue::Color(_) => FrontendGraphDataType::Color,
70-
TaggedValue::Gradient(_) | TaggedValue::GradientTable(_) => FrontendGraphDataType::Gradient,
69+
TaggedValue::Color(_) | TaggedValue::OptionalColor(_) => FrontendGraphDataType::Color,
70+
TaggedValue::Gradient(_) | TaggedValue::GradientStops(_) => FrontendGraphDataType::Gradient,
7171
TaggedValue::String(_) => FrontendGraphDataType::Typography,
7272
_ => FrontendGraphDataType::General,
7373
},

editor/src/messages/portfolio/document_migration.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,31 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
19861986
.set_input(&InputConnector::node(*node_id, 1), NodeInput::value(TaggedValue::ImageData(image), false), network_path);
19871987
}
19881988

1989+
// Migrate Color Value, Fill backup_color, and Stroke color inputs from Color(Table<Color>) to OptionalColor(Option<Color>)
1990+
let color_to_optional_cases: &[(_, usize)] = &[
1991+
(graphene_std::math_nodes::color_value::IDENTIFIER, 1),
1992+
(graphene_std::vector_nodes::fill::IDENTIFIER, 2),
1993+
(graphene_std::vector::stroke::IDENTIFIER, 1),
1994+
];
1995+
for &(ref identifier, input_index) in color_to_optional_cases {
1996+
if reference == DefinitionIdentifier::ProtoNode(identifier.clone())
1997+
&& let Some(NodeInput::Value { tagged_value, .. }) = node.inputs.get(input_index)
1998+
&& let TaggedValue::Color(color) = &**tagged_value
1999+
{
2000+
let color = *color;
2001+
2002+
document.network_interface.set_input(
2003+
&InputConnector::node(*node_id, input_index),
2004+
NodeInput::value(TaggedValue::OptionalColor(Some(color)), false),
2005+
network_path,
2006+
);
2007+
}
2008+
}
2009+
2010+
// Migrate Artboard and Empty Image color inputs from Color(Table<Color>) to Color(Color), which is handled by serde migration already (no-op here)
2011+
2012+
// Migrate GradientTable(Table<GradientStops>) to GradientStops(GradientStops), which is handled by serde migration via alias (no-op here)
2013+
19892014
// ==================================
19902015
// PUT ALL MIGRATIONS ABOVE THIS LINE
19912016
// ==================================

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ macro_rules! tagged_value {
118118
// Tries using the default for the tagged value type. If it not implemented, then uses the default used in document_node_types. If it is not used there, then TaggedValue::None is returned.
119119
Some(match concrete_type.id? {
120120
x if x == TypeId::of::<()>() => TaggedValue::None,
121-
// Table-wrapped types need a single-row default with the element's default, not an empty table
122-
x if x == TypeId::of::<Table<Color>>() => TaggedValue::Color(Table::new_from_element(Color::default())),
123-
x if x == TypeId::of::<Table<GradientStops>>() => TaggedValue::GradientTable(Table::new_from_element(GradientStops::default())),
121+
x if x == TypeId::of::<Table<Color>>() => TaggedValue::OptionalColor(Some(Color::default())),
122+
x if x == TypeId::of::<Option<Color>>() => TaggedValue::OptionalColor(None),
123+
x if x == TypeId::of::<Table<GradientStops>>() => TaggedValue::GradientStops(GradientStops::default()),
124124
$( x if x == TypeId::of::<$ty>() => TaggedValue::$identifier(Default::default()), )*
125125
_ => return None,
126126
})
@@ -202,14 +202,16 @@ tagged_value! {
202202
#[serde(alias = "ArtboardGroup")]
203203
Artboard(Table<Artboard>),
204204
#[serde(deserialize_with = "core_types::misc::migrate_color")] // TODO: Eventually remove this migration document upgrade code
205-
#[serde(alias = "ColorTable", alias = "OptionalColor", alias = "ColorNotInTable")]
206-
Color(Table<Color>),
207-
#[serde(deserialize_with = "graphic_types::vector_types::gradient::migrate_gradient_stops")] // TODO: Eventually remove this migration document upgrade code
208-
#[serde(alias = "GradientPositions", alias = "GradientStops")]
209-
GradientTable(Table<GradientStops>),
210205
// ============
211206
// STRUCT TYPES
212207
// ============
208+
#[serde(alias = "ColorTable", alias = "ColorNotInTable")]
209+
Color(Color),
210+
#[serde(deserialize_with = "core_types::misc::migrate_optional_color")] // TODO: Eventually remove this migration document upgrade code
211+
OptionalColor(Option<Color>),
212+
#[serde(deserialize_with = "graphic_types::vector_types::gradient::migrate_gradient_stops")] // TODO: Eventually remove this migration document upgrade code
213+
#[serde(alias = "GradientPositions", alias = "GradientTable")]
214+
GradientStops(GradientStops),
213215
FVec2(Vec2),
214216
FAffine2(Affine2),
215217
#[serde(alias = "IVec2", alias = "UVec2")]
@@ -397,10 +399,9 @@ impl TaggedValue {
397399
() if ty == TypeId::of::<u32>() => FromStr::from_str(string).map(TaggedValue::U32).ok()?,
398400
() if ty == TypeId::of::<DVec2>() => to_dvec2(string).map(TaggedValue::DVec2)?,
399401
() if ty == TypeId::of::<bool>() => FromStr::from_str(string).map(TaggedValue::Bool).ok()?,
400-
// `Color` (not in a table) is still currently needed by `BlackAndWhiteNode` and `ColorOverlayNode` GPU `shader_node(PerPixelAdjust)` variants
401-
() if ty == TypeId::of::<Color>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
402-
() if ty == TypeId::of::<Table<Color>>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
403-
() if ty == TypeId::of::<Table<GradientStops>>() => to_gradient(string).map(|color| TaggedValue::GradientTable(Table::new_from_element(color)))?,
402+
() if ty == TypeId::of::<Color>() => to_color(string).map(TaggedValue::Color)?,
403+
() if ty == TypeId::of::<Option<Color>>() => TaggedValue::OptionalColor(to_color(string)),
404+
() if ty == TypeId::of::<GradientStops>() => to_gradient(string).map(TaggedValue::GradientStops)?,
404405
() if ty == TypeId::of::<Fill>() => to_color(string).map(|color| TaggedValue::Fill(Fill::solid(color)))?,
405406
() if ty == TypeId::of::<ReferencePoint>() => to_reference_point(string).map(TaggedValue::ReferencePoint)?,
406407
_ => return None,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
7070
#[cfg(feature = "gpu")]
7171
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Raster<GPU>>]),
7272
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Color>]),
73+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Color]),
74+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<Color>]),
75+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GradientStops]),
7376
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<GradientStops>]),
7477
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Image<Color>]),
7578
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => String]),
@@ -137,6 +140,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
137140
// Context nullification
138141
#[cfg(feature = "gpu")]
139142
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &PlatformEditorApi, Context => graphene_std::ContextFeatures]),
143+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => Color, Context => graphene_std::ContextFeatures]),
140144
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate, Context => graphene_std::ContextFeatures]),
141145
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderOutput, Context => graphene_std::ContextFeatures]),
142146
#[cfg(target_family = "wasm")]
@@ -152,6 +156,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
152156
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<Raster<CPU>>]),
153157
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<Color>]),
154158
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
159+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Color]),
160+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Option<Color>]),
161+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => GradientStops]),
155162
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<GradientStops>]),
156163
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Vec<DVec2>]),
157164
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Vec<NodeId>]),

0 commit comments

Comments
 (0)