Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Keavon committed Jan 21, 2025
1 parent e5cc11b commit 07ef5c9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use graph_craft::document::*;
use graph_craft::imaginate_input::ImaginateSamplingMethod;
use graph_craft::ProtoNodeIdentifier;
use graphene_core::raster::brush_cache::BrushCache;
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, Image, ImageFrame, NoiseType, RedGreenBlue, RedGreenBlueAlpha};
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, ImageFrame, NoiseType, RedGreenBlue, RedGreenBlueAlpha};
use graphene_core::text::{Font, TypesettingConfig};
use graphene_core::transform::Footprint;
use graphene_core::vector::VectorData;
Expand Down Expand Up @@ -2922,12 +2922,13 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
properties: None, // Some(&node_properties::imaginate_properties),
});

pub static NODE_OVERRIDES: once_cell::sync::Lazy<HashMap<String, Box<dyn Fn(NodeId, &mut NodePropertiesContext) -> Vec<LayoutGroup> + Send + Sync>>> =
once_cell::sync::Lazy::new(static_node_properties);
type NodeProperties = HashMap<String, Box<dyn Fn(NodeId, &mut NodePropertiesContext) -> Vec<LayoutGroup> + Send + Sync>>;

pub static NODE_OVERRIDES: once_cell::sync::Lazy<NodeProperties> = once_cell::sync::Lazy::new(static_node_properties);

