Fix select tool deselect all (#714)
* Fix select tool deselect all * remove extra log * add back buffer to branch * Remove the buffer vec Co-authored-by: mfish33 <maxmfishernj@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
58675eb64d
commit
8f00a4071d
|
|
@ -127,19 +127,18 @@ impl Fsm for ArtboardToolFsmState {
|
||||||
if let ToolMessage::Artboard(event) = event {
|
if let ToolMessage::Artboard(event) = event {
|
||||||
match (self, event) {
|
match (self, event) {
|
||||||
(ArtboardToolFsmState::Ready | ArtboardToolFsmState::ResizingBounds | ArtboardToolFsmState::Dragging, ArtboardToolMessage::DocumentIsDirty) => {
|
(ArtboardToolFsmState::Ready | ArtboardToolFsmState::ResizingBounds | ArtboardToolFsmState::Dragging, ArtboardToolMessage::DocumentIsDirty) => {
|
||||||
let mut buffer = Vec::new();
|
|
||||||
match (
|
match (
|
||||||
tool_data.selected_board.map(|path| document.artboard_bounding_box_and_transform(&[path], font_cache)).unwrap_or(None),
|
tool_data.selected_board.map(|path| document.artboard_bounding_box_and_transform(&[path], font_cache)).unwrap_or(None),
|
||||||
tool_data.bounding_box_overlays.take(),
|
tool_data.bounding_box_overlays.take(),
|
||||||
) {
|
) {
|
||||||
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(&mut buffer),
|
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
||||||
(Some((bounds, transform)), paths) => {
|
(Some((bounds, transform)), paths) => {
|
||||||
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(&mut buffer));
|
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(responses));
|
||||||
|
|
||||||
bounding_box_overlays.bounds = bounds;
|
bounding_box_overlays.bounds = bounds;
|
||||||
bounding_box_overlays.transform = transform;
|
bounding_box_overlays.transform = transform;
|
||||||
|
|
||||||
bounding_box_overlays.transform(&mut buffer);
|
bounding_box_overlays.transform(responses);
|
||||||
|
|
||||||
tool_data.bounding_box_overlays = Some(bounding_box_overlays);
|
tool_data.bounding_box_overlays = Some(bounding_box_overlays);
|
||||||
|
|
||||||
|
|
@ -154,7 +153,6 @@ impl Fsm for ArtboardToolFsmState {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
(ArtboardToolFsmState::Ready, ArtboardToolMessage::PointerDown) => {
|
(ArtboardToolFsmState::Ready, ArtboardToolMessage::PointerDown) => {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ pub enum SelectToolMessage {
|
||||||
Abort,
|
Abort,
|
||||||
#[remain::unsorted]
|
#[remain::unsorted]
|
||||||
DocumentIsDirty,
|
DocumentIsDirty,
|
||||||
|
#[remain::unsorted]
|
||||||
|
SelectionChanged,
|
||||||
|
|
||||||
// Tool-specific messages
|
// Tool-specific messages
|
||||||
Align {
|
Align {
|
||||||
|
|
@ -275,7 +277,7 @@ impl ToolTransition for SelectTool {
|
||||||
SignalToMessageMap {
|
SignalToMessageMap {
|
||||||
document_dirty: Some(SelectToolMessage::DocumentIsDirty.into()),
|
document_dirty: Some(SelectToolMessage::DocumentIsDirty.into()),
|
||||||
tool_abort: Some(SelectToolMessage::Abort.into()),
|
tool_abort: Some(SelectToolMessage::Abort.into()),
|
||||||
selection_changed: None,
|
selection_changed: Some(SelectToolMessage::SelectionChanged.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -339,25 +341,22 @@ impl Fsm for SelectToolFsmState {
|
||||||
use SelectToolMessage::*;
|
use SelectToolMessage::*;
|
||||||
|
|
||||||
if let ToolMessage::Select(event) = event {
|
if let ToolMessage::Select(event) = event {
|
||||||
log::debug!("self: {:?}, even: {:?}", self, event);
|
|
||||||
match (self, event) {
|
match (self, event) {
|
||||||
(_, DocumentIsDirty) => {
|
(_, DocumentIsDirty | SelectionChanged) => {
|
||||||
let mut buffer = Vec::new();
|
|
||||||
match (document.selected_visible_layers_bounding_box(font_cache), tool_data.bounding_box_overlays.take()) {
|
match (document.selected_visible_layers_bounding_box(font_cache), tool_data.bounding_box_overlays.take()) {
|
||||||
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(&mut buffer),
|
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
||||||
(Some(bounds), paths) => {
|
(Some(bounds), paths) => {
|
||||||
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(&mut buffer));
|
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(responses));
|
||||||
|
|
||||||
bounding_box_overlays.bounds = bounds;
|
bounding_box_overlays.bounds = bounds;
|
||||||
bounding_box_overlays.transform = DAffine2::IDENTITY;
|
bounding_box_overlays.transform = DAffine2::IDENTITY;
|
||||||
|
|
||||||
bounding_box_overlays.transform(&mut buffer);
|
bounding_box_overlays.transform(responses);
|
||||||
|
|
||||||
tool_data.bounding_box_overlays = Some(bounding_box_overlays);
|
tool_data.bounding_box_overlays = Some(bounding_box_overlays);
|
||||||
}
|
}
|
||||||
(_, _) => {}
|
(_, _) => {}
|
||||||
};
|
};
|
||||||
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
|
|
||||||
|
|
||||||
tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, font_cache);
|
tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, font_cache);
|
||||||
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
|
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
|
||||||
|
|
@ -394,7 +393,6 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
tool_data.drag_start = input.mouse.position;
|
tool_data.drag_start = input.mouse.position;
|
||||||
tool_data.drag_current = input.mouse.position;
|
tool_data.drag_current = input.mouse.position;
|
||||||
let mut buffer = Vec::new();
|
|
||||||
|
|
||||||
let dragging_bounds = if let Some(bounding_box) = &mut tool_data.bounding_box_overlays {
|
let dragging_bounds = if let Some(bounding_box) = &mut tool_data.bounding_box_overlays {
|
||||||
let edges = bounding_box.check_selected_edges(input.mouse.position);
|
let edges = bounding_box.check_selected_edges(input.mouse.position);
|
||||||
|
|
@ -448,7 +446,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
RotatingBounds
|
RotatingBounds
|
||||||
} else if selected.iter().any(|path| intersection.contains(path)) {
|
} else if selected.iter().any(|path| intersection.contains(path)) {
|
||||||
buffer.push(DocumentMessage::StartTransaction.into());
|
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||||
tool_data.layers_dragging = selected;
|
tool_data.layers_dragging = selected;
|
||||||
|
|
||||||
tool_data
|
tool_data
|
||||||
|
|
@ -458,14 +456,14 @@ impl Fsm for SelectToolFsmState {
|
||||||
Dragging
|
Dragging
|
||||||
} else {
|
} else {
|
||||||
if !input.keyboard.get(add_to_selection as usize) {
|
if !input.keyboard.get(add_to_selection as usize) {
|
||||||
buffer.push(DocumentMessage::DeselectAllLayers.into());
|
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||||
tool_data.layers_dragging.clear();
|
tool_data.layers_dragging.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(intersection) = intersection.pop() {
|
if let Some(intersection) = intersection.pop() {
|
||||||
selected = vec![intersection];
|
selected = vec![intersection];
|
||||||
buffer.push(DocumentMessage::AddSelectedLayers { additional_layers: selected.clone() }.into());
|
responses.push_back(DocumentMessage::AddSelectedLayers { additional_layers: selected.clone() }.into());
|
||||||
buffer.push(DocumentMessage::StartTransaction.into());
|
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||||
tool_data.layers_dragging.append(&mut selected);
|
tool_data.layers_dragging.append(&mut selected);
|
||||||
tool_data
|
tool_data
|
||||||
.snap_handler
|
.snap_handler
|
||||||
|
|
@ -473,11 +471,10 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
Dragging
|
Dragging
|
||||||
} else {
|
} else {
|
||||||
tool_data.drag_box_overlay_layer = Some(add_bounding_box(&mut buffer));
|
tool_data.drag_box_overlay_layer = Some(add_bounding_box(responses));
|
||||||
DrawingBox
|
DrawingBox
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
|
|
||||||
|
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ impl SelectedEdges {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a viewport relative bounding box overlay with no transform handles
|
/// Create a viewport relative bounding box overlay with no transform handles
|
||||||
pub fn add_bounding_box(responses: &mut Vec<Message>) -> Vec<LayerId> {
|
pub fn add_bounding_box(responses: &mut VecDeque<Message>) -> Vec<LayerId> {
|
||||||
let path = vec![generate_uuid()];
|
let path = vec![generate_uuid()];
|
||||||
|
|
||||||
let operation = Operation::AddRect {
|
let operation = Operation::AddRect {
|
||||||
|
|
@ -146,13 +146,13 @@ pub fn add_bounding_box(responses: &mut Vec<Message>) -> Vec<LayerId> {
|
||||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), Fill::None),
|
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 1.0)), Fill::None),
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
};
|
};
|
||||||
responses.push(DocumentMessage::Overlays(operation.into()).into());
|
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||||
|
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the transform handle overlay
|
/// Add the transform handle overlay
|
||||||
fn add_transform_handles(responses: &mut Vec<Message>) -> [Vec<LayerId>; 8] {
|
fn add_transform_handles(responses: &mut VecDeque<Message>) -> [Vec<LayerId>; 8] {
|
||||||
const EMPTY_VEC: Vec<LayerId> = Vec::new();
|
const EMPTY_VEC: Vec<LayerId> = Vec::new();
|
||||||
let mut transform_handle_paths = [EMPTY_VEC; 8];
|
let mut transform_handle_paths = [EMPTY_VEC; 8];
|
||||||
|
|
||||||
|
|
@ -165,7 +165,7 @@ fn add_transform_handles(responses: &mut Vec<Message>) -> [Vec<LayerId>; 8] {
|
||||||
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 2.0)), Fill::solid(Color::WHITE)),
|
style: style::PathStyle::new(Some(Stroke::new(COLOR_ACCENT, 2.0)), Fill::solid(Color::WHITE)),
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
};
|
};
|
||||||
responses.push(DocumentMessage::Overlays(operation.into()).into());
|
responses.push_back(DocumentMessage::Overlays(operation.into()).into());
|
||||||
|
|
||||||
*item = current_path;
|
*item = current_path;
|
||||||
}
|
}
|
||||||
|
|
@ -211,10 +211,10 @@ pub struct BoundingBoxOverlays {
|
||||||
|
|
||||||
impl BoundingBoxOverlays {
|
impl BoundingBoxOverlays {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(buffer: &mut Vec<Message>) -> Self {
|
pub fn new(responses: &mut VecDeque<Message>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bounding_box: add_bounding_box(buffer),
|
bounding_box: add_bounding_box(responses),
|
||||||
transform_handles: add_transform_handles(buffer),
|
transform_handles: add_transform_handles(responses),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -236,10 +236,10 @@ impl BoundingBoxOverlays {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the position of the bounding box and transform handles
|
/// Update the position of the bounding box and transform handles
|
||||||
pub fn transform(&mut self, buffer: &mut Vec<Message>) {
|
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 transform = transform_from_box(self.bounds[0], self.bounds[1], self.transform).to_cols_array();
|
||||||
let path = self.bounding_box.clone();
|
let path = self.bounding_box.clone();
|
||||||
buffer.push(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
||||||
|
|
||||||
// Helps push values that end in approximately half, plus or minus some floating point imprecision, towards the same side of the round() function
|
// 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;
|
const BIAS: f64 = 0.0001;
|
||||||
|
|
@ -249,7 +249,7 @@ impl BoundingBoxOverlays {
|
||||||
let translation = (position - (scale / 2.) - 0.5 + BIAS).round();
|
let translation = (position - (scale / 2.) - 0.5 + BIAS).round();
|
||||||
let transform = DAffine2::from_scale_angle_translation(scale, 0., translation).to_cols_array();
|
let transform = DAffine2::from_scale_angle_translation(scale, 0., translation).to_cols_array();
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
buffer.push(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
responses.push_back(DocumentMessage::Overlays(Operation::SetLayerTransformInViewport { path, transform }.into()).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,9 +314,9 @@ impl BoundingBoxOverlays {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the overlays
|
/// Removes the overlays
|
||||||
pub fn delete(self, buffer: &mut impl Extend<Message>) {
|
pub fn delete(self, responses: &mut VecDeque<Message>) {
|
||||||
buffer.extend([DocumentMessage::Overlays(Operation::DeleteLayer { path: self.bounding_box }.into()).into()]);
|
responses.push_back(DocumentMessage::Overlays(Operation::DeleteLayer { path: self.bounding_box }.into()).into());
|
||||||
buffer.extend(
|
responses.extend(
|
||||||
self.transform_handles
|
self.transform_handles
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path| DocumentMessage::Overlays(Operation::DeleteLayer { path: path.clone() }.into()).into()),
|
.map(|path| DocumentMessage::Overlays(Operation::DeleteLayer { path: path.clone() }.into()).into()),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue