Skip to content

Commit 1d6cbeb

Browse files
committed
Code review
1 parent 3df8d22 commit 1d6cbeb

File tree

15 files changed

+68
-38
lines changed

15 files changed

+68
-38
lines changed

editor/src/messages/portfolio/document/document_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use graphene_core::raster::BlendMode;
1111
use graphene_core::raster::Image;
1212
use graphene_core::vector::style::ViewMode;
1313
use graphene_core::Color;
14-
15-
use glam::DAffine2;
1614
use graphene_std::renderer::ClickTarget;
1715
use graphene_std::transform::Footprint;
1816
use graphene_std::vector::VectorData;
1917

18+
use glam::DAffine2;
19+
2020
#[impl_message(Message, PortfolioMessage, Document)]
2121
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
2222
pub enum DocumentMessage {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,8 @@ impl NodeNetworkInterface {
31053105
};
31063106
node.implementation = implementation;
31073107
}
3108+
3109+
// TODO: Eventually remove this (probably starting late 2024)
31083110
/// Keep metadata in sync with the new implementation if this is used by anything other than the upgrade scripts
31093111
pub fn replace_implementation_metadata(&mut self, node_id: &NodeId, network_path: &[NodeId], metadata: DocumentNodePersistentMetadata) {
31103112
let Some(network_metadata) = self.network_metadata_mut(network_path) else {

editor/src/messages/tool/tool_messages/select_tool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ impl Fsm for SelectToolFsmState {
533533

534534
edges
535535
});
536+
536537
let rotating_bounds = tool_data
537538
.bounding_box_manager
538539
.as_ref()
@@ -640,6 +641,7 @@ impl Fsm for SelectToolFsmState {
640641
tool_data.layers_dragging = selected;
641642

642643
tool_data.get_snap_candidates(document, input);
644+
643645
SelectToolFsmState::Dragging
644646
}
645647
// Dragging a selection box
@@ -652,7 +654,6 @@ impl Fsm for SelectToolFsmState {
652654
}
653655

654656
if let Some(intersection) = intersection {
655-
656657
tool_data.layer_selected_on_start = Some(intersection);
657658
selected = intersection_list;
658659

@@ -661,6 +662,7 @@ impl Fsm for SelectToolFsmState {
661662
_ => drag_deepest_manipulation(responses, selected, tool_data, document),
662663
}
663664
tool_data.get_snap_candidates(document, input);
665+
664666
responses.add(DocumentMessage::StartTransaction);
665667
SelectToolFsmState::Dragging
666668
} else {

editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformL
8787
*mouse_position = input.mouse.position;
8888
*start_mouse = input.mouse.position;
8989
selected.original_transforms.clear();
90+
91+
selected.responses.add(DocumentMessage::StartTransaction);
9092
};
9193

9294
match message {
@@ -97,6 +99,7 @@ impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformL
9799

98100
self.transform_operation = TransformOperation::None;
99101

102+
responses.add(DocumentMessage::EndTransaction);
100103
responses.add(ToolMessage::UpdateHints);
101104
responses.add(NodeGraphMessage::RunDocumentGraph);
102105
}
@@ -156,6 +159,7 @@ impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformL
156159

157160
self.transform_operation = TransformOperation::None;
158161

162+
responses.add(DocumentMessage::AbortTransaction);
159163
responses.add(ToolMessage::UpdateHints);
160164
}
161165
TransformLayerMessage::ConstrainX => self.transform_operation.constrain_axis(Axis::X, &mut selected, self.snap),

