Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ pub(crate) fn property_from_type(
Some(x) if x == TypeId::of::<String>() => text_widget(default_info).into(),
Some(x) if x == TypeId::of::<DVec2>() => vec2_widget(default_info, "X", "Y", "", None, false),
Some(x) if x == TypeId::of::<DAffine2>() => transform_widget(default_info, &mut extra_widgets),
Some(x) if x == TypeId::of::<Color>() => color_widget(default_info, ColorInput::default()),
Some(x) if x == TypeId::of::<Option<Color>>() => color_widget(default_info, ColorInput::default()),
// ==========================
// PRIMITIVE COLLECTION TYPES
// ==========================
Expand Down Expand Up @@ -926,6 +928,22 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:

// Add the color input
match &**tagged_value {
TaggedValue::ColorNotInTable(color) => widgets.push(
color_button
.value(FillChoice::Solid(*color))
.allow_none(false)
.on_update(update_value(|input: &ColorInput| TaggedValue::ColorNotInTable(input.value.as_solid().unwrap()), node_id, index))
.on_commit(commit_value)
.widget_holder(),
),
TaggedValue::OptionalColorNotInTable(color) => widgets.push(
color_button
.value(color.map_or(FillChoice::None, FillChoice::Solid))
.allow_none(true)
.on_update(update_value(|input: &ColorInput| TaggedValue::OptionalColorNotInTable(input.value.as_solid()), node_id, index))
.on_commit(commit_value)
.widget_holder(),
),
TaggedValue::Color(color_table) => widgets.push(
color_button
.value(match color_table.iter().next() {
Expand Down Expand Up @@ -965,7 +983,7 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
.on_commit(commit_value)
.widget_holder(),
),
_ => {}
x => warn!("Colour {x:?}"),
}

LayoutGroup::Row { widgets }
Expand Down
9 changes: 9 additions & 0 deletions node-graph/graph-craft/src/document/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ tagged_value! {
Bool(bool),
String(String),
OptionalF64(Option<f64>),
ColorNotInTable(Color),
OptionalColorNotInTable(Option<Color>),
// ========================
// LISTS OF PRIMITIVE TYPES
// ========================
Expand Down Expand Up @@ -358,6 +360,8 @@ impl TaggedValue {
x if x == TypeId::of::<DVec2>() => to_dvec2(string).map(TaggedValue::DVec2)?,
x if x == TypeId::of::<bool>() => FromStr::from_str(string).map(TaggedValue::Bool).ok()?,
x if x == TypeId::of::<Table<Color>>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
x if x == TypeId::of::<Color>() => to_color(string).map(|color| TaggedValue::ColorNotInTable(color))?,
x if x == TypeId::of::<Option<Color>>() => TaggedValue::ColorNotInTable(to_color(string)?),
x if x == TypeId::of::<Fill>() => to_color(string).map(|color| TaggedValue::Fill(Fill::solid(color)))?,
x if x == TypeId::of::<ReferencePoint>() => to_reference_point(string).map(TaggedValue::ReferencePoint)?,
_ => return None,
Expand Down Expand Up @@ -512,3 +516,8 @@ mod fake_hash {
}
}
}

#[test]
fn can_construct_color() {
assert_eq!(TaggedValue::from_type(&concrete!(Color)).unwrap(), TaggedValue::ColorNotInTable(Color::default()));
}
5 changes: 1 addition & 4 deletions node-graph/graster-nodes/src/adjustments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn black_and_white<T: Adjust<Color>>(
GradientStops,
)]
mut image: T,
#[default(Color::BLACK)] tint: Table<Color>,
#[default(Color::BLACK)] tint: Color,
#[default(40.)]
#[range((-200., 300.))]
reds: PercentageF32,
Expand All @@ -327,9 +327,6 @@ fn black_and_white<T: Adjust<Color>>(
#[range((-200., 300.))]
magentas: PercentageF32,
) -> T {
let tint: Option<Color> = tint.into();
let tint = tint.unwrap_or(Color::BLACK);

image.adjust(|color| {
let color = color.to_gamma_srgb();

Expand Down
13 changes: 2 additions & 11 deletions node-graph/graster-nodes/src/blending_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,12 @@ fn color_overlay<T: Adjust<Color>>(
GradientStops,
)]
mut image: T,
#[default(Color::BLACK)] color: Table<Color>,
#[default(Color::BLACK)] color: Color,
blend_mode: BlendMode,
#[default(100.)] opacity: PercentageF32,
) -> T {
let opacity = (opacity as f32 / 100.).clamp(0., 1.);

let color: Option<Color> = color.into();
let color = color.unwrap_or(Color::BLACK);

image.adjust(|pixel| {
let image = pixel.map_rgb(|channel| channel * (1. - opacity));

Expand Down Expand Up @@ -206,13 +203,7 @@ mod test {
// 100% of the output should come from the multiplied value
let opacity = 100.;

let result = super::color_overlay(
(),
Table::new_from_element(Raster::new_cpu(image.clone())),
Table::new_from_element(overlay_color),
BlendMode::Multiply,
opacity,
);
let result = super::color_overlay((), Table::new_from_element(Raster::new_cpu(image.clone())), overlay_color, BlendMode::Multiply, opacity);
let result = result.iter().next().unwrap().element;

// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
Expand Down
8 changes: 2 additions & 6 deletions node-graph/gstd/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ fn text<'i: 'n>(
#[unit(" px")]
#[default(0.)]
character_spacing: f64,
#[unit(" px")]
#[default(None)]
max_width: Option<f64>,
#[unit(" px")]
#[default(None)]
max_height: Option<f64>,
#[unit(" px")] max_width: Option<f64>,
#[unit(" px")] max_height: Option<f64>,
/// Faux italic.
#[unit("°")]
#[default(0.)]
Expand Down
1 change: 1 addition & 0 deletions node-graph/preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT OR Apache-2.0"
[features]

[dependencies]
log = { workspace = true }

# Workspace dependencies
graphene-std = { workspace = true, features = ["gpu"] }
Expand Down
12 changes: 11 additions & 1 deletion node-graph/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate log;

use graph_craft::document::value::*;
use graph_craft::document::*;
use graph_craft::proto::RegistryValueSource;
Expand Down Expand Up @@ -150,7 +153,14 @@ pub fn node_inputs(fields: &[registry::FieldMetadata], first_node_io: &NodeIOTyp

match field.value_source {
RegistryValueSource::None => {}
RegistryValueSource::Default(data) => return NodeInput::value(TaggedValue::from_primitive_string(data, ty).unwrap_or(TaggedValue::None), exposed),
RegistryValueSource::Default(data) => {
if let Some(custom_default) = TaggedValue::from_primitive_string(data, ty) {
return NodeInput::value(custom_default, exposed);
} else {
// It is incredibly useful to get a warning when the default type cannot be parsed rather than defaulting to `()`.
warn!("Failed to parse default value for type {ty:?} with data {data}");
}
}
RegistryValueSource::Scope(data) => return NodeInput::scope(Cow::Borrowed(data)),
};

Expand Down
Loading