mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 02:08:12 +08:00
Replace responses.push() with responses.add() everywhere (#1186)
This commit is contained in:
@@ -17,16 +17,13 @@ pub fn new_vector_layer(subpaths: Vec<Subpath<ManipulatorGroupId>>, layer_path:
|
||||
}
|
||||
|
||||
pub fn new_custom_layer(network: NodeNetwork, layer_path: Vec<LayerId>, responses: &mut VecDeque<Message>) {
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
responses.push_back(
|
||||
Operation::AddNodeGraphFrame {
|
||||
path: layer_path.clone(),
|
||||
insert_index: -1,
|
||||
transform: DAffine2::ZERO.to_cols_array(),
|
||||
network,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
responses.add(DocumentMessage::DeselectAllLayers);
|
||||
responses.add(Operation::AddNodeGraphFrame {
|
||||
path: layer_path.clone(),
|
||||
insert_index: -1,
|
||||
transform: DAffine2::ZERO.to_cols_array(),
|
||||
network,
|
||||
});
|
||||
responses.add(DocumentMessage::NodeGraphFrameGenerate { layer_path });
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ impl OverlayRenderer {
|
||||
insert_index: -1,
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
layer_path
|
||||
}
|
||||
@@ -177,7 +177,7 @@ impl OverlayRenderer {
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 2.0)), Fill::solid(Color::WHITE)),
|
||||
insert_index: -1,
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
layer_path
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ impl OverlayRenderer {
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 2.0)), Fill::solid(Color::WHITE)),
|
||||
insert_index: -1,
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
layer_path
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl OverlayRenderer {
|
||||
/// Remove an overlay at the specified path
|
||||
fn remove_overlay(path: Option<Vec<LayerId>>, responses: &mut VecDeque<Message>) {
|
||||
if let Some(path) = path {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path }.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ impl OverlayRenderer {
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), Fill::None),
|
||||
insert_index: -1,
|
||||
};
|
||||
responses.push_front(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add_front(DocumentMessage::Overlays(operation.into()));
|
||||
layer_path
|
||||
}
|
||||
|
||||
@@ -226,12 +226,12 @@ impl OverlayRenderer {
|
||||
|
||||
fn place_outline_overlays(outline_path: Vec<LayerId>, parent_transform: &DAffine2, responses: &mut VecDeque<Message>) {
|
||||
let transform_message = Self::overlay_transform_message(outline_path, parent_transform.to_cols_array());
|
||||
responses.push_back(transform_message);
|
||||
responses.add(transform_message);
|
||||
}
|
||||
|
||||
fn modify_outline_overlays(outline_path: Vec<LayerId>, subpath: graphene_core::vector::Subpath, responses: &mut VecDeque<Message>) {
|
||||
let outline_modify_message = Self::overlay_modify_message(outline_path, subpath);
|
||||
responses.push_back(outline_modify_message);
|
||||
responses.add(outline_modify_message);
|
||||
}
|
||||
|
||||
/// Updates the position of the overlays based on the [Subpath] points.
|
||||
@@ -245,7 +245,7 @@ impl OverlayRenderer {
|
||||
|
||||
let translation = (parent_transform.transform_point2(handle_position) + VIEWPORT_GRID_ROUNDING_BIAS).round() + DVec2::splat(0.5);
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, angle, translation).to_cols_array();
|
||||
responses.push_back(Self::overlay_transform_message(line_overlay.to_vec(), transform));
|
||||
responses.add(Self::overlay_transform_message(line_overlay.to_vec(), transform));
|
||||
|
||||
let marker_overlay = marker_source.take().unwrap_or_else(|| Self::create_handle_overlay(responses));
|
||||
|
||||
@@ -254,7 +254,7 @@ impl OverlayRenderer {
|
||||
let translation = (parent_transform.transform_point2(handle_position) - (scale / 2.) + VIEWPORT_GRID_ROUNDING_BIAS).round();
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, angle, translation).to_cols_array();
|
||||
|
||||
responses.push_back(Self::overlay_transform_message(marker_overlay.clone(), transform));
|
||||
responses.add(Self::overlay_transform_message(marker_overlay.clone(), transform));
|
||||
|
||||
*marker_source = Some(marker_overlay);
|
||||
};
|
||||
@@ -275,7 +275,7 @@ impl OverlayRenderer {
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, angle, translation).to_cols_array();
|
||||
|
||||
let message = Self::overlay_transform_message(anchor_overlay.clone(), transform);
|
||||
responses.push_back(message);
|
||||
responses.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,23 +283,23 @@ impl OverlayRenderer {
|
||||
fn remove_manipulator_group_overlays(overlay_paths: &ManipulatorGroupOverlays, responses: &mut VecDeque<Message>) {
|
||||
overlay_paths.iter().flatten().for_each(|layer_id| {
|
||||
trace!("Overlay: Sending delete message for: {:?}", layer_id);
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path: layer_id.clone() }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path: layer_id.clone() }.into()));
|
||||
});
|
||||
}
|
||||
|
||||
fn remove_outline_overlays(overlay_path: Vec<LayerId>, responses: &mut VecDeque<Message>) {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path: overlay_path }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path: overlay_path }.into()));
|
||||
}
|
||||
|
||||
/// Sets the visibility of the handles overlay.
|
||||
fn set_manipulator_group_overlay_visibility(manipulator_group_overlays: &ManipulatorGroupOverlays, visibility: bool, responses: &mut VecDeque<Message>) {
|
||||
manipulator_group_overlays.iter().flatten().for_each(|layer_id| {
|
||||
responses.push_back(Self::overlay_visibility_message(layer_id.clone(), visibility));
|
||||
responses.add(Self::overlay_visibility_message(layer_id.clone(), visibility));
|
||||
});
|
||||
}
|
||||
|
||||
fn set_outline_overlay_visibility(overlay_path: Vec<LayerId>, visibility: bool, responses: &mut VecDeque<Message>) {
|
||||
responses.push_back(Self::overlay_visibility_message(overlay_path, visibility));
|
||||
responses.add(Self::overlay_visibility_message(overlay_path, visibility));
|
||||
}
|
||||
|
||||
/// Create a visibility message for an overlay.
|
||||
@@ -340,7 +340,7 @@ impl OverlayRenderer {
|
||||
.is_some();
|
||||
|
||||
let style = if selected { selected_style.clone() } else { deselected_style.clone() };
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerStyle { path: overlay_path.clone(), style }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::SetLayerStyle { path: overlay_path.clone(), style }.into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl PathOutline {
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
};
|
||||
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
overlay_path
|
||||
}
|
||||
@@ -59,14 +59,14 @@ impl PathOutline {
|
||||
|
||||
// Update the shape bezpath
|
||||
let operation = Operation::SetShapePath { path: overlay.clone(), subpath };
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
// Update the transform to match the document
|
||||
let operation = Operation::SetLayerTransform {
|
||||
path: overlay.clone(),
|
||||
transform: document.document_legacy.multiply_transforms(&document_layer_path).unwrap().to_cols_array(),
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
Some(overlay)
|
||||
}
|
||||
@@ -87,7 +87,7 @@ impl PathOutline {
|
||||
// Discard the overlay layer if it exists
|
||||
if let Some(overlay_path) = copied_overlay_path {
|
||||
let operation = Operation::DeleteLayer { path: overlay_path };
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
}
|
||||
}
|
||||
result
|
||||
@@ -97,7 +97,7 @@ impl PathOutline {
|
||||
pub fn clear_hovered(&mut self, responses: &mut VecDeque<Message>) {
|
||||
if let Some(path) = self.hovered_overlay_path.take() {
|
||||
let operation = Operation::DeleteLayer { path };
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
}
|
||||
self.hovered_layer_path = None;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ impl PathOutline {
|
||||
pub fn clear_selected(&mut self, responses: &mut VecDeque<Message>) {
|
||||
while let Some(path) = self.selected_overlay_paths.pop() {
|
||||
let operation = Operation::DeleteLayer { path };
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ impl PathOutline {
|
||||
}
|
||||
for path in old_overlay_paths {
|
||||
let operation = Operation::DeleteLayer { path };
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl Pivot {
|
||||
pub fn clear_overlays(&mut self, responses: &mut VecDeque<Message>) {
|
||||
if let Some(overlays) = self.pivot_overlay_circles.take() {
|
||||
for path in overlays {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path }.into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,43 +107,37 @@ impl Pivot {
|
||||
};
|
||||
|
||||
let layer_paths = [vec![generate_uuid()], vec![generate_uuid()]];
|
||||
responses.push_back(
|
||||
DocumentMessage::Overlays(
|
||||
Operation::AddEllipse {
|
||||
path: layer_paths[0].clone(),
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
style: style::PathStyle::new(
|
||||
Some(style::Stroke::new(COLOR_ACCENT, PIVOT_OUTER_OUTLINE_THICKNESS)),
|
||||
style::Fill::Solid(graphene_core::raster::color::Color::WHITE),
|
||||
),
|
||||
insert_index: -1,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
responses.add(DocumentMessage::Overlays(
|
||||
Operation::AddEllipse {
|
||||
path: layer_paths[0].clone(),
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
style: style::PathStyle::new(
|
||||
Some(style::Stroke::new(COLOR_ACCENT, PIVOT_OUTER_OUTLINE_THICKNESS)),
|
||||
style::Fill::Solid(graphene_core::raster::color::Color::WHITE),
|
||||
),
|
||||
insert_index: -1,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
responses.push_back(
|
||||
DocumentMessage::Overlays(
|
||||
Operation::AddEllipse {
|
||||
path: layer_paths[1].clone(),
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
style: style::PathStyle::new(None, style::Fill::Solid(COLOR_ACCENT)),
|
||||
insert_index: -1,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
));
|
||||
responses.add(DocumentMessage::Overlays(
|
||||
Operation::AddEllipse {
|
||||
path: layer_paths[1].clone(),
|
||||
transform: DAffine2::IDENTITY.to_cols_array(),
|
||||
style: style::PathStyle::new(None, style::Fill::Solid(COLOR_ACCENT)),
|
||||
insert_index: -1,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
));
|
||||
|
||||
self.pivot_overlay_circles = Some(layer_paths.clone());
|
||||
let [outer, inner] = layer_paths;
|
||||
|
||||
let pivot_diameter_without_outline = PIVOT_OUTER - PIVOT_OUTER_OUTLINE_THICKNESS;
|
||||
let transform = DAffine2::from_scale_angle_translation(DVec2::splat(pivot_diameter_without_outline), 0., pivot - DVec2::splat(pivot_diameter_without_outline / 2.)).to_cols_array();
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::TransformLayerInViewport { path: outer, transform }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::TransformLayerInViewport { path: outer, transform }.into()));
|
||||
|
||||
let transform = DAffine2::from_scale_angle_translation(DVec2::splat(PIVOT_INNER), 0., pivot - DVec2::splat(PIVOT_INNER / 2.)).to_cols_array();
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::TransformLayerInViewport { path: inner, transform }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::TransformLayerInViewport { path: inner, transform }.into()));
|
||||
}
|
||||
|
||||
pub fn update_pivot(&mut self, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) {
|
||||
|
||||
@@ -29,40 +29,37 @@ impl SnapOverlays {
|
||||
// If there isn't one in the pool to ruse, add a new alignment line to the pool with the intended transform
|
||||
let layer_path = if index >= overlay_paths.len() {
|
||||
let layer_path = vec![generate_uuid()];
|
||||
responses.push_back(
|
||||
DocumentMessage::Overlays(
|
||||
if is_axis {
|
||||
Operation::AddLine {
|
||||
path: layer_path.clone(),
|
||||
transform,
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), style::Fill::None),
|
||||
insert_index: -1,
|
||||
}
|
||||
} else {
|
||||
Operation::AddEllipse {
|
||||
path: layer_path.clone(),
|
||||
transform,
|
||||
style: style::PathStyle::new(None, style::Fill::Solid(COLOR_ACCENT)),
|
||||
insert_index: -1,
|
||||
}
|
||||
responses.add(DocumentMessage::Overlays(
|
||||
if is_axis {
|
||||
Operation::AddLine {
|
||||
path: layer_path.clone(),
|
||||
transform,
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), style::Fill::None),
|
||||
insert_index: -1,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
Operation::AddEllipse {
|
||||
path: layer_path.clone(),
|
||||
transform,
|
||||
style: style::PathStyle::new(None, style::Fill::Solid(COLOR_ACCENT)),
|
||||
insert_index: -1,
|
||||
}
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
));
|
||||
overlay_paths.push(layer_path.clone());
|
||||
layer_path
|
||||
}
|
||||
// Otherwise, reuse an overlay from the pool and update its new transform
|
||||
else {
|
||||
let layer_path = overlay_paths[index].clone();
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerTransform { path: layer_path.clone(), transform }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::SetLayerTransform { path: layer_path.clone(), transform }.into()));
|
||||
layer_path
|
||||
};
|
||||
|
||||
// Then set its opacity to the fade amount
|
||||
if let Some(opacity) = opacity {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerOpacity { path: layer_path, opacity }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::SetLayerOpacity { path: layer_path, opacity }.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +144,7 @@ impl SnapOverlays {
|
||||
/// Remove overlays from the pool beyond a given index. Pool entries up through that index will be kept.
|
||||
fn remove_unused_overlays(overlay_paths: &mut Vec<Vec<LayerId>>, responses: &mut VecDeque<Message>, remove_after_index: usize) {
|
||||
while overlay_paths.len() > remove_after_index {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path: overlay_paths.pop().unwrap() }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path: overlay_paths.pop().unwrap() }.into()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ pub fn add_bounding_box(responses: &mut VecDeque<Message>) -> Vec<LayerId> {
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), Fill::None),
|
||||
insert_index: -1,
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
path
|
||||
}
|
||||
@@ -178,7 +178,7 @@ fn add_transform_handles(responses: &mut VecDeque<Message>) -> [Vec<LayerId>; 8]
|
||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 2.0)), Fill::solid(Color::WHITE)),
|
||||
insert_index: -1,
|
||||
};
|
||||
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(operation.into()));
|
||||
|
||||
*item = current_path;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ impl BoundingBoxOverlays {
|
||||
pub fn transform(&mut self, responses: &mut VecDeque<Message>) {
|
||||
let transform = transform_from_box(self.bounds[0], self.bounds[1], self.transform).to_cols_array();
|
||||
let path = self.bounding_box.clone();
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()));
|
||||
|
||||
// Helps push values that end in approximately half, plus or minus some floating point imprecision, towards the same side of the round() function
|
||||
const BIAS: f64 = 0.0001;
|
||||
@@ -263,7 +263,7 @@ impl BoundingBoxOverlays {
|
||||
let translation = (position - (scale / 2.) - 0.5 + BIAS).round();
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, 0., translation).to_cols_array();
|
||||
let path = path.clone();
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ impl BoundingBoxOverlays {
|
||||
|
||||
/// Removes the overlays
|
||||
pub fn delete(self, responses: &mut VecDeque<Message>) {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path: self.bounding_box }.into()).into());
|
||||
responses.add(DocumentMessage::Overlays(Operation::DeleteLayer { path: self.bounding_box }.into()));
|
||||
responses.extend(
|
||||
self.transform_handles
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user