frontend/src/components/panels/Layers.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@
499499
500500
// Dimming
501501
&.selected {
502-
// Halfway between 3-darkgray and 4-dimgray (this interpolation approach only works on grayscale values)
503-
--component: calc((Max(var(--color-3-darkgray-rgb)) + Max(var(--color-4-dimgray-rgb))) / 2);
502+
// 1/3 between 3-darkgray and 4-dimgray (this interpolation approach only works on grayscale values)
503+
--component: calc((Max(var(--color-3-darkgray-rgb)) * 2 + Max(var(--color-4-dimgray-rgb))) / 3);
504504
background: rgb(var(--component), var(--component), var(--component));
505505
506506
&.full-highlight {

node-graph/gcore/src/graphic_element.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ impl AlphaBlending {
4343
#[derive(Clone, Debug, PartialEq, DynAny, Default)]
4444
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4545
pub struct GraphicGroup {
46-
// TODO: Convert to spread sheet format
4746
elements: Vec<(GraphicElement, Option<NodeId>)>,
48-
// TODO: Convert to Vec<DAffine2>
4947
pub transform: DAffine2,
50-
// TODO: Convert to Vec<AlphaBlending>
5148
pub alpha_blending: AlphaBlending,
5249
}
5350

@@ -258,7 +255,8 @@ async fn construct_layer<Data: Into<GraphicElement> + Send>(
258255
stack.transform = DAffine2::IDENTITY;
259256
}
260257

261-
let encapsulating_node_id = node_path.get(node_path.len() - 2).cloned();
258+
// Get the penultimate element of the node path, or None if the path is too short
259+
let encapsulating_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
262260
stack.push((element, encapsulating_node_id));
263261
stack
264262
}
@@ -324,10 +322,8 @@ async fn add_artboard<Data: Into<Artboard> + Send>(
324322
let artboard = self.artboard.eval(footprint).await;
325323
let mut artboards = self.artboards.eval(footprint).await;
326324

327-
let encapsulating_node_id = match node_path.len() {
328-
len if len >= 2 => node_path.get(len - 2).cloned(),
329-
_ => None,
330-
};
325+
// Get the penultimate element of the node path, or None if the path is too short
326+
let encapsulating_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
331327
artboards.add_artboard(artboard.into(), encapsulating_node_id);
332328

333329
artboards

node-graph/gcore/src/graphic_element/renderer.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod quad;
22
mod rect;
3-
use dyn_any::DynAny;
43
pub use quad::Quad;
54
pub use rect::Rect;
65

@@ -13,6 +12,7 @@ use crate::Raster;
1312
use crate::{vector::VectorData, Artboard, Color, GraphicElement, GraphicGroup};
1413

1514
use bezier_rs::Subpath;
15+
use dyn_any::{DynAny, StaticType};
1616

1717
use base64::Engine;
1818
use glam::{DAffine2, DVec2};
@@ -270,7 +270,6 @@ pub fn to_transform(transform: DAffine2) -> usvg::Transform {
270270
usvg::Transform::from_row(cols[0] as f32, cols[1] as f32, cols[2] as f32, cols[3] as f32, cols[4] as f32, cols[5] as f32)
271271
}
272272

273-
use dyn_any::StaticType;
274273
#[derive(Debug, Clone, PartialEq, DynAny)]
275274
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
276275
pub struct RenderMetadata {
@@ -281,19 +280,25 @@ pub struct RenderMetadata {
281280

282281
pub trait GraphicElementRendered {
283282
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);
283+
284284
fn bounding_box(&self, transform: DAffine2) -> Option<[DVec2; 2]>;
285+
285286
// The upstream click targets for each layer are collected during the render so that they do not have to be calculated for each click detection
286287
fn add_upstream_click_targets(&self, _click_targets: &mut Vec<ClickTarget>) {}
288+
287289
// TODO: Store all click targets in a vec which contains the AABB, click target, and path
288290
// fn add_click_targets(&self, click_targets: &mut Vec<([DVec2; 2], ClickTarget, Vec<NodeId>)>, current_path: Option<NodeId>) {}
291+
289292
// Recursively iterate over data in the render (including groups upstream from vector data in the case of a boolean operation) to collect the footprints, click targets, and vector modify
290293
fn collect_metadata(&self, _metadata: &mut RenderMetadata, _footprint: Footprint, _element_id: Option<NodeId>) {}
294+
291295
#[cfg(feature = "vello")]
292296
fn to_vello_scene(&self, transform: DAffine2, context: &mut RenderContext) -> Scene {
293297
let mut scene = vello::Scene::new();
294298
self.render_to_vello(&mut scene, transform, context);
295299
scene
296300
}
301+
297302
#[cfg(feature = "vello")]
298303
fn render_to_vello(&self, _scene: &mut Scene, _transform: DAffine2, _render_condext: &mut RenderContext) {}
299304

@@ -334,11 +339,13 @@ impl GraphicElementRendered for GraphicGroup {
334339

335340
fn collect_metadata(&self, metadata: &mut RenderMetadata, mut footprint: Footprint, element_id: Option<NodeId>) {
336341
footprint.transform *= self.transform;
342+
337343
for (element, element_id) in self.elements.iter() {
338344
if let Some(element_id) = element_id {
339345
element.collect_metadata(metadata, footprint, Some(*element_id));
340346
}
341347
}
348+
342349
if let Some(graphic_group_id) = element_id {
343350
let mut all_upstream_click_targets = Vec::new();
344351
self.add_upstream_click_targets(&mut all_upstream_click_targets);
@@ -349,10 +356,13 @@ impl GraphicElementRendered for GraphicGroup {
349356
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
350357
for (element, _) in self.elements.iter() {
351358
let mut new_click_targets = Vec::new();
359+
352360
element.add_upstream_click_targets(&mut new_click_targets);
361+
353362
for click_target in new_click_targets.iter_mut() {
354363
click_target.apply_transform(element.transform())
355364
}
365+
356366
click_targets.extend(new_click_targets);
357367
}
358368
}
@@ -374,9 +384,11 @@ impl GraphicElementRendered for GraphicGroup {
374384
&vello::kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y),
375385
);
376386
}
387+
377388
for (element, _) in self.iter() {
378389
element.render_to_vello(scene, child_transform, context);
379390
}
391+
380392
if layer {
381393
scene.pop_layer();
382394
}
@@ -447,6 +459,7 @@ impl GraphicElementRendered for VectorData {
447459
.insert(element_id, self.stroke_bezier_paths().map(fill).map(|subpath| ClickTarget::new(subpath, stroke_width)).collect());
448460
metadata.vector_data.insert(element_id, self.clone());
449461
}
462+
450463
if let Some(upstream_graphic_group) = &self.upstream_graphic_group {
451464
footprint.transform *= self.transform;
452465
upstream_graphic_group.collect_metadata(metadata, footprint, None);
@@ -615,7 +628,7 @@ impl GraphicElementRendered for Artboard {
615628

616629
write!(
617630
&mut attributes.0.svg_defs,
618-
r##"<clipPath id="{id}"><rect x="0" y="0" width="{}" height="{}"/></clipPath>"##,
631+
r##"<clipPath id="{id}"><rect x="0" y="0" width="{}" height="{}" /></clipPath>"##,
619632
self.dimensions.x, self.dimensions.y
620633
)
621634
.unwrap();
@@ -644,11 +657,13 @@ impl GraphicElementRendered for Artboard {
644657
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
645658
metadata.footprints.insert(element_id, (footprint, DAffine2::from_translation(self.location.as_dvec2())));
646659
}
660+
647661
self.graphic_group.collect_metadata(metadata, footprint, None);
648662
}
649663

650664
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
651665
let mut subpath = Subpath::new_rect(DVec2::ZERO, self.dimensions.as_dvec2());
666+
652667
if self.graphic_group.transform.matrix2.determinant() != 0. {
653668
subpath.apply_transform(self.graphic_group.transform.inverse());
654669
click_targets.push(ClickTarget::new(subpath, 0.));
@@ -690,6 +705,7 @@ impl GraphicElementRendered for crate::ArtboardGroup {
690705
artboard.render_svg(render, render_params);
691706
}
692707
}
708+
693709
fn bounding_box(&self, transform: DAffine2) -> Option<[DVec2; 2]> {
694710
self.artboards.iter().filter_map(|(element, _)| element.bounding_box(transform)).reduce(Quad::combine_bounds)
695711
}
@@ -760,11 +776,11 @@ impl GraphicElementRendered for ImageFrame<Color> {
760776
}
761777

762778
fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option<NodeId>) {
763-
if let Some(element_id) = element_id {
764-
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
765-
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
766-
metadata.footprints.insert(element_id, (footprint, self.transform));
767-
}
779+
let Some(element_id) = element_id else { return };
780+
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
781+
782+
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
783+
metadata.footprints.insert(element_id, (footprint, self.transform));
768784
}
769785

770786
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
@@ -838,11 +854,11 @@ impl GraphicElementRendered for Raster {
838854
}
839855

840856
fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option<NodeId>) {
841-
if let Some(element_id) = element_id {
842-
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
843-
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
844-
metadata.footprints.insert(element_id, (footprint, self.transform()));
845-
}
857+
let Some(element_id) = element_id else { return };
858+
859+
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
860+
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
861+
metadata.footprints.insert(element_id, (footprint, self.transform()));
846862
}
847863

848864
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
@@ -911,6 +927,7 @@ impl GraphicElementRendered for GraphicElement {
911927
if let Some(element_id) = element_id {
912928
metadata.footprints.insert(element_id, (footprint, self.transform()));
913929
}
930+
914931
match self {
915932
GraphicElement::VectorData(vector_data) => vector_data.collect_metadata(metadata, footprint, element_id),
916933
GraphicElement::Raster(raster) => raster.collect_metadata(metadata, footprint, element_id),

node-graph/gcore/src/uuid.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
pub use uuid_generation::*;
2+
3+
use dyn_any::DynAny;
4+
use dyn_any::StaticType;
5+
16
#[derive(Clone, Copy, serde::Serialize, serde::Deserialize, specta::Type)]
27
pub struct Uuid(
38
#[serde(with = "u64_string")]
@@ -66,10 +71,6 @@ mod uuid_generation {
6671
}
6772
}
6873

69-
use dyn_any::DynAny;
70-
use dyn_any::StaticType;
71-
pub use uuid_generation::*;
72-
7374
#[repr(transparent)]
7475
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type, DynAny)]
7576
pub struct NodeId(pub u64);

node-graph/gcore/src/vector/style.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,12 @@ impl PathStyle {
742742
self.fill = fill;
743743
}
744744

745+
pub fn set_stroke_transform(&mut self, transform: DAffine2) {
746+
if let Some(stroke) = &mut self.stroke {
747+
stroke.transform = transform;
748+
}
749+
}
750+
745751
/// Replace the path's [Stroke] with a provided one.
746752
///
747753
/// # Example

node-graph/gcore/src/vector/vector_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct VectorData {
2828
pub segment_domain: SegmentDomain,
2929
pub region_domain: RegionDomain,
3030

31-
// Used to store the upstream graphic group during destructive Boolean Operations so that click targets can be preserved.
31+
// Used to store the upstream graphic group during destructive Boolean Operations (and other nodes with a similar effect) so that click targets can be preserved.
3232
pub upstream_graphic_group: Option<crate::GraphicGroup>,
3333
}
3434

0 commit comments

Comments
 (0)