Skip to content
Closed
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 @@ -11,9 +11,9 @@ use graphene_std::Context;
use graphene_std::gradient::GradientStops;
use graphene_std::memo::IORecord;
use graphene_std::raster_types::{CPU, GPU, Raster};
use graphene_std::table::Table;
use graphene_std::table::{CustomColumnValue, Table};
use graphene_std::vector::Vector;
use graphene_std::vector::style::{Fill, FillChoice};
use graphene_std::vector::style::{Fill, FillChoice, GRADIENT_SPREAD_METHOD_KEY, GRADIENT_TYPE_KEY};
use graphene_std::{Artboard, Graphic};
use std::any::Any;
use std::sync::Arc;
Expand Down Expand Up @@ -204,6 +204,9 @@ trait TableRowLayout {
fn element_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
vec![]
}
fn format_column_value(_key: &str, value: &CustomColumnValue) -> String {
format!("{value:?}")
}
}

impl<T: TableRowLayout> TableRowLayout for Vec<T> {
Expand Down Expand Up @@ -258,23 +261,35 @@ impl<T: TableRowLayout> TableRowLayout for Table<T> {
}
}

let additional_keys = self.additional_column_keys();

let mut rows = self
.iter()
.enumerate()
.map(|(index, row)| {
vec![
let mut data = vec![
TextLabel::new(format!("{index}")).narrow(true).widget_instance(),
row.element.element_widget(index),
TextLabel::new(format_transform_matrix(row.transform)).narrow(true).widget_instance(),
TextLabel::new(format!("{}", row.alpha_blending)).narrow(true).widget_instance(),
TextLabel::new(row.source_node_id.map_or_else(|| "-".to_string(), |id| format!("{}", id.0)))
.narrow(true)
.widget_instance(),
]
];

for key in &additional_keys {
let value = *(row.additional.get(key).unwrap_or(&&CustomColumnValue::None));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using unwrap_or with a reference to a reference (&&CustomColumnValue::None) is unnecessary and can be simplified to unwrap_or(&CustomColumnValue::None).

Suggested change
let value = *(row.additional.get(key).unwrap_or(&&CustomColumnValue::None));
let value = row.additional.get(key).unwrap_or(&CustomColumnValue::None);

let formatted_value = T::format_column_value(key, value);
log::debug!("formatted_value {}", formatted_value);
data.push(TextLabel::new(formatted_value).narrow(true).widget_instance());
}
data
})
.collect::<Vec<_>>();

rows.insert(0, column_headings(&["", "element", "transform", "alpha_blending", "source_node_id"]));
let mut headings = vec!["", "element", "transform", "alpha_blending", "source_node_id"];
headings.extend(additional_keys);
rows.insert(0, column_headings(headings.as_slice()));

vec![LayoutGroup::table(rows, false)]
}
Expand Down Expand Up @@ -574,6 +589,16 @@ impl TableRowLayout for GradientStops {
let widgets = vec![self.element_widget(0)];
vec![LayoutGroup::row(widgets)]
}
fn format_column_value(key: &str, value: &CustomColumnValue) -> String {
match (key, value) {
(GRADIENT_TYPE_KEY, CustomColumnValue::U32(0)) => "Linear".to_string(),
(GRADIENT_TYPE_KEY, CustomColumnValue::U32(1)) => "Radial".to_string(),
(GRADIENT_SPREAD_METHOD_KEY, CustomColumnValue::U32(0)) => "Pad".to_string(),
(GRADIENT_SPREAD_METHOD_KEY, CustomColumnValue::U32(1)) => "Reflect".to_string(),
(GRADIENT_SPREAD_METHOD_KEY, CustomColumnValue::U32(2)) => "Repeat".to_string(),
_ => format!("{value:?}"),
}
}
}

impl TableRowLayout for f64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use graphene_std::raster_types::{CPU, Raster};
use graphene_std::subpath::Subpath;
use graphene_std::table::Table;
use graphene_std::text::{Font, TypesettingConfig};
use graphene_std::vector::PointId;
use graphene_std::vector::VectorModificationType;
use graphene_std::vector::style::{Fill, Stroke};
use graphene_std::vector::style::{Fill, GradientSpreadMethod, Stroke};
use graphene_std::vector::{GradientStops, GradientType, PointId, VectorModificationType};
use graphene_std::{Artboard, Color};

