mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 01:48:11 +08:00
Only open the node graph panel after drawing a new frame to avoid layout shift interruption (#924)
* Store drag start as document position * Don't open graph whilst drawing * Rename to is_drawing_node_graph_frame Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
f51dda5149
commit
df74f6f562
@@ -11,7 +11,7 @@ use glam::{DAffine2, DVec2, Vec2Swizzles};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Resize {
|
||||
pub drag_start: ViewportPosition,
|
||||
drag_start: ViewportPosition,
|
||||
pub path: Option<Vec<LayerId>>,
|
||||
snap_manager: SnapManager,
|
||||
}
|
||||
@@ -21,7 +21,14 @@ impl Resize {
|
||||
pub fn start(&mut self, responses: &mut VecDeque<Message>, document: &DocumentMessageHandler, mouse_position: DVec2, font_cache: &FontCache) {
|
||||
self.snap_manager.start_snap(document, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
self.snap_manager.add_all_document_handles(document, &[], &[], &[]);
|
||||
self.drag_start = self.snap_manager.snap_position(responses, document, mouse_position);
|
||||
let root_transform = document.document_legacy.root.transform;
|
||||
self.drag_start = root_transform.inverse().transform_point2(self.snap_manager.snap_position(responses, document, mouse_position));
|
||||
}
|
||||
|
||||
/// Calculate the drag start position in viewport space.
|
||||
pub fn viewport_drag_start(&self, document: &DocumentMessageHandler) -> DVec2 {
|
||||
let root_transform = document.document_legacy.root.transform;
|
||||
root_transform.transform_point2(self.drag_start)
|
||||
}
|
||||
|
||||
pub fn calculate_transform(
|
||||
@@ -33,7 +40,7 @@ impl Resize {
|
||||
ipp: &InputPreprocessorMessageHandler,
|
||||
) -> Option<Message> {
|
||||
if let Some(path) = &self.path {
|
||||
let mut start = self.drag_start;
|
||||
let mut start = self.viewport_drag_start(document);
|
||||
|
||||
let stop = self.snap_manager.snap_position(responses, document, ipp.mouse.position);
|
||||
|
||||
|
||||
@@ -105,6 +105,9 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
|
||||
|
||||
// Notify the frontend about the new active tool to be displayed
|
||||
tool_data.register_properties(responses, LayoutTarget::ToolShelf);
|
||||
|
||||
// Ensure the node graph drawing state is reset
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
|
||||
}
|
||||
ToolMessage::DeactivateTools => {
|
||||
let tool_data = &mut self.tool_state.tool_data;
|
||||
|
||||
@@ -159,7 +159,7 @@ impl Fsm for EllipseToolFsmState {
|
||||
state
|
||||
}
|
||||
(Drawing, DragStop) => {
|
||||
match shape_data.drag_start.distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
match shape_data.viewport_drag_start(document).distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ impl Fsm for ImaginateToolFsmState {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input.mouse.position, font_cache);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: true }.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
@@ -221,11 +222,12 @@ impl Fsm for ImaginateToolFsmState {
|
||||
state
|
||||
}
|
||||
(Drawing, DragStop) => {
|
||||
match shape_data.drag_start.distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
match shape_data.viewport_drag_start(document).distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
|
||||
shape_data.cleanup(responses);
|
||||
|
||||
Ready
|
||||
@@ -233,6 +235,8 @@ impl Fsm for ImaginateToolFsmState {
|
||||
(Drawing, Abort) => {
|
||||
responses.push_back(DocumentMessage::AbortTransaction.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
|
||||
|
||||
shape_data.cleanup(responses);
|
||||
|
||||
Ready
|
||||
|
||||
@@ -134,6 +134,7 @@ impl Fsm for NodeGraphToolFsmState {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input.mouse.position, font_cache);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: true }.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
@@ -186,17 +187,19 @@ impl Fsm for NodeGraphToolFsmState {
|
||||
state
|
||||
}
|
||||
(Drawing, DragStop) => {
|
||||
match shape_data.drag_start.distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
match shape_data.viewport_drag_start(document).distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
|
||||
shape_data.cleanup(responses);
|
||||
|
||||
Ready
|
||||
}
|
||||
(Drawing, Abort) => {
|
||||
responses.push_back(DocumentMessage::AbortTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
|
||||
|
||||
shape_data.cleanup(responses);
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ impl Fsm for RectangleToolFsmState {
|
||||
state
|
||||
}
|
||||
(Drawing, DragStop) => {
|
||||
match shape_data.drag_start.distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
match shape_data.viewport_drag_start(document).distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ impl Fsm for ShapeToolFsmState {
|
||||
state
|
||||
}
|
||||
(Drawing, DragStop) => {
|
||||
match shape_data.drag_start.distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
match shape_data.viewport_drag_start(document).distance(input.mouse.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user