Apply lints and cleanup to Rust code

This commit is contained in:
Keavon Chambers
2023-01-29 03:01:57 -08:00
parent 5388b59e97
commit d990110f63
27 changed files with 122 additions and 119 deletions

View File

@@ -58,11 +58,11 @@ pub enum FrontendMessage {
hostname: String,
},
TriggerImaginateGenerate {
parameters: ImaginateGenerationParameters,
parameters: Box<ImaginateGenerationParameters>,
#[serde(rename = "baseImage")]
base_image: Option<ImaginateBaseImage>,
base_image: Option<Box<ImaginateBaseImage>>,
#[serde(rename = "maskImage")]
mask_image: Option<ImaginateMaskImage>,
mask_image: Option<Box<ImaginateMaskImage>>,
#[serde(rename = "maskPaintMode")]
mask_paint_mode: ImaginateMaskPaintMode,
#[serde(rename = "maskBlurPx")]

View File

@@ -467,7 +467,7 @@ impl<'a, const LENGTH: usize> Iterator for BitVectorIter<'a, LENGTH> {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
while self.iter_index < (STORAGE_SIZE_BITS as usize) * LENGTH {
while self.iter_index < STORAGE_SIZE_BITS * LENGTH {
let bit_value = self.bitvector.get(self.iter_index);
self.iter_index += 1;

View File

@@ -164,7 +164,7 @@ impl Layout {
// Simply diff the internal layout
(Self::WidgetLayout(current), Self::WidgetLayout(new)) => current.diff(new, widget_path, widget_diffs),
(current, Self::WidgetLayout(widget_layout)) => {
// Upate current to the new value
// Update current to the new value
*current = Self::WidgetLayout(widget_layout.clone());
// Push an update sublayout value
@@ -179,7 +179,7 @@ impl Layout {
impl Default for Layout {
fn default() -> Self {
Layout::WidgetLayout(WidgetLayout::default())
Self::WidgetLayout(WidgetLayout::default())
}
}

View File

@@ -1661,7 +1661,10 @@ impl DocumentMessageHandler {
direction: SeparatorDirection::Horizontal,
})),
WidgetHolder::new(Widget::RadioInput(RadioInput {
selected_index: if self.view_mode == ViewMode::Normal { 0 } else { 1 },
selected_index: match self.view_mode {
ViewMode::Normal => 0,
_ => 1,
},
entries: vec![
RadioEntryData {
value: "normal".into(),

View File

@@ -141,7 +141,7 @@ impl MessageHandler<NavigationMessage, (&Document, &InputPreprocessorMessageHand
}
self.snap_zoom = new_snap;
let difference = self.mouse_position.y as f64 - ipp.mouse.position.y as f64;
let difference = self.mouse_position.y - ipp.mouse.position.y;
let amount = 1. + difference * VIEWPORT_ZOOM_MOUSE_RATE;
self.zoom *= amount;

View File

@@ -31,7 +31,7 @@ impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformL
fn process_message(&mut self, message: TransformLayerMessage, (layer_metadata, document, ipp, font_cache): TransformData, responses: &mut VecDeque<Message>) {
use TransformLayerMessage::*;
let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then(|| layer_path)).collect::<Vec<_>>();
let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then_some(layer_path)).collect::<Vec<_>>();
let mut selected = Selected::new(&mut self.original_transforms, &mut self.pivot, &selected_layers, responses, document);
let mut begin_operation = |operation: TransformOperation, typing: &mut Typing, mouse_position: &mut DVec2, start_mouse: &mut DVec2| {

View File

@@ -11,19 +11,14 @@ use std::collections::{HashMap, VecDeque};
pub type OriginalTransforms = HashMap<Vec<LayerId>, DAffine2>;
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Copy)]
pub enum Axis {
#[default]
Both,
X,
Y,
}
impl Default for Axis {
fn default() -> Self {
Self::Both
}
}
impl Axis {
pub fn set_or_toggle(&mut self, target: Axis) {
// If constrained to an axis and target is requesting the same axis, toggle back to Both
@@ -137,20 +132,15 @@ impl Scale {
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
#[derive(Default, Debug, Clone, PartialEq, Copy)]
pub enum TransformOperation {
#[default]
None,
Grabbing(Translation),
Rotating(Rotation),
Scaling(Scale),
}
impl Default for TransformOperation {
fn default() -> Self {
TransformOperation::None
}
}
impl TransformOperation {
pub fn apply_transform_operation(&self, selected: &mut Selected, snapping: bool) {
if self != &TransformOperation::None {

View File

@@ -256,8 +256,8 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
PortfolioMessage::DocumentPassMessage {
document_id,
message: NodeGraphMessage::SetQualifiedInputValue {
layer_path: layer_path.clone(),
node_path: node_path.clone(),
layer_path,
node_path,
input_index: get("Status"),
value: TaggedValue::ImaginateStatus(status),
}
@@ -706,11 +706,10 @@ impl PortfolioMessageHandler {
// Adjust the output of the graph so we find the relevant output
'outer: for end in (0..node_path.len()).rev() {
let mut inner_network = &mut network;
for index in 0..end {
let node_id = node_path[index];
inner_network.output = node_id;
for node_id in node_path.iter().take(end) {
inner_network.output = *node_id;
let Some(new_inner) = inner_network.nodes.get_mut(&node_id).and_then(|node| node.implementation.get_network_mut()) else {
let Some(new_inner) = inner_network.nodes.get_mut(node_id).and_then(|node| node.implementation.get_network_mut()) else {
return Err("Failed to find network".to_string());
};
inner_network = new_inner;
@@ -859,9 +858,9 @@ impl PortfolioMessageHandler {
responses.push_back(
FrontendMessage::TriggerImaginateGenerate {
parameters,
base_image,
mask_image,
parameters: Box::new(parameters),
base_image: base_image.map(Box::new),
mask_image: mask_image.map(Box::new),
mask_paint_mode: if Self::compute_input::<bool>(&network, &imaginate_node, get("Inpaint"), Cow::Borrowed(&image))? {
ImaginateMaskPaintMode::Inpaint
} else {

View File

@@ -58,7 +58,7 @@ impl OverlayRenderer {
// Create, place, and style the manipulator overlays
for (manipulator_group_id, manipulator_group) in shape.manipulator_groups().enumerate() {
let manipulator_group_cache = self.manipulator_group_overlay_cache.entry((*layer_id, *manipulator_group_id)).or_insert(Default::default());
let manipulator_group_cache = self.manipulator_group_overlay_cache.entry((*layer_id, *manipulator_group_id)).or_default();
// Only view in and out handles if they are not on top of the anchor
let [in_handle, out_handle] = {

View File

@@ -29,18 +29,22 @@ pub struct ShapeEditor {
selected_layers: Vec<Vec<LayerId>>,
}
pub struct SelectedPointsInfo<'a> {
pub points: Vec<ManipulatorPointInfo<'a>>,
pub offset: DVec2,
}
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct ManipulatorPointInfo<'a> {
pub shape_layer_path: &'a [LayerId],
pub manipulator_group_id: u64,
pub manipulator_type: ManipulatorType,
}
// TODO Consider keeping a list of selected manipulators to minimize traversals of the layers
impl ShapeEditor {
/// Select the first point within the selection threshold.
/// Returns a tuple of the points if found and the offset, or None otherwise.
pub fn select_point(
&self,
document: &Document,
mouse_position: DVec2,
select_threshold: f64,
add_to_selection: bool,
responses: &mut VecDeque<Message>,
) -> Option<(Vec<(&[LayerId], u64, ManipulatorType)>, DVec2)> {
/// Returns a tuple of the points if found and the offset, or `None` otherwise.
pub fn select_point(&self, document: &Document, mouse_position: DVec2, select_threshold: f64, add_to_selection: bool, responses: &mut VecDeque<Message>) -> Option<SelectedPointsInfo> {
if self.selected_layers.is_empty() {
return None;
}
@@ -73,7 +77,11 @@ impl ShapeEditor {
.enumerate()
.filter(|(_id, manipulator_group)| manipulator_group.is_anchor_selected())
.flat_map(|(id, manipulator_group)| manipulator_group.selected_points().map(move |point| (id, point.manipulator_type)))
.map(|(anchor, manipulator_point)| (path.as_slice(), *anchor, manipulator_point))
.map(|(anchor, manipulator_point)| ManipulatorPointInfo {
shape_layer_path: path.as_slice(),
manipulator_group_id: *anchor,
manipulator_type: manipulator_point,
})
})
.collect::<Vec<_>>();
@@ -82,32 +90,36 @@ impl ShapeEditor {
// This is selecting the manipulator only for now, next to generalize to points
if should_select {
// If we're replacing the selection, clear all points in other selected shapes
let add = add_to_selection || is_point_selected;
let point = (manipulator_group_id, ManipulatorType::from_index(manipulator_point_index));
// Clear all point in other selected shapes
if !add {
points.clear();
responses.push_back(DocumentMessage::DeselectAllManipulatorPoints.into());
points = vec![(shape_layer_path, point.0, point.1)];
} else {
points.push((shape_layer_path, point.0, point.1));
}
// Add to the selected points
let point_info = ManipulatorPointInfo {
shape_layer_path,
manipulator_group_id,
manipulator_type: ManipulatorType::from_index(manipulator_point_index),
};
points.push(point_info);
responses.push_back(
Operation::SelectManipulatorPoints {
layer_path: shape_layer_path.to_vec(),
point_ids: vec![point],
point_ids: vec![(point_info.manipulator_group_id, point_info.manipulator_type)],
add,
}
.into(),
);
// Offset to snap the selected point to the cursor
let offset = if let Ok(viewspace) = document.generate_transform_relative_to_viewport(shape_layer_path) {
mouse_position - viewspace.transform_point2(point_position)
} else {
DVec2::ZERO
};
let offset = document
.generate_transform_relative_to_viewport(shape_layer_path)
.map(|viewspace| mouse_position - viewspace.transform_point2(point_position))
.unwrap_or_default();
return Some((points, offset));
return Some(SelectedPointsInfo { points, offset });
} else {
responses.push_back(
Operation::DeselectManipulatorPoints {
@@ -116,7 +128,13 @@ impl ShapeEditor {
}
.into(),
);
points.retain(|x| *x != (shape_layer_path, manipulator_group_id, ManipulatorType::from_index(manipulator_point_index)));
points.retain(|x| {
*x != ManipulatorPointInfo {
shape_layer_path,
manipulator_group_id,
manipulator_type: ManipulatorType::from_index(manipulator_point_index),
}
});
return None;
}

View File

@@ -1,3 +1,4 @@
use super::shape_editor::ManipulatorPointInfo;
use crate::application::generate_uuid;
use crate::consts::{
COLOR_ACCENT, SNAP_AXIS_OVERLAY_FADE_DISTANCE, SNAP_AXIS_TOLERANCE, SNAP_AXIS_UNSNAPPED_OPACITY, SNAP_POINT_OVERLAY_FADE_FAR, SNAP_POINT_OVERLAY_FADE_NEAR, SNAP_POINT_SIZE, SNAP_POINT_TOLERANCE,
@@ -257,7 +258,7 @@ impl SnapManager {
layer: &Layer,
path: &[LayerId],
include_handles: bool,
ignore_points: &[(&[LayerId], u64, ManipulatorType)],
ignore_points: &[ManipulatorPointInfo],
) {
if let LayerDataType::Shape(shape_layer) = &layer.data {
let transform = document_message_handler.document_legacy.multiply_transforms(path).unwrap();
@@ -277,7 +278,13 @@ impl SnapManager {
}
})
.filter_map(|(id, point)| point.as_ref().map(|val| (id, val)))
.filter(|(id, point)| !ignore_points.contains(&(path, *id, point.manipulator_type)))
.filter(|(id, point)| {
!ignore_points.contains(&ManipulatorPointInfo {
shape_layer_path: path,
manipulator_group_id: *id,
manipulator_type: point.manipulator_type,
})
})
.map(|(_id, point)| DVec2::new(point.position.x, point.position.y))
.map(|pos| transform.transform_point2(pos));
self.add_snap_points(document_message_handler, input, snap_points);
@@ -291,7 +298,7 @@ impl SnapManager {
input: &InputPreprocessorMessageHandler,
include_handles: &[&[LayerId]],
exclude: &[&[LayerId]],
ignore_points: &[(&[LayerId], u64, ManipulatorType)],
ignore_points: &[ManipulatorPointInfo],
) {
for path in document_message_handler.all_layers() {
if !exclude.contains(&path) {

View File

@@ -4,7 +4,7 @@ use crate::messages::input_mapper::utility_types::input_keyboard::{Key, MouseMot
use crate::messages::layout::utility_types::layout_widget::PropertyHolder;
use crate::messages::prelude::*;
use crate::messages::tool::common_functionality::overlay_renderer::OverlayRenderer;
use crate::messages::tool::common_functionality::shape_editor::ShapeEditor;
use crate::messages::tool::common_functionality::shape_editor::{ManipulatorPointInfo, ShapeEditor};
use crate::messages::tool::common_functionality::snapping::SnapManager;
use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
@@ -157,10 +157,9 @@ impl Fsm for PathToolFsmState {
let toggle_add_to_selection = input.keyboard.get(add_to_selection as usize);
// Select the first point within the threshold (in pixels)
if let Some((mut new_selected, offset)) =
tool_data
.shape_editor
.select_point(&document.document_legacy, input.mouse.position, SELECTION_THRESHOLD, toggle_add_to_selection, responses)
if let Some(mut selected_points) = tool_data
.shape_editor
.select_point(&document.document_legacy, input.mouse.position, SELECTION_THRESHOLD, toggle_add_to_selection, responses)
{
responses.push_back(DocumentMessage::StartTransaction.into());
@@ -171,18 +170,24 @@ impl Fsm for PathToolFsmState {
// Do not snap against handles when anchor is selected
let mut extension = Vec::new();
for &(path, id, point_type) in new_selected.iter() {
if point_type == ManipulatorType::Anchor {
extension.push((path, id, ManipulatorType::InHandle));
extension.push((path, id, ManipulatorType::OutHandle));
for point in selected_points.points.iter() {
if point.manipulator_type == ManipulatorType::Anchor {
extension.push(ManipulatorPointInfo {
manipulator_type: ManipulatorType::InHandle,
..*point
});
extension.push(ManipulatorPointInfo {
manipulator_type: ManipulatorType::OutHandle,
..*point
});
}
}
new_selected.extend(extension);
selected_points.points.extend(extension);
let include_handles = tool_data.shape_editor.selected_layers_ref();
tool_data.snap_manager.add_all_document_handles(document, input, &include_handles, &[], &new_selected);
tool_data.snap_manager.add_all_document_handles(document, input, &include_handles, &[], &selected_points.points);
tool_data.drag_start_pos = input.mouse.position - offset;
tool_data.drag_start_pos = input.mouse.position - selected_points.offset;
PathToolFsmState::Dragging
}
// We didn't find a point nearby, so consider selecting the nearest shape instead

View File

@@ -287,7 +287,7 @@ pub struct ToolFsmState {
impl Default for ToolFsmState {
fn default() -> Self {
ToolFsmState {
Self {
tool_data: ToolData {
active_tool_type: ToolType::Select,
tools: list_tools_in_groups()