#[impl_message(Message, DocumentMessage, GraphOperation)]
Expand All @@ -26,6 +25,13 @@ pub enum GraphOperationMessage {
layer: LayerNodeIdentifier,
fill: f64,
},
GradientTableSet {
layer: LayerNodeIdentifier,
stops: GradientStops,
transform: DAffine2,
gradient_type: GradientType,
spread_method: GradientSpreadMethod,
},
OpacitySet {
layer: LayerNodeIdentifier,
opacity: f64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
modify_inputs.blending_fill_set(fill);
}
}
GraphOperationMessage::GradientTableSet {
layer,
stops,
transform,
gradient_type,
spread_method,
} => {
if let Some(mut modify_inputs) = ModifyInputsContext::new_with_layer(layer, network_interface, responses) {
modify_inputs.gradient_table_set(stops, transform, gradient_type, spread_method);
}
}
GraphOperationMessage::OpacitySet { layer, opacity } => {
if let Some(mut modify_inputs) = ModifyInputsContext::new_with_layer(layer, network_interface, responses) {
modify_inputs.opacity_set(opacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use graphene_std::brush::brush_stroke::BrushStroke;
use graphene_std::raster::BlendMode;
use graphene_std::raster_types::{CPU, Raster};
use graphene_std::subpath::Subpath;
use graphene_std::table::Table;
use graphene_std::table::{Table, TableRow};
use graphene_std::text::{Font, TypesettingConfig};
use graphene_std::vector::Vector;
use graphene_std::vector::style::{Fill, Stroke};
use graphene_std::vector::{PointId, VectorModificationType};
use graphene_std::vector::style::{Fill, GradientSpreadMethod, GradientTableRowExt, Stroke};
use graphene_std::vector::{GradientStops, GradientType, PointId, Vector, VectorModificationType};
use graphene_std::{Artboard, Color, Graphic, NodeInputDecleration};

#[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -457,6 +456,16 @@ impl<'a> ModifyInputsContext<'a> {
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(fill * 100.), false), false);
}

pub fn gradient_table_set(&mut self, stops: GradientStops, transform: DAffine2, gradient_type: GradientType, spread_method: GradientSpreadMethod) {
let Some(gradient_node_id) = self.existing_proto_node_id(graphene_std::math_nodes::gradient_value::IDENTIFIER, true) else {
return;
};

let table = Table::new_from_row(TableRow::new_gradient_row(stops, transform, gradient_type, spread_method));
let input_connector = InputConnector::node(gradient_node_id, 1);
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::GradientTable(table), false), false);
}

pub fn clip_mode_toggle(&mut self, clip_mode: Option<bool>) {
let clip = !clip_mode.unwrap_or(false);
let Some(clip_node_id) = self.existing_proto_node_id(graphene_std::blending_nodes::blending::IDENTIFIER, true) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,20 +1153,37 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
.on_commit(commit_value)
.widget_instance(),
),
TaggedValue::GradientTable(gradient_table) => widgets.push(
color_button
.value(match gradient_table.iter().next() {
Some(row) => FillChoice::Gradient(row.element.clone()),
None => FillChoice::Gradient(GradientStops::default()),
})
.on_update(update_value(
|input: &ColorInput| TaggedValue::GradientTable(input.value.as_gradient().iter().map(|&gradient| TableRow::new_from_element(gradient.clone())).collect()),
node_id,
index,
))
.on_commit(commit_value)
.widget_instance(),
),
TaggedValue::GradientTable(gradient_table) => {
let existing_transform = gradient_table.iter().next().map(|row| *row.transform).unwrap_or_default();

widgets.push(
color_button
.value(match gradient_table.iter().next() {
Some(row) => FillChoice::Gradient(row.element.clone()),
None => FillChoice::Gradient(GradientStops::default()),
})
.on_update(update_value(
move |input: &ColorInput| {
TaggedValue::GradientTable(
input
.value
.as_gradient()
.iter()
.map(|&gradient| TableRow {
element: gradient.clone(),
transform: existing_transform,
..Default::default()
})
.collect(),
)
},
node_id,
index,
))
.on_commit(commit_value)
.widget_instance(),
)
}
x => warn!("Color {x:?}"),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use graphene_std::table::Table;
use graphene_std::text::{Font, TypesettingConfig};
use graphene_std::vector::misc::ManipulatorPointId;
use graphene_std::vector::style::{Fill, Gradient};
use graphene_std::vector::{PointId, SegmentId, VectorModificationType};
use graphene_std::vector::{GradientStops, PointId, SegmentId, VectorModificationType};
use std::collections::VecDeque;

/// Returns the ID of the first Spline node in the horizontal flow which is not followed by a `Path` node, or `None` if none exists.
Expand Down Expand Up @@ -285,6 +285,17 @@ pub fn get_gradient(layer: LayerNodeIdentifier, network_interface: &NodeNetworkI
Some(gradient.clone())
}

/// Get the gradient table of a layer.
pub fn get_gradient_table(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<Table<GradientStops>> {
let gradient_table_index = 1;

let inputs = NodeGraphLayer::new(layer, network_interface).find_node_inputs(&DefinitionIdentifier::ProtoNode(graphene_std::math_nodes::gradient_value::IDENTIFIER))?;
let TaggedValue::GradientTable(gradient_table) = inputs.get(gradient_table_index)?.as_value()? else {
return None;
};
Some(gradient_table.clone())
}

/// Get the current fill of a layer from the closest "Fill" node.
pub fn get_fill_color(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<Color> {
let fill_index = 1;
Expand Down
Loading