/// Defines the logic for inputs to display a custom properties panel widget.
fn static_node_properties() -> HashMap<String, Box<dyn Fn(NodeId, &mut NodePropertiesContext) -> Vec<LayoutGroup> + Send + Sync>> {
let mut map: HashMap<String, Box<dyn Fn(NodeId, &mut NodePropertiesContext) -> Vec<LayoutGroup> + Send + Sync>> = HashMap::new();
fn static_node_properties() -> NodeProperties {
let mut map: NodeProperties = HashMap::new();
map.insert("channel_mixer_properties".to_string(), Box::new(node_properties::channel_mixer_properties));
map.insert("fill_properties".to_string(), Box::new(node_properties::fill_properties));
map.insert("stroke_properties".to_string(), Box::new(node_properties::stroke_properties));
Expand All @@ -2938,21 +2939,22 @@ fn static_node_properties() -> HashMap<String, Box<dyn Fn(NodeId, &mut NodePrope
map.insert("rectangle_properties".to_string(), Box::new(node_properties::rectangle_properties));
map.insert(
"identity_properties".to_string(),
Box::new(|_node_id, _context| node_properties::string_properties("The identity node simply passes its data through.".to_string())),
Box::new(|_node_id, _context| node_properties::string_properties("The identity node simply passes its data through.")),
);
map.insert(
"monitor_properties".to_string(),
Box::new(|_node_id, _context| node_properties::string_properties("The Monitor node is used by the editor to access the data flowing through it.".to_string())),
Box::new(|_node_id, _context| node_properties::string_properties("The Monitor node is used by the editor to access the data flowing through it.")),
);
map
}

static INPUT_OVERRIDES: once_cell::sync::Lazy<HashMap<String, Box<dyn Fn(NodeId, usize, &mut NodePropertiesContext) -> Result<Vec<LayoutGroup>, String> + Send + Sync>>> =
once_cell::sync::Lazy::new(static_input_properties);
type InputProperties = HashMap<String, Box<dyn Fn(NodeId, usize, &mut NodePropertiesContext) -> Result<Vec<LayoutGroup>, String> + Send + Sync>>;

static INPUT_OVERRIDES: once_cell::sync::Lazy<InputProperties> = once_cell::sync::Lazy::new(static_input_properties);

/// Defines the logic for inputs to display a custom properties panel widget.
fn static_input_properties() -> HashMap<String, Box<dyn Fn(NodeId, usize, &mut NodePropertiesContext) -> Result<Vec<LayoutGroup>, String> + Send + Sync>> {
let mut map: HashMap<String, Box<dyn Fn(NodeId, usize, &mut NodePropertiesContext) -> Result<Vec<LayoutGroup>, String> + Send + Sync>> = HashMap::new();
fn static_input_properties() -> InputProperties {
let mut map: InputProperties = HashMap::new();
map.insert("hidden".to_string(), Box::new(|_node_id, _index, _context| Ok(Vec::new())));
map.insert(
"string".to_string(),
Expand All @@ -2963,7 +2965,7 @@ fn static_input_properties() -> HashMap<String, Box<dyn Fn(NodeId, usize, &mut N
let Some(string) = value.as_str() else {
return Err(format!("Could not downcast string properties for node {}", node_id));
};
Ok(node_properties::string_properties(string.to_string()))
Ok(node_properties::string_properties(string))
}),
);
map.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1989,10 +1989,11 @@ impl NodeGraphMessageHandler {
.collect::<Vec<_>>()
.iter()
.filter_map(|node_id| {
context
.network_interface
.is_pinned(node_id, context.selection_network_path)
.then(|| node_properties::generate_node_properties(*node_id, context))
if context.network_interface.is_pinned(node_id, context.selection_network_path) {
Some(node_properties::generate_node_properties(*node_id, context))
} else {
None
}
})
.collect::<Vec<_>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#![allow(clippy::too_many_arguments)]

use super::document_node_definitions::{NodePropertiesContext, IMAGINATE_NODE, NODE_OVERRIDES};
use super::document_node_definitions::{NodePropertiesContext, NODE_OVERRIDES};
use super::utility_types::FrontendGraphDataType;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::utility_types::network_interface::InputConnector;
use crate::messages::prelude::*;

use graph_craft::document::value::TaggedValue;
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod, ImaginateServerStatus, ImaginateStatus};
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod};
use graph_craft::Type;
use graphene_core::memo::IORecord;
use graphene_core::raster::curve::Curve;
use graphene_core::raster::{
BlendMode, CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, ImageFrame, LuminanceCalculation, NoiseType, RedGreenBlue, RedGreenBlueAlpha, RelativeAbsolute,
Expand All @@ -28,7 +27,7 @@ use graphene_std::{GraphicGroup, Raster};

use glam::{DAffine2, DVec2, IVec2, UVec2};

pub(crate) fn string_properties(text: String) -> Vec<LayoutGroup> {
pub(crate) fn string_properties(text: &str) -> Vec<LayoutGroup> {
let widget = TextLabel::new(text).widget_holder();
vec![LayoutGroup::Row { widgets: vec![widget] }]
}
Expand Down Expand Up @@ -2090,11 +2089,12 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
// }

pub(crate) fn node_no_properties(node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
string_properties(if context.network_interface.is_layer(&node_id, context.selection_network_path) {
"Layer has no properties".to_string()
let text = if context.network_interface.is_layer(&node_id, context.selection_network_path) {
"Layer has no properties"
} else {
"Node has no properties".to_string()
})
"Node has no properties"
};
string_properties(text)
}

pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodePropertiesContext) -> LayoutGroup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3722,30 +3722,30 @@ impl NodeNetworkInterface {
return;
};
for downstream_connection in &outward_wires {
self.disconnect_input(downstream_connection, &network_path);
self.create_wire(&OutputConnector::Import(shift_output_down - 1), downstream_connection, &network_path);
self.disconnect_input(downstream_connection, network_path);
self.create_wire(&OutputConnector::Import(shift_output_down - 1), downstream_connection, network_path);
}
}
// Node inputs at or above the end index should be shifted up one
for shift_output_up in (end_index..last_import_index).rev() {
let Some(outward_wires) = self
.outward_wires(&network_path)
.outward_wires(network_path)
.and_then(|outward_wires| outward_wires.get(&OutputConnector::Import(shift_output_up)))
.cloned()
else {
log::error!("Could not get outward wires in reorder_import");
return;
};
for downstream_connection in &outward_wires {
self.disconnect_input(downstream_connection, &network_path);
self.create_wire(&OutputConnector::Import(shift_output_up + 1), downstream_connection, &network_path);
self.disconnect_input(downstream_connection, network_path);
self.create_wire(&OutputConnector::Import(shift_output_up + 1), downstream_connection, network_path);
}
}

// Move the connections to the moved export after all other ones have been shifted
for downstream_connection in &move_to_end_index {
self.disconnect_input(downstream_connection, &network_path);
self.create_wire(&OutputConnector::Import(end_index), downstream_connection, &network_path);
self.disconnect_input(downstream_connection, network_path);
self.create_wire(&OutputConnector::Import(end_index), downstream_connection, network_path);
}

// Update the metadata for the current network
Expand Down
5 changes: 4 additions & 1 deletion editor/src/messages/tool/tool_messages/pen_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,10 @@ impl Fsm for PenToolFsmState {
(_, PenToolMessage::Redo) => {
tool_data.point_index = (tool_data.point_index + 1).min(tool_data.latest_points.len().saturating_sub(1));
tool_data.place_anchor(SnapData::new(document, input), transform, input.mouse.position, responses);
(tool_data.point_index == 0).then_some(PenToolFsmState::Ready).unwrap_or(PenToolFsmState::PlacingAnchor)
match tool_data.point_index {
0 => PenToolFsmState::Ready,
_ => PenToolFsmState::PlacingAnchor,
}
}
_ => self,
}
Expand Down

0 comments on commit 07ef5c9

Please sign in to comment.