Skip to content

Commit 9064e64

Browse files
committed
Re-add support for Color and Option<Color>
1 parent 9735bfe commit 9064e64

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ pub(crate) fn property_from_type(
173173
Some(x) if x == TypeId::of::<String>() => text_widget(default_info).into(),
174174
Some(x) if x == TypeId::of::<DVec2>() => vec2_widget(default_info, "X", "Y", "", None, false),
175175
Some(x) if x == TypeId::of::<DAffine2>() => transform_widget(default_info, &mut extra_widgets),
176+
Some(x) if x == TypeId::of::<Color>() => color_widget(default_info, ColorInput::default()),
177+
Some(x) if x == TypeId::of::<Option<Color>>() => color_widget(default_info, ColorInput::default()),
176178
// ==========================
177179
// PRIMITIVE COLLECTION TYPES
178180
// ==========================
@@ -926,6 +928,22 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
926928

927929
// Add the color input
928930
match &**tagged_value {
931+
TaggedValue::ColorNotInTable(color) => widgets.push(
932+
color_button
933+
.value(FillChoice::Solid(*color))
934+
.allow_none(false)
935+
.on_update(update_value(|input: &ColorInput| TaggedValue::ColorNotInTable(input.value.as_solid().unwrap()), node_id, index))
936+
.on_commit(commit_value)
937+
.widget_holder(),
938+
),
939+
TaggedValue::OptionalColorNotInTable(color) => widgets.push(
940+
color_button
941+
.value(color.map_or(FillChoice::None, FillChoice::Solid))
942+
.allow_none(true)
943+
.on_update(update_value(|input: &ColorInput| TaggedValue::OptionalColorNotInTable(input.value.as_solid()), node_id, index))
944+
.on_commit(commit_value)
945+
.widget_holder(),
946+
),
929947
TaggedValue::Color(color_table) => widgets.push(
930948
color_button
931949
.value(match color_table.iter().next() {
@@ -965,7 +983,7 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
965983
.on_commit(commit_value)
966984
.widget_holder(),
967985
),
968-
_ => {}
986+
x => warn!("Colour {x:?}"),
969987
}
970988

971989
LayoutGroup::Row { widgets }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ tagged_value! {
171171
Bool(bool),
172172
String(String),
173173
OptionalF64(Option<f64>),
174+
ColorNotInTable(Color),
175+
OptionalColorNotInTable(Option<Color>),
174176
// ========================
175177
// LISTS OF PRIMITIVE TYPES
176178
// ========================
@@ -358,6 +360,8 @@ impl TaggedValue {
358360
x if x == TypeId::of::<DVec2>() => to_dvec2(string).map(TaggedValue::DVec2)?,
359361
x if x == TypeId::of::<bool>() => FromStr::from_str(string).map(TaggedValue::Bool).ok()?,
360362
x if x == TypeId::of::<Table<Color>>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
363+
x if x == TypeId::of::<Color>() => to_color(string).map(|color| TaggedValue::ColorNotInTable(color))?,
364+
x if x == TypeId::of::<Option<Color>>() => TaggedValue::ColorNotInTable(to_color(string)?),
361365
x if x == TypeId::of::<Fill>() => to_color(string).map(|color| TaggedValue::Fill(Fill::solid(color)))?,
362366
x if x == TypeId::of::<ReferencePoint>() => to_reference_point(string).map(TaggedValue::ReferencePoint)?,
363367
_ => return None,
@@ -512,3 +516,8 @@ mod fake_hash {
512516
}
513517
}
514518
}
519+
520+
#[test]
521+
fn can_construct_color() {
522+
assert_eq!(TaggedValue::from_type(&concrete!(Color)).unwrap(), TaggedValue::ColorNotInTable(Color::default()));
523+
}

0 commit comments

Comments
 